Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
eljackjoestar-cmd:codex/reserve-direct-memory
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
eljackjoestar-cmd:codex/reserve-direct-memory

Conversation

@eljackjoestar-cmd

Copy link
Copy Markdown
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants