perf(libkernel): prefault mapped Windows direct memory in the background #4290

Closed
moong15 wants to merge 2 commits from upstream-pr/4290 into main
moong15 commented 2026-10-12 04:57:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by moong15 on 2026-10-12T04:57:14Z.


What

Opt-in background prefaulting of mapped Windows direct memory. With APS5_PREFAULT_MEMORY set, a worker processes mapped ranges of at least 2 MiB using VirtualLock followed by VirtualUnlock in 2 MiB chunks. It requests soft working-set headroom of at least 64 MiB minimum and 128 MiB maximum. The worker does not write the pages. Linux is unchanged.

This aims to move first-touch page residency work away from guest loading threads. It is separate from the write-protection exception tracking fixed by #4535, which is now merged. The option can increase memory residency and remains disabled by default. A successful lock is followed immediately by an unlock, so residency is not guaranteed afterward.

Reopened after #4535 merged and rebased without conflicts onto main ea2bbefb2. Current head: b2e1166df. The diff remains one file, 56 added lines. The earlier adjacent #4281 change is already in main. An open-PR search for prefault/VirtualLock found no competing implementation; automated overlap review remains pending.

Tested

Reopening validation: git diff --check passed. No build, runtime test or game comparison has been rerun on the rebased b2e1166df head. This remains a draft while that validation and the current repository's performance-report evidence are pending.

Historical evidence, not validation of the rebased head: Windows 11 Pro 26200, Ryzen 7 9800X3D, 47 GB RAM, Radeon RX 9070 XT (driver 32.0.32015.2008), WinLibs GCC 15.2, Release. guest_memory previously passed with the option unset and set.

Earlier Hades II PPSA36082 v01.006 warm-cache runs used a local d146ec1b6 build with this branch's DirectMemory.cpp, unpublished diagnostics, two cache options, APS5_HOST_IMPORT_MIB=16384 and APS5_NO_WRITE_WATCH=1 in both arms. Without prefault, 4/4 runs crashed with a LoadTaskScheduler null write around 7.4-7.5 seconds; with prefault, 5/5 survived their observation windows (three 69-77 seconds and two 40 seconds) and the longer runs opened menu audio banks. Those results do not establish performance or correctness with normal write tracking on current main, nor prove the crash's cause.

