Memory: Implement lazy commit for physical memory backing store (fixes Windows commit limit & enables Dreaming Sarah on original ROG Ally Z1 Extreme hardware) #238

Closed
github-bot wants to merge 2 commits from gh-pr/238/head into gh-pr/238/base
Owner

@⁠necat101 on GitHub · 2026-08-12 03:34 UTC · original
necat101:main → main · +87 −1 · 4 files · 2 commits · closed without merging

This PR resolves a critical memory management issue on Windows where the emulator would commit the entire 13.5 GiB physical memory backing store during startup, frequently hitting the system's commit limit before any game code could execute. The fix implements lazy page commitment, reducing initial committed memory from ~13.5 GiB to just ~16 KiB.

With this change, Dreaming Sarah (PPSA02929) is now playable at ~60 FPS with full input support, audio, and save/continue functionality.

The Problem
On Windows, VirtualAlloc with SEC_COMMIT was forcing the OS to reserve and commit the full 13.5 GiB of emulated physical memory at emulator launch. On systems with moderate RAM/commit limits, this would fail with error 0x5AF before the game could even reach the title screen. The existing error handling would report this as a generic "backing store unavailable" without clear diagnostic information.

The Fix
memoryAddressSpace.inc: Changed the backing section from SEC_COMMIT to SEC_RESERVE, then introduced lazy commitment of backing pages as guest memory accesses occur.

Error Handling: Added a distinct BackingCommitFailed diagnostic to differentiate commitment failures from other backing-store issues.

Memory Management: Extended memory.cpp and memory.h with supporting hooks to track and manage lazy commitment.

Tests: Added regression coverage in VirtualMemoryAllocationTests.cpp to verify lazy-commit behavior. The full virtual-memory test suite passes.

Result: The new test shows only 16 KiB committed at startup versus the previous 13.5 GiB.

Verification
Dreaming Sarah was exercised beyond the title screen to validate the fix and overall emulator stability:

✅ Title/menu renders correctly

✅ "New Game" enters successfully

✅ Intro sequence plays

✅ Forest gameplay renders correctly

✅ Character movement and camera scrolling work as expected

✅ Sustained ~60 FPS during gameplay probes

✅ SDL audio opens successfully at 48 kHz stereo

✅ Pause menu functions correctly

✅ In-game "Save" writes localStorage.json to _SaveData\PPSA02929\SAVEDATA00\

✅ Graceful shutdown completes without errors

✅ Relaunch enables "Continue"

✅ "Continue" restores saved forest state correctly

✅ No fatal, unsupported, unimplemented, or failure diagnostics observed during probes

**@⁠necat101** on GitHub · 2026-08-12 03:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/238) `necat101:main` → `main` · +87 −1 · 4 files · 2 commits · closed without merging This PR resolves a critical memory management issue on Windows where the emulator would commit the entire 13.5 GiB physical memory backing store during startup, frequently hitting the system's commit limit before any game code could execute. The fix implements lazy page commitment, reducing initial committed memory from ~13.5 GiB to just ~16 KiB. With this change, Dreaming Sarah (PPSA02929) is now playable at ~60 FPS with full input support, audio, and save/continue functionality. The Problem On Windows, VirtualAlloc with SEC_COMMIT was forcing the OS to reserve and commit the full 13.5 GiB of emulated physical memory at emulator launch. On systems with moderate RAM/commit limits, this would fail with error 0x5AF before the game could even reach the title screen. The existing error handling would report this as a generic "backing store unavailable" without clear diagnostic information. The Fix memoryAddressSpace.inc: Changed the backing section from SEC_COMMIT to SEC_RESERVE, then introduced lazy commitment of backing pages as guest memory accesses occur. Error Handling: Added a distinct BackingCommitFailed diagnostic to differentiate commitment failures from other backing-store issues. Memory Management: Extended memory.cpp and memory.h with supporting hooks to track and manage lazy commitment. Tests: Added regression coverage in VirtualMemoryAllocationTests.cpp to verify lazy-commit behavior. The full virtual-memory test suite passes. Result: The new test shows only 16 KiB committed at startup versus the previous 13.5 GiB. Verification Dreaming Sarah was exercised beyond the title screen to validate the fix and overall emulator stability: ✅ Title/menu renders correctly ✅ "New Game" enters successfully ✅ Intro sequence plays ✅ Forest gameplay renders correctly ✅ Character movement and camera scrolling work as expected ✅ Sustained ~60 FPS during gameplay probes ✅ SDL audio opens successfully at 48 kHz stereo ✅ Pause menu functions correctly ✅ In-game "Save" writes localStorage.json to _SaveData\PPSA02929\SAVEDATA00\ ✅ Graceful shutdown completes without errors ✅ Relaunch enables "Continue" ✅ "Continue" restores saved forest state correctly ✅ No fatal, unsupported, unimplemented, or failure diagnostics observed during probes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:14:03 +00:00
github-bot closed this pull request 2026-11-26 09:14:03 +00:00
Author
Owner

@⁠necat101 on GitHub · 2026-08-13 07:01 UTC · original

!bump

**@⁠necat101** on GitHub · 2026-08-13 07:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/238#issuecomment-5277127445) !bump
Author
Owner

@⁠Nmzik on GitHub · 2026-08-29 21:38 UTC · original

#390

**@⁠Nmzik** on GitHub · 2026-08-29 21:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/238#issuecomment-5465032899) https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/390

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.