memory: prefault large direct-memory mappings on Linux (fixes Hades II load crash) #1104
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!1104
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1104/head"
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?
@Xfedis on GitHub · 2026-10-06 08:50 UTC · original
Xfedis:linux-prefault-direct-memory→main· +28 −0 · 1 files · 1 commits · closed without mergingProblem
On Linux, Hades II (PPSA36082, 01.006.000) crashes about 2.5 s after launch while it loads
Content/Packages/1080p/Fx.pkg:The faulting instruction is a libc
memcpywith a NULL destination. The game requests a 16 MiB staging buffer from its own VMA-style allocator. That allocator sub-allocates from a 512 MiB direct-memory pool (0x240200000). The pool is full, so the game gets NULL back and copies the texture into it anyway.Why the pool fills up
I traced allocations and frees in the game's allocator with gdb:
Fix
In
KernelMapDirectMemory, writable direct mappings of 64 MiB or more getMADV_HUGEPAGEfollowed byMADV_POPULATE_WRITE. Console memory is physically backed anyway, so this matches the behavior the game expects. With the patch Hades II gets through loading and reaches the main menu at a steady 60 fps.KYTY_PLATFORM_LINUX, so the Windows and macOS code paths don't change.KYTY_NO_PREFAULTkeeps demand faulting.MADV_POPULATE_WRITEon kernels older than 5.14), the failure is logged and the mapping falls back to demand paging.I used an environment variable because it was the smallest change. I'm happy to turn the opt-out into a proper config or launcher setting if you'd prefer that.
Testing
memcpy. After the patch it loads through to the main menu at 60 fps, fullscreen 2560×1440.git clang-formatreports no changes.AI use disclosure
Claude Code (Claude Opus 5.5) did the investigation (gdb tracing of the guest allocator, thread sampling, fault counting) and wrote the change. The diff was built and tested locally on the hardware above.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-06 09:04 UTC · original
📝 Walkthrough
Walkthrough
KernelMapDirectMemorynow callsPrefaultDirectMappingafter allocation-callback processing. On Linux, the helper skips mappings smaller than 64 MiB, mappings withoutPROT_CPU_WRITE, and mappings whenKYTY_NO_PREFAULTis set. For other mappings, it requests huge pages and populates writable pages. It logs an error if population fails. On other platforms, the helper does nothing.Suggested reviewers:
nmzikPriority: ⬆️ High
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
d376aThe change breaks the supported macOS build. Exclude macOS from the Linux-specific advice branch before merging.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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
Comment
@coderabbitai helpto get the list of available commands.@ -98,0 +120,4 @@(void)prot;#endif}@coderabbitai[bot] on GitHub · 2026-10-06 09:04 UTC · original
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 15159
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 20659
🌐 Web query:
Apple XNU macOS SDK sys/mman.h MADV_HUGEPAGE MADV_NORMAL MADV_FREE authoritative source💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6380
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 218
Exclude macOS from the Linux-only advice branch.
On macOS, CMake sets
KYTY_PLATFORM_LINUX, so this branch compiles. Apple’s publicsys/mman.hdoes not declareMADV_HUGEPAGE, and this code has no fallback for it. The undeclared identifier breaks the macOS build.Suggested fix
@coderabbitai[bot] on GitHub · 2026-10-06 09:04 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
217abc39-60c9-49b5-adcf-a19628f0b326📥 Commits
Reviewing files that changed from the base of the PR and between
cdb64bfd4fandd376a6c21f.📒 Files selected for processing (1)
src/kernel/memory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
Pull request closed