gh-144319: obtain SeLockMemoryPrivilege on Windows#144928
gh-144319: obtain SeLockMemoryPrivilege on Windows#144928pablogsal merged 3 commits intopython:mainfrom
Conversation
can be used on Windows
|
Skipping news because that's already covered by @pablogsal 's previous PRs. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
pablogsal
left a comment
There was a problem hiding this comment.
LGTM! Thanks for working in this 🤘
| // but without having all privileges adjusted (ERROR_NOT_ALL_ASSIGNED). | ||
| BOOL status = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL); | ||
| DWORD error = GetLastError(); | ||
| if (!status || (error != ERROR_SUCCESS)) |
There was a problem hiding this comment.
If I am not missing anything seems that the MSDN docs state that AdjustTokenPrivileges returns nonzero (success) even when not all privileges were adjusted: we correctly handle this via GetLastError(). However, the error message "failed to obtain SeLockMemoryPrivilege for huge pages" doesn’t distinguish between:
- The token adjustment API failing entirely
- The privilege simply not being held
The second case is the common, expected failure mode (user just doesn’t have the privilege). A more actionable error message for that case would help like perhaps "SeLockMemoryPrivilege not held; grant it via Local Security Policy or disable PYTHON_PYMALLOC_HUGEPAGES".
|
…on into fix-pythongh-138577 * 'fix-pythongh-138577' of github.com:CuriousLearner/cpython: pythongh-146202: Create tmp_dir in regrtest worker (python#146347) pythongh-144319: obtain SeLockMemoryPrivilege on Windows (python#144928) pythongh-146199: Fix error handling in `code_richcompare` when `PyObject_RichCompareBool` fails (python#146200) pythongh-146197: Include a bit more information in sys._emscripten_info.runtime (python#146346) pythongh-135871: Reload lock internal state while spinning in `PyMutex_LockTimed` (pythongh-146064) pythongh-145719: Add `.efi` file detection in `mimetypes` (python#145720)
Obtain SeLockMemoryPrivilege on startup on Windows to be able to use large pages when requested by setting the environment variable
PYTHON_PYMALLOC_HUGEPAGES.I've decided to fail if that doesn't succeed instead of silently switching to normal 4K pages and updated the documentation.
Using
bench_obmalloc.pyfrom the issue I getfor an AMD64 VS2026 release build (no PGO) on my PC (Haswell i5-4570, Windows 10).
📚 Documentation preview 📚: https://cpython-previews--144928.org.readthedocs.build/