fix(agc): cache Linux describePages results #4395

Merged
oneandonlydean merged 3 commits from upstream-pr/4395 into main 2026-10-12 10:54:52 +00:00
oneandonlydean commented 2026-10-12 09:12:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T09:12:20Z.


What

This carries #1810 by @Swastik-51, rebased onto main after #3454, with the commits and their authors kept: fix(agc): cache Linux describePages results (@Swastik-51), fix(agc): store only the requested pages of a Linux page query (@ahir061) and the test commit I pushed to that branch on 10-10. #1810 was reviewed and accepted there; it could not go green because the AI-assisted: line of its description was never answered, which only the author can do on his PR. The only conflict was the name #3454 gave the query helper: ProcMapsQueryFd() is now HostMapping::QueryFd(), and the carry uses the new name. The changed lines are otherwise the same as in #1810.

Fixes #1791.

On Linux, describePages asked the kernel (PROCMAP_QUERY, or /proc/self/maps on kernels before 6.11) what a guest range maps to but did not store the readable pages it found in the page table, so every uncached guest-range check repeated the query.

  • Adds PageStates::record(), shared by both platforms, which stores the page state. The Windows VirtualQuery path already did this inline and now calls it.
  • The PROCMAP_QUERY path and the /proc/self/maps path store their results the same way.
  • Only the pages of the request, rounded out to whole pages, are stored. Linux merges adjacent anonymous mappings with equal flags, so an arena VMA can span GiBs, and storing all of it on each miss would rewrite every page after an invalidation.
  • The generation check and the invalidation through the allocation registry are unchanged.

Titles, from the runs posted on #1810:

  • Hades II (PPSA36082): 25.8 → 32.7 fps, p95 frame time 41.2 → 32.5 ms (@Raghav314, RTX 4090, standing in the hub for 20 s); 25.1-26.0 → 31.1-32.7 fps and 81.0 → 62.6 µs of AGC worker time per draw packet on a second machine (@eliyarson, RTX 3080 Ti, measured after #3454 with the same resolution of the rename). Before the change the PROCMAP_QUERY ioctl from describePages was the top frame in 116 of 400 samples of the AGC worker thread there.
  • Disney Epic Mickey: Rebrushed (PPSA15657) on kernel 6.8, where the /proc/self/maps path is used: logos and intro movies 5-6 → 57-60 fps, and the title screen is reached (@johnmaia).
  • PPSA28997: 7.4 → 60.3 fps where the frame rate was bound by these queries (@jeffrey12cali).

Tested

Linux (CachyOS, kernel 7.2, GCC 16.2.1, RTX 4090, NVIDIA 610.57.04), Release, configured with the CI flags (-DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON), on main 2979ae37:

  • Full build passes.
  • agc_driver_graphics (the arena block of RunUnmappedGapTests, which runs on Linux since #861): with GuestMemory.cpp as on main and the test from this PR it fails with a checked arena page was queried again instead of read from the page table; with the change it passes.
  • ctest -R "agc|guest_|memory|write": 752 of 752 pass, on main and with the change (agc_driver_stencil_ref_export reports skipped on both).
  • python3 tools/check_conventions.py --base origin/main and tools/check_test_registration.py pass.
  • A 2D title we test with: one unattended run to gameplay passes its frame checks, no skipped draws, no fatal lines, no GPU errors in the kernel log.
  • The fps figures above are the testers' own, from #1810; I did not measure a frame rate difference here.

Not tested here: the /proc/self/maps path (this kernel has PROCMAP_QUERY; @johnmaia ran it on kernel 6.8, before the rebase), Windows (the VirtualQuery path only moves into record(); the CI job is the test), and Hades II on this rebase.

Checklist

  • Based on current main; no other open PR implements the same functions (#1810 is the PR this replaces)
  • 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 in TechnicalDebt
  • 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
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4827283410 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4395). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T09:12:20Z. --- ### What This carries #1810 by @Swastik-51, rebased onto `main` after #3454, with the commits and their authors kept: `fix(agc): cache Linux describePages results` (@Swastik-51), `fix(agc): store only the requested pages of a Linux page query` (@ahir061) and the test commit I pushed to that branch on 10-10. #1810 was reviewed and accepted there; it could not go green because the `AI-assisted:` line of its description was never answered, which only the author can do on his PR. The only conflict was the name #3454 gave the query helper: `ProcMapsQueryFd()` is now `HostMapping::QueryFd()`, and the carry uses the new name. The changed lines are otherwise the same as in #1810. Fixes #1791. On Linux, `describePages` asked the kernel (`PROCMAP_QUERY`, or `/proc/self/maps` on kernels before 6.11) what a guest range maps to but did not store the readable pages it found in the page table, so every uncached guest-range check repeated the query. - Adds `PageStates::record()`, shared by both platforms, which stores the page state. The Windows `VirtualQuery` path already did this inline and now calls it. - The `PROCMAP_QUERY` path and the `/proc/self/maps` path store their results the same way. - Only the pages of the request, rounded out to whole pages, are stored. Linux merges adjacent anonymous mappings with equal flags, so an arena VMA can span GiBs, and storing all of it on each miss would rewrite every page after an invalidation. - The generation check and the invalidation through the allocation registry are unchanged. Titles, from the runs posted on #1810: - Hades II (PPSA36082): 25.8 → 32.7 fps, p95 frame time 41.2 → 32.5 ms (@Raghav314, RTX 4090, standing in the hub for 20 s); 25.1-26.0 → 31.1-32.7 fps and 81.0 → 62.6 µs of AGC worker time per draw packet on a second machine (@eliyarson, RTX 3080 Ti, measured after #3454 with the same resolution of the rename). Before the change the `PROCMAP_QUERY` ioctl from `describePages` was the top frame in 116 of 400 samples of the AGC worker thread there. - Disney Epic Mickey: Rebrushed (PPSA15657) on kernel 6.8, where the `/proc/self/maps` path is used: logos and intro movies 5-6 → 57-60 fps, and the title screen is reached (@johnmaia). - PPSA28997: 7.4 → 60.3 fps where the frame rate was bound by these queries (@jeffrey12cali). ### Tested Linux (CachyOS, kernel 7.2, GCC 16.2.1, RTX 4090, NVIDIA 610.57.04), Release, configured with the CI flags (`-DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON`), on `main` 2979ae37: - Full build passes. - `agc_driver_graphics` (the arena block of `RunUnmappedGapTests`, which runs on Linux since #861): with `GuestMemory.cpp` as on `main` and the test from this PR it fails with `a checked arena page was queried again instead of read from the page table`; with the change it passes. - `ctest -R "agc|guest_|memory|write"`: 752 of 752 pass, on `main` and with the change (`agc_driver_stencil_ref_export` reports skipped on both). - `python3 tools/check_conventions.py --base origin/main` and `tools/check_test_registration.py` pass. - A 2D title we test with: one unattended run to gameplay passes its frame checks, no skipped draws, no fatal lines, no GPU errors in the kernel log. - The fps figures above are the testers' own, from #1810; I did not measure a frame rate difference here. Not tested here: the `/proc/self/maps` path (this kernel has `PROCMAP_QUERY`; @johnmaia ran it on kernel 6.8, before the rebase), Windows (the `VirtualQuery` path only moves into `record()`; the CI job is the test), and Hades II on this rebase. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#1810 is the PR this replaces) - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 - [x] AI-assisted: yes (Claude Code)
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!4395
No description provided.