Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

pinned: enable SeLockMemoryPrivilege and round the arena to GetLargePageMinimum

pipeob097cf327c1e72
diff --git a/src/core/pinned.cu b/src/core/pinned.cu
index 56573ce32..841ca233a 100644
--- a/src/core/pinned.cu
+++ b/src/core/pinned.cu
@@ -29,11 +29,33 @@ namespace {
// A 2 MB-aligned reservation. Large pages first, then the largest alignment the OS will give us for free.
void* reserve(uint64_t bytes, PageBacking& got, std::string& note) {
#ifdef _WIN32
+ // MEM_LARGE_PAGES needs SeLockMemoryPrivilege. Having it assigned to the account is not enough: the
+ // PROCESS must enable it in its own token (AdjustTokenPrivileges) before VirtualAlloc, or the call fails.
+ // An account without the assignment, or a failure to enable, leaves the process as it was: VirtualAlloc
+ // then refuses and the 4 KB fallback below runs - that is the EXPECTED outcome on a desktop.
+ {
+ HANDLE tok = nullptr;
+ if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tok)) {
+ TOKEN_PRIVILEGES tp{};
+ tp.PrivilegeCount = 1;
+ if (LookupPrivilegeValueW(nullptr, L"SeLockMemoryPrivilege", &tp.Privileges[0].Luid)) {
+ tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+ if (!AdjustTokenPrivileges(tok, FALSE, &tp, 0, nullptr, nullptr) && GetLastError() != ERROR_NOT_ALL_ASSIGNED)
+ (void) 0; // nothing actionable: the large-page attempt below reports the outcome
+ }
+ CloseHandle(tok);
+ }
+ }
// MEM_LARGE_PAGES needs SeLockMemoryPrivilege; a normal account does not have it and VirtualAlloc then
// fails with ERROR_PRIVILEGE_NOT_HELD. That is the EXPECTED outcome on a desktop, not an error.
SIZE_T large = GetLargePageMinimum();
- if (large > 0) {
- void* p = VirtualAlloc(nullptr, (SIZE_T) bytes, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES,
+ // A/B switch: STRATA_NO_LARGEPAGES=1 skips the large-page attempt, same run, same boot.
+ if (large > 0 && std::getenv("STRATA_NO_LARGEPAGES") == nullptr) {
+ // MEM_LARGE_PAGES requires the allocation size to be an exact multiple of the large page size -
+ // anything else is ERROR_INVALID_PARAMETER (87), which reads like a privilege problem but is not.
+ // Round up: the slack is under 2 MB and the tail stays unused.
+ const SIZE_T lbytes = (SIZE_T) (((SIZE_T) bytes + large - 1) / large * large);
+ void* p = VirtualAlloc(nullptr, lbytes, MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES,
PAGE_READWRITE);
if (p) {
got = PageBacking::LargePages;
@@ -43,6 +65,8 @@ void* reserve(uint64_t bytes, PageBacking& got, std::string& note) {
note = "large pages refused (GetLargePageMinimum=" + std::to_string((unsigned long long) large) +
", VirtualAlloc error " + std::to_string((unsigned long long) GetLastError()) +
" - needs SeLockMemoryPrivilege); using 4 KB pages";
+ } else if (std::getenv("STRATA_NO_LARGEPAGES") != nullptr) {
+ note = "large pages skipped (STRATA_NO_LARGEPAGES); using 4 KB pages";
} else {
note = "this system has no large-page minimum; using 4 KB pages";
}