memory: prefault large direct-memory mappings on Windows (Hades II) #2284
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2284
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2284"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@JonathanBencke on GitHub · 2026-11-14 23:19 UTC · original
JonathanBencke:fix/hades2-windows-prefault→main· +42 −0 · 1 files · 1 commits · openSummary
Hades II (PPSA36082, 01.006.000) crashes on Windows about 3.8 s after launch, while it loads
Content/Packages/1080p/Fx.pkg:This is the crash that #1104 analysed and fixed for Linux only (closed, not merged). This PR is the Windows counterpart. Large writable direct-memory mappings are touched once when they are mapped, so the game no longer pays a host page fault per 4 KiB page while it streams textures. With the change the game gets past loading and plays at 60 fps on the same machine.
Cause
The faulting instruction is a store in the game's
libc.prxmemcpy(module base0x910000000), called from a row-copy loop in the eboot at0x90028fa00. That loop copies a 4096x1024 texture (row pitch0x4000, 1024 rows) into an upload buffer whose address is 0.Decoded from the stack in the crash log: the upload region's descriptor is filled by the eboot helper at
0x900067610. That helper asks the game's own allocator (0x9003eb290) for0x1000000bytes (16 MiB) and gets back an allocation record whose address field is NULL. The game does not check it and copies into it.The allocator sub-allocates these 16 MiB buffers from a 512 MiB direct-memory pool (
0x240200000). The pool runs out for the reason given in #1104: the streamer frees each upload buffer only after it has tiled the texture into the 6 GiB direct-memory pool (0x260200000). Every first write to a page of that pool is a host page fault, so the streamer falls behind the loader and the 16 MiB buffers pile up.On Windows,
MapDirectMemorymaps a direct range as a view of the pagefile-backed section (GuestAddressSpace::MapBacking). Windows gives the pages of a section view only on first access, so this is the same first-touch cost as the anonymous mappings on Linux.The crash depends on host speed. #2148 reports Hades II as In game on an i7-13700K with build
589bd14. On this Ryzen 5 5500 it crashes every time: 3 of 3 runs with today'smain(3e226bf).Change
src/kernel/memory.cpp, Windows only:PrefaultDirectMapping. AfterMapDirectMemoryhas mapped a range, and beforeMapGpuRange, it reads one byte per 4 KiB host page.ReadWrite.KYTY_NO_PREFAULTdisables it, the same opt-out as #1104.prefault = <addr> + <len> in <ms>line to the printf log.MADV_POPULATE_WRITEpath from #1104 is not part of this PR.Console direct memory is physically backed, so committing it at map time is what the game expects. Hades II maps 7.7 GiB of direct memory, so its resident memory goes up by that much right at boot. That is the same budget the game has on the console.
Evidence
Machine: Windows 11 Pro, AMD Ryzen 5 5500 (6C/12T), NVIDIA GeForce RTX 3060 12 GB (driver 621.01), 32 GB RAM.
Build:
3e226bf+ this commit, Release, clang-cl.Raw logs (paths replaced): https://github.com/JonathanBencke/KytyPS5/tree/evidence-hades2-prefault
KYTY_NO_PREFAULT=1(same asmain)LoadTaskScheduler,pc=0x910003fb0,address=0x0Prefault cost, measured in a run with the full trace:
0x2002000000x240200000(upload pool)0x260200000(texture pool)0x3e0200000In-game
With prefault on, gameplay at 60 fps. The title bar shows the build, the GPU, the CPU and the frame counter (frame 1440 at 30 s, frame 4790 at 86 s):
Tests
kyty_emulatorandlauncher(clang-cl from LLVM 23.1.5, MSVC 14.44 toolset).virtual_memory_allocation_tests,memory_tracker_tests,page_manager_tests,image_page_table_tests,sync_on_address_testsandevent_queue_lifetime_testspass on this branch.Related
AI use: investigated and written with Claude Code (it read the crash dumps, disassembled the eboot around the fault, found #1104, wrote the change and ran the A/B tests). The runs and screenshots are from my machine and my copy of the game.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-14 23:24 UTC · original
No actionable comments were generated in the recent review.
Walkthrough
The direct-memory mapping path now calls
PrefaultDirectMappingafter a successful mapping and beforeMapGpuRange. On Windows, the helper reads one byte per 4 KiB page for mappings of at least 64 MiB inReadWritemode, unlessKYTY_NO_PREFAULTis set. It logs the elapsed time. On other platforms, the helper does nothing.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
4d2ffThis change prefaults large direct-memory mappings on Windows to reduce texture-streaming stalls, and it can be turned off with an environment variable. No concrete defect was found. One narrow concurrency scenario involving replaced mappings with active page watchers could not be fully checked, but it is not established. The change looks reasonably safe to merge, though other games with large mappings were not tested.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: a Windows-only prefault of large direct-memory mappings, which the objectives and summary confirm. It also names the target game, Hades II. The title is specific and accurate, so it passes.
Full details: Description check
Explanation
The description states the crash being fixed, the Windows-only prefault helper, the 64 MiB and ReadWrite conditions, the KYTY_NO_PREFAULT opt-out, logging, and test results. It relates directly to the changeset, so it passes.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
32e2b7e6-801f-448d-8e71-799d4cc66663Reviewing files that changed from the base of the PR and between
3e226bff9dand4d2ff1b569.src/kernel/memory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.