tools/windows/enable_large_pages.ps1: grant "Lock pages in memory" to the current account (#2185)

A helper for the large-page arena (#1412): run as Administrator, it adds the account to
SeLockMemoryPrivilege with secedit, says that a new logon is needed, and prints the secpol.msc
steps when it cannot run. Changed from the PR: secedit /configure is limited to
/areas USER_RIGHTS (the exported policy is not re-applied as a whole), and the description no
longer claims a speed-up we have not measured. docs/DETAILS.md points to it. Not run on our side
(no Windows box for it).

Co-authored-by: dvasdekis <19279397+dvasdekis@users.noreply.github.com>
This commit is contained in:
Niko1221anddvasdekis committed 2026-10-13 04:36:04 +02:00
1 parent ea73bc2522
commit 2f335a5eab
2 files changed
+90 -1

No files matched your search

+1 -1
View File
@@ -521,7 +521,7 @@ In the task's properties set both of these (the defaults are the opposite):
(Both were changed at once, so the isolated effect of each is not measured.) If the model still starts
slowly, the engine prints a hint under its `loaded ... GiB at ...` line naming this cause.
**Large pages need a new logon (#1412).** Granting "Lock pages in memory" (`secpol.msc`, User Rights Assignment) to the account that runs the engine takes effect at the next logon: Windows puts the privilege in the access token when the session starts, so log off and on (or reboot) after granting it. Until then the startup log still says the large pages were refused.
**Large pages need a new logon (#1412).** Granting "Lock pages in memory" (`secpol.msc`, User Rights Assignment) to the account that runs the engine takes effect at the next logon: Windows puts the privilege in the access token when the session starts, so log off and on (or reboot) after granting it. Until then the startup log still says the large pages were refused. `tools\windows\enable_large_pages.ps1` (run as Administrator) grants it to the current account with `secedit`.
### Chat in the terminal (optional)
+89
View File
@@ -0,0 +1,89 @@
<#
.SYNOPSIS
Enables the 'Lock pages in memory' privilege (SeLockMemoryPrivilege) on Windows.
.DESCRIPTION
Strata keeps the experts the GPU does not hold in a host memory arena. With SeLockMemoryPrivilege
granted, Windows lets it allocate that arena in 2 MB large pages (MEM_LARGE_PAGES); without it the
engine says at start that the large pages were refused and uses 4 KB pages (docs/DETAILS.md, #1412).
The same can be done by hand with secpol.msc (User Rights Assignment, "Lock pages in memory").
NOTE: Windows applies security token privilege changes ONLY after sign-out/sign-in or reboot.
#>
[CmdletBinding()]
param (
[string]$AccountName = $env:USERNAME
)
function Test-IsAdmin {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (-not (Test-IsAdmin)) {
Write-Host "[!] This script must be run as Administrator." -ForegroundColor Yellow
Write-Host " Right-click PowerShell -> 'Run as Administrator', then run:"
Write-Host " .\tools\windows\enable_large_pages.ps1"
Write-Host ""
Write-Host " GUI Alternative:"
Write-Host " 1. Press Win + R, type 'secpol.msc' and press Enter."
Write-Host " 2. Navigate to: Security Settings -> Local Policies -> User Rights Assignment"
Write-Host " 3. Double-click 'Lock pages in memory'."
Write-Host " 4. Click 'Add User or Group...', add '$AccountName', and click OK."
Write-Host " 5. Sign out of Windows and sign back in."
exit 1
}
Write-Host "=== Configuring 'Lock pages in memory' (SeLockMemoryPrivilege) for $AccountName ===" -ForegroundColor Cyan
$tempInf = [System.IO.Path]::GetTempFileName()
$tempSdb = [System.IO.Path]::ChangeExtension($tempInf, ".sdb")
try {
Write-Host "1. Exporting current security policy..."
secedit /export /cfg $tempInf | Out-Null
$content = Get-Content $tempInf -Raw
$userSid = (New-Object System.Security.Principal.NTAccount($AccountName)).Translate([System.Security.Principal.SecurityIdentifier]).Value
if ($content -match "SeLockMemoryPrivilege\s*=\s*(.*)") {
$currentList = $matches[1].Trim()
if ($currentList -match [regex]::Escape($userSid) -or $currentList -match [regex]::Escape($AccountName)) {
Write-Host "[OK] $AccountName already possesses SeLockMemoryPrivilege." -ForegroundColor Green
Write-Host " If 'whoami /priv' still shows it as missing, please SIGN OUT and sign back in to refresh your token."
return
}
$newList = "$currentList,*$userSid"
$content = $content -replace "SeLockMemoryPrivilege\s*=.*", "SeLockMemoryPrivilege = $newList"
} else {
# Section [Privilege Rights]
if ($content -match "\[Privilege Rights\]") {
$content = $content -replace "\[Privilege Rights\]", "[Privilege Rights]`r`nSeLockMemoryPrivilege = *$userSid"
} else {
$content += "`r`n[Privilege Rights]`r`nSeLockMemoryPrivilege = *$userSid`r`n"
}
}
Set-Content -Path $tempInf -Value $content -Encoding ASCII
Write-Host "2. Importing updated policy database..."
secedit /import /db $tempSdb /cfg $tempInf | Out-Null
Write-Host "3. Applying updated policy to Windows system..."
secedit /configure /db $tempSdb /cfg $tempInf /areas USER_RIGHTS | Out-Null # only the user rights, nothing else of the exported policy
Write-Host ""
Write-Host "[SUCCESS] SeLockMemoryPrivilege has been granted to $AccountName ($userSid)!" -ForegroundColor Green
Write-Host "==========================================================================" -ForegroundColor Cyan
Write-Host "IMPORTANT: You MUST sign out of Windows and sign back in (or restart)" -ForegroundColor Yellow
Write-Host " for the new privilege to take effect on your user session." -ForegroundColor Yellow
Write-Host "==========================================================================" -ForegroundColor Cyan
}
catch {
Write-Host "[ERROR] Failed to configure privilege automatically: $_" -ForegroundColor Red
Write-Host "Please use the GUI steps via secpol.msc outlined above."
}
finally {
if (Test-Path $tempInf) { Remove-Item $tempInf -Force -ErrorAction SilentlyContinue }
if (Test-Path $tempSdb) { Remove-Item $tempSdb -Force -ErrorAction SilentlyContinue }
}