perf(libkernel): commit Windows direct backing when mapped #4281

Merged
eljackjoestar-cmd merged 1 commit from upstream-pr/4281 into main 2026-10-12 10:49:43 +00:00
eljackjoestar-cmd commented 2026-10-12 03:59:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eljackjoestar-cmd on 2026-10-12T03:59:54Z.


What

On Windows, creating direct-memory backing charges its entire allocation to the system commit limit even when only a small part is mapped. Lost Soul Aside allocates almost all 13.5 GiB of guest direct memory at startup; the unused backing leaves too little commit headroom for level loading.

Create paging-file sections with SEC_RESERVE, then commit reserved mapped pages before applying guest protection. Existing committed views retain their contents. Physical contents remain shared between aliases and survive unmap/remap until their backing is released. Linux keeps its current implementation. This follows Microsoft's CreateFileMapping and VirtualAlloc contracts; it changes host allocation lifetime, not guest protection or shader semantics.

Checked open PRs for SEC_RESERVE and direct-memory commitment. #2054 changes singly mapped pages to private write-watched storage to avoid Windows exception-frame corruption; #637 changes write tracking; neither implements this backing reservation. No equivalent fix was found.

Tested

Separate checkout based on main d146ec1b6, Windows 11 x64, WinLibs GCC 15.2, Release, BUILD_TESTING=ON. libc, libkernel and guest_memory_tests build. guest_memory passes in 1.46 s, including new sparse 256 MiB backing checks that map its first and last pages, verify zero initialization, shared alias writes, unchanged distant contents and preservation across unmap/remap. Existing protection, physical reuse, partial release and alias tests remain passing.

A separate native probe allocates 2 GiB, maps 16 KiB at offset 1 GiB and verifies alias writes and remapped contents. System commit rose by 2,167,386,112 bytes immediately after allocation on the same-main baseline, versus 4,861,952 bytes with the integration candidate and 13,668,352 bytes with the isolated branch. These global counters include unrelated host activity; the large eager backing charge is absent, not a promise about exact per-page process accounting.

Lost Soul Aside integration testing with existing graphics/audio dependencies and #4271: startup had about 19.2 GiB commit headroom where the prior run had about 6.4 GiB. It reached the title menu and then level loading; near the end of loading about 3 GiB remained. The run subsequently aborted on buffer descriptor uses an unsupported type. Earlier cold startup still had an Unreal garbage-collection assertion. Gameplay, green flashes, startup crackling and full playability are not claimed fixed. Integration dependencies are excluded from this branch.

Committed pages are not decommitted merely by unmapping a view; their contents must survive later remapping. Commitment persists until the physical backing and remaining views are destroyed. Peak gameplay memory, Linux execution, older Windows versions and full CI remain unverified. No game data, logs, snapshots, probes or experimental diagnostics are committed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No new code comments; memory limitation recorded in TechnicalDebt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824753167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4281). Originally posted by [eljackjoestar-cmd](https://github.com/eljackjoestar-cmd) on 2026-10-12T03:59:54Z. --- ### What On Windows, creating direct-memory backing charges its entire allocation to the system commit limit even when only a small part is mapped. Lost Soul Aside allocates almost all 13.5 GiB of guest direct memory at startup; the unused backing leaves too little commit headroom for level loading. Create paging-file sections with `SEC_RESERVE`, then commit reserved mapped pages before applying guest protection. Existing committed views retain their contents. Physical contents remain shared between aliases and survive unmap/remap until their backing is released. Linux keeps its current implementation. This follows Microsoft's [CreateFileMapping](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingw) and [VirtualAlloc](https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc) contracts; it changes host allocation lifetime, not guest protection or shader semantics. Checked open PRs for `SEC_RESERVE` and direct-memory commitment. #2054 changes singly mapped pages to private write-watched storage to avoid Windows exception-frame corruption; #637 changes write tracking; neither implements this backing reservation. No equivalent fix was found. ### Tested Separate checkout based on main `d146ec1b6`, Windows 11 x64, WinLibs GCC 15.2, Release, BUILD_TESTING=ON. `libc`, `libkernel` and `guest_memory_tests` build. `guest_memory` passes in 1.46 s, including new sparse 256 MiB backing checks that map its first and last pages, verify zero initialization, shared alias writes, unchanged distant contents and preservation across unmap/remap. Existing protection, physical reuse, partial release and alias tests remain passing. A separate native probe allocates 2 GiB, maps 16 KiB at offset 1 GiB and verifies alias writes and remapped contents. System commit rose by 2,167,386,112 bytes immediately after allocation on the same-main baseline, versus 4,861,952 bytes with the integration candidate and 13,668,352 bytes with the isolated branch. These global counters include unrelated host activity; the large eager backing charge is absent, not a promise about exact per-page process accounting. Lost Soul Aside integration testing with existing graphics/audio dependencies and #4271: startup had about 19.2 GiB commit headroom where the prior run had about 6.4 GiB. It reached the title menu and then level loading; near the end of loading about 3 GiB remained. The run subsequently aborted on `buffer descriptor uses an unsupported type`. Earlier cold startup still had an Unreal garbage-collection assertion. Gameplay, green flashes, startup crackling and full playability are not claimed fixed. Integration dependencies are excluded from this branch. Committed pages are not decommitted merely by unmapping a view; their contents must survive later remapping. Commitment persists until the physical backing and remaining views are destroyed. Peak gameplay memory, Linux execution, older Windows versions and full CI remain unverified. No game data, logs, snapshots, probes or experimental diagnostics are committed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No new code comments; memory limitation recorded in TechnicalDebt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Codex)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4281
No description provided.