Subsequent combined-fix investigation and its limitations are recorded in #4535. Fresh matched main-versus-prefault measurements with write tracking enabled are needed here. No current-head speed, cold-cache, rendered-menu or gameplay claim is made. Before making a speed claim, collect the same-machine/same-scene summary lines and attach traces as required by the Performance report issue form. Full upstream CI requires a maintainer's manual workflow run.

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 comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none; #4535 is merged and included in the base
  • Unblocks: none; investigating PPSA36082 #1965, current-head confirmation pending
  • AI-assisted: yes (Claude Code, OpenAI Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4825104639 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4290). Originally posted by [moong15](https://github.com/moong15) on 2026-10-12T04:57:14Z. --- ### What Opt-in background prefaulting of mapped Windows direct memory. With `APS5_PREFAULT_MEMORY` set, a worker processes mapped ranges of at least 2 MiB using `VirtualLock` followed by `VirtualUnlock` in 2 MiB chunks. It requests soft working-set headroom of at least 64 MiB minimum and 128 MiB maximum. The worker does not write the pages. Linux is unchanged. This aims to move first-touch page residency work away from guest loading threads. It is separate from the write-protection exception tracking fixed by #4535, which is now merged. The option can increase memory residency and remains disabled by default. A successful lock is followed immediately by an unlock, so residency is not guaranteed afterward. Reopened after #4535 merged and rebased without conflicts onto `main` ea2bbefb2. Current head: b2e1166df. The diff remains one file, 56 added lines. The earlier adjacent #4281 change is already in main. An open-PR search for prefault/VirtualLock found no competing implementation; automated overlap review remains pending. ### Tested **Reopening validation:** `git diff --check` passed. No build, runtime test or game comparison has been rerun on the rebased b2e1166df head. This remains a draft while that validation and the current repository's performance-report evidence are pending. **Historical evidence, not validation of the rebased head:** Windows 11 Pro 26200, Ryzen 7 9800X3D, 47 GB RAM, Radeon RX 9070 XT (driver 32.0.32015.2008), WinLibs GCC 15.2, Release. `guest_memory` previously passed with the option unset and set. Earlier Hades II PPSA36082 v01.006 warm-cache runs used a local d146ec1b6 build with this branch's DirectMemory.cpp, unpublished diagnostics, two cache options, `APS5_HOST_IMPORT_MIB=16384` and **`APS5_NO_WRITE_WATCH=1`** in both arms. Without prefault, 4/4 runs crashed with a LoadTaskScheduler null write around 7.4-7.5 seconds; with prefault, 5/5 survived their observation windows (three 69-77 seconds and two 40 seconds) and the longer runs opened menu audio banks. Those results do not establish performance or correctness with normal write tracking on current main, nor prove the crash's cause. Subsequent combined-fix investigation and its limitations are recorded in #4535. Fresh matched main-versus-prefault measurements with write tracking enabled are needed here. No current-head speed, cold-cache, rendered-menu or gameplay claim is made. Before making a speed claim, collect the same-machine/same-scene summary lines and attach traces as required by the Performance report issue form. Full upstream CI requires a maintainer's manual workflow run. ### 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 comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none; #4535 is merged and included in the base - [x] Unblocks: none; investigating PPSA36082 #1965, current-head confirmation pending - [x] AI-assisted: yes (Claude Code, OpenAI Codex)
github-actions[bot] commented 2026-10-13 06:49:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T06:49:43Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4508 core/libs/prx/libkernel/CMakeLists.txt L1117
#4725 core/libs/prx/libkernel/CMakeLists.txt L1117
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139991183 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4290#issuecomment-6139991183). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T06:49:43Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4508 | `core/libs/prx/libkernel/CMakeLists.txt` [L1117](https://github.com/boykopovar/AnyPS5/blob/14036cb0e8aeddb686a6c745193610528bd8a9f0/core/libs/prx/libkernel/CMakeLists.txt#L1117) | | | | #4725 | `core/libs/prx/libkernel/CMakeLists.txt` [L1117](https://github.com/boykopovar/AnyPS5/blob/14036cb0e8aeddb686a6c745193610528bd8a9f0/core/libs/prx/libkernel/CMakeLists.txt#L1117) | | |
xXPBSXx commented 2026-10-13 08:14:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:14:17Z.


Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release: this PR merged onto main c080fc2d5 (no conflict).

  • windows_prefault_enabled (0.64 s) and windows_prefault_disabled (0.38 s) pass with the PR.
  • With the PR's change to DirectMemory.cpp taken back to main, windows_prefault_enabled fails (Prefault check failed at WindowsPrefault.cpp:39, 6.4 s); windows_prefault_disabled still passes. So the new check fails without the change and the test finishes in well under 30 s either way.

Not tested: Linux (Windows-only code), a console, a title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141283341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4290#issuecomment-6141283341). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T08:14:17Z. --- Tested on Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release: this PR merged onto `main` `c080fc2d5` (no conflict). - `windows_prefault_enabled` (0.64 s) and `windows_prefault_disabled` (0.38 s) pass with the PR. - With the PR's change to `DirectMemory.cpp` taken back to `main`, `windows_prefault_enabled` fails (`Prefault check failed` at `WindowsPrefault.cpp:39`, 6.4 s); `windows_prefault_disabled` still passes. So the new check fails without the change and the test finishes in well under 30 s either way. Not tested: Linux (Windows-only code), a console, a title run. AI-assisted (Claude Code).

Pull request closed

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!4290
No description provided.