AGC: inaccessible guest pages are never cached, so on Linux before 6.11 every probe re-parses /proc/self/maps and Guardians of the Galaxy (PPSA01748) drops to 0.02 FPS; fix branch ready #6183

Closed
opened 2026-10-15 00:55:14 +00:00 by Tamalero · 3 comments
Tamalero commented 2026-10-15 00:55:14 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-15T00:55:14Z.


On Linux kernels without PROCMAP_QUERY (before 6.11, which includes Ubuntu 24.04 LTS's default 6.8), Guardians of the Galaxy reaches its language screen and then nearly stops: one frame every one to three minutes, with both GPUs idle. On a 6.11+ kernel the same build runs that screen at about 6 FPS. Forcing the fallback with APS5_NO_PROCMAP_QUERY=1 reproduces it on any kernel.

The cause is in GuestMemory's page table. describePages stores only readable runs, so an answer of "inaccessible" is never remembered. Guardians' table snapshots (TableSnapshotter::Column → ShaderMemory::accessible → GuestMemory::Accessible) keep probing a reserved, PROT_NONE part of the guest arena, about 190 times a second. With PROCMAP_QUERY each probe is one cheap ioctl. Without it, each probe parses the whole of /proc/self/maps (about 7,500 lines here).

Title: Marvel's Guardians of the Galaxy (PPSA01748 v01.006.000)
Where it stops: the language screen, on main 411e5e6d9 plus #6033 and one NpManager stub the title needs to start. Every run: 3 of 3 on kernel 6.8, 4 of 4 on kernel 7.2 with APS5_NO_PROCMAP_QUERY=1.

What the threads show

  • Under gdb at the stall, the guest's main thread and its job workers spin on one guest global. Both GPUs read 0% busy. That is the game waiting for its next frame, not the cause.
  • One host thread reads /proc/self/maps at about 140 MB/s (715 MB in 5 s, 4 KB reads; /proc/<pid>/task/<tid>/io). Its stack: ResourceMaterializer::Materialize → TableSnapshotter::Snapshot → TableSnapshotter::Column → ShaderMemory::accessible → GuestMemory::Accessible → verify → describePages → std::getline.
  • A local counter on the fallback path, over 80,000 parses: 78,823 were for mapped arena addresses. All were 4-byte probes into one reservation, 2a3490000-2d1160000 ---p. Of the rest, 431 were in the main image and 746 elsewhere, and there were no gaps. A second counter found only a handful of results dropped by a generation change during a parse, so the misses come from the page table never storing inaccessible pages.

Fix

Branch: https://github.com/Tamalero/AnyPS5/tree/fix/guest-memory-cache-inaccessible-pages (one commit on ab9a47684).

  • PageStates::record stores inaccessible runs as a third page value instead of skipping them. describePages answers them from the table like readable runs. Gaps found by either Linux path are recorded the same way. They are forgotten by the same registry invalidation as readable pages.
  • Guest stack protection changes outside the registry, in DoMprotect's stack branch and in RestoreStackPages at thread exit. Both now call GuestAllocationsInvalidate_nid_postfix for their pages, as GuestHeap already does.
  • On Windows, PAGE_GUARD regions are not stored, since the OS clears the guard on first touch. They were not stored before either, because they never counted as readable.
-            if (!readable || span->size == 0 || regionEnd <= span->base || base >= span->base + span->size) continue;
-            const std::uint8_t value = PageReadable | (writable ? PageWritable : 0u);
+            if (span->size == 0 || regionEnd <= span->base || base >= span->base + span->size) continue;
+            const std::uint8_t value = readable ? static_cast<std::uint8_t>(PageReadable | (writable ? PageWritable : 0u)) : PageInaccessible;
...
-            if ((value & 3u) != 0) {
+            if (value != 0) {
                 const auto next = span->runEnd(cursor, value, end);
-                if (!emit(PageRun{cursor, next, true, (value & PageWritable) != 0})) return true;
+                if (!emit(PageRun{cursor, next, (value & PageReadable) != 0, (value & PageWritable) != 0})) return true;

RunUnmappedGapTests (agc_driver_graphics) gains a case that reserves an arena page PROT_NONE, checks it, and opens it behind the registry. The page must still read as inaccessible from the table. Once GuestAllocations::Mutation::Add registers it, it must read as accessible.

Results

Machine Kernel Before With the fix
RTX 4090, i9-14900K 7.2, APS5_NO_PROCMAP_QUERY=1 0.02–0.05 FPS on the language screen (3 frames a minute) 5.4–6.6 FPS, same as without the switch
Radeon Pro V620 (RADV, Mesa 25.2.8), EPYC 7452, Ubuntu 24.04 VM 6.8 stalls at frame ~2,400 on the language screen 2.7–3.9 FPS, ran to frame 4,875 (about 15 minutes) without stalling; reaches the screen in ~11 min instead of ~20

Still open (not in this branch)

With the fix, one thread still parses /proc/self/maps on old kernels, at about 140 MB/s on the desktop. It doesn't hold up frames here. Those lookups are readable addresses in the main executable's writable data (rw-p, anonymous after backWritableImageAnonymously). PageStates::initialize only sets up the image span on Windows, so on Linux every lookup there goes to the host. A Linux image span would cover that; I've left it out, as a separate change with its own invalidation questions.

Details and tests
  • Linux (CachyOS, kernel 7.2), GCC, Release. agc_driver_graphics passes, both with and without APS5_NO_PROCMAP_QUERY=1. With GuestMemory.cpp from main and the new test, it fails with "a checked inaccessible arena page was queried again instead of read from the page table" (negative check).
  • Full ctest -j16: everything passes except agc_driver_flip_stores_small_results and agc_driver_store_idle_results, which failed once under heavy load (another title running alongside) and passed 3 of 3 when rerun alone.
  • tools/check_conventions.py --base origin/main passes.
  • Not tested: Windows (the PAGE_GUARD exclusion and the stack invalidation compile there but are unexercised), macOS.
  • Related: #1791 (PROCMAP_QUERY results were not stored), #3235 (module-info lookups scanning maps), #757/#758 (the table snapshots that probe here). The docs don't state a minimum kernel, and Ubuntu 24.04 LTS ships 6.8.
  • I have fewer than 10 merged PRs, so this is an issue with the branch rather than a PR.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5858146700 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6183). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-15T00:55:14Z. --- On Linux kernels without `PROCMAP_QUERY` (before 6.11, which includes Ubuntu 24.04 LTS's default 6.8), Guardians of the Galaxy reaches its language screen and then nearly stops: one frame every one to three minutes, with both GPUs idle. On a 6.11+ kernel the same build runs that screen at about 6 FPS. Forcing the fallback with `APS5_NO_PROCMAP_QUERY=1` reproduces it on any kernel. The cause is in `GuestMemory`'s page table. `describePages` stores only readable runs, so an answer of "inaccessible" is never remembered. Guardians' table snapshots (`TableSnapshotter::Column` → `ShaderMemory::accessible` → `GuestMemory::Accessible`) keep probing a reserved, `PROT_NONE` part of the guest arena, about 190 times a second. With `PROCMAP_QUERY` each probe is one cheap ioctl. Without it, each probe parses the whole of `/proc/self/maps` (about 7,500 lines here). **Title:** Marvel's Guardians of the Galaxy (PPSA01748 v01.006.000) **Where it stops:** the language screen, on main `411e5e6d9` plus #6033 and one NpManager stub the title needs to start. Every run: 3 of 3 on kernel 6.8, 4 of 4 on kernel 7.2 with `APS5_NO_PROCMAP_QUERY=1`. ### What the threads show - Under gdb at the stall, the guest's main thread and its job workers spin on one guest global. Both GPUs read 0% busy. That is the game waiting for its next frame, not the cause. - One host thread reads `/proc/self/maps` at about 140 MB/s (715 MB in 5 s, 4 KB reads; `/proc/<pid>/task/<tid>/io`). Its stack: `ResourceMaterializer::Materialize` → `TableSnapshotter::Snapshot` → `TableSnapshotter::Column` → `ShaderMemory::accessible` → `GuestMemory::Accessible` → `verify` → `describePages` → `std::getline`. - A local counter on the fallback path, over 80,000 parses: 78,823 were for **mapped** arena addresses. All were 4-byte probes into one reservation, `2a3490000-2d1160000 ---p`. Of the rest, 431 were in the main image and 746 elsewhere, and there were no gaps. A second counter found only a handful of results dropped by a generation change during a parse, so the misses come from the page table never storing inaccessible pages. ### Fix Branch: https://github.com/Tamalero/AnyPS5/tree/fix/guest-memory-cache-inaccessible-pages (one commit on `ab9a47684`). - `PageStates::record` stores inaccessible runs as a third page value instead of skipping them. `describePages` answers them from the table like readable runs. Gaps found by either Linux path are recorded the same way. They are forgotten by the same registry invalidation as readable pages. - Guest stack protection changes outside the registry, in `DoMprotect`'s stack branch and in `RestoreStackPages` at thread exit. Both now call `GuestAllocationsInvalidate_nid_postfix` for their pages, as `GuestHeap` already does. - On Windows, `PAGE_GUARD` regions are not stored, since the OS clears the guard on first touch. They were not stored before either, because they never counted as readable. ```diff - if (!readable || span->size == 0 || regionEnd <= span->base || base >= span->base + span->size) continue; - const std::uint8_t value = PageReadable | (writable ? PageWritable : 0u); + if (span->size == 0 || regionEnd <= span->base || base >= span->base + span->size) continue; + const std::uint8_t value = readable ? static_cast<std::uint8_t>(PageReadable | (writable ? PageWritable : 0u)) : PageInaccessible; ... - if ((value & 3u) != 0) { + if (value != 0) { const auto next = span->runEnd(cursor, value, end); - if (!emit(PageRun{cursor, next, true, (value & PageWritable) != 0})) return true; + if (!emit(PageRun{cursor, next, (value & PageReadable) != 0, (value & PageWritable) != 0})) return true; ``` `RunUnmappedGapTests` (`agc_driver_graphics`) gains a case that reserves an arena page `PROT_NONE`, checks it, and opens it behind the registry. The page must still read as inaccessible from the table. Once `GuestAllocations::Mutation::Add` registers it, it must read as accessible. ### Results | Machine | Kernel | Before | With the fix | |---|---|---|---| | RTX 4090, i9-14900K | 7.2, `APS5_NO_PROCMAP_QUERY=1` | 0.02–0.05 FPS on the language screen (3 frames a minute) | 5.4–6.6 FPS, same as without the switch | | Radeon Pro V620 (RADV, Mesa 25.2.8), EPYC 7452, Ubuntu 24.04 VM | 6.8 | stalls at frame ~2,400 on the language screen | 2.7–3.9 FPS, ran to frame 4,875 (about 15 minutes) without stalling; reaches the screen in ~11 min instead of ~20 | ### Still open (not in this branch) With the fix, one thread still parses `/proc/self/maps` on old kernels, at about 140 MB/s on the desktop. It doesn't hold up frames here. Those lookups are readable addresses in the main executable's writable data (`rw-p`, anonymous after `backWritableImageAnonymously`). `PageStates::initialize` only sets up the image span on Windows, so on Linux every lookup there goes to the host. A Linux image span would cover that; I've left it out, as a separate change with its own invalidation questions. <details><summary>Details and tests</summary> - Linux (CachyOS, kernel 7.2), GCC, Release. `agc_driver_graphics` passes, both with and without `APS5_NO_PROCMAP_QUERY=1`. With `GuestMemory.cpp` from `main` and the new test, it fails with "a checked inaccessible arena page was queried again instead of read from the page table" (negative check). - Full `ctest -j16`: everything passes except `agc_driver_flip_stores_small_results` and `agc_driver_store_idle_results`, which failed once under heavy load (another title running alongside) and passed 3 of 3 when rerun alone. - `tools/check_conventions.py --base origin/main` passes. - Not tested: Windows (the `PAGE_GUARD` exclusion and the stack invalidation compile there but are unexercised), macOS. - Related: #1791 (PROCMAP_QUERY results were not stored), #3235 (module-info lookups scanning maps), #757/#758 (the table snapshots that probe here). The docs don't state a minimum kernel, and Ubuntu 24.04 LTS ships 6.8. - I have fewer than 10 merged PRs, so this is an issue with the branch rather than a PR. </details> *Tested and written by Claude (AI assistant) on a contributor's machine.*
milescoviello commented 2026-10-15 01:07:42 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T01:07:42Z.


Same slow path, different miss. I opened #6179 an hour ago for the other half. The two don't overlap, and your branch merges cleanly with it.

  • Yours: inaccessible pages inside the arena are never stored, so every probe of them parses the file again.
  • #6179: readable ranges outside the arena and image spans, which the page table doesn't cover at all, also parse the file every time. ASTRO BOT (PPSA21564) checks the 96-byte Shader headers it passes from RegisteredHeader → SameHeader. Those headers live in the host heap. On kernel 6.8 that was 404,000 parses (25.7 s of CPU) in 200 s. For read-only checks of at most 4 KiB on such kernels, #6179 tries process_vm_readv on the own process first and falls back to the existing path on any failure.

Your change wouldn't cover the Astro case, since those addresses aren't in a span. #6179 wouldn't cover Guardians, since its probes are of PROT_NONE pages, where process_vm_readv fails and falls back. So both are needed.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6182020436 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6183#issuecomment-6182020436). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-15T01:07:42Z. --- Same slow path, different miss. I opened #6179 an hour ago for the other half. The two don't overlap, and your branch merges cleanly with it. - Yours: inaccessible pages inside the arena are never stored, so every probe of them parses the file again. - #6179: readable ranges **outside** the arena and image spans, which the page table doesn't cover at all, also parse the file every time. ASTRO BOT (PPSA21564) checks the 96-byte `Shader` headers it passes from `RegisteredHeader` → `SameHeader`. Those headers live in the host heap. On kernel 6.8 that was 404,000 parses (25.7 s of CPU) in 200 s. For read-only checks of at most 4 KiB on such kernels, #6179 tries `process_vm_readv` on the own process first and falls back to the existing path on any failure. Your change wouldn't cover the Astro case, since those addresses aren't in a span. #6179 wouldn't cover Guardians, since its probes are of `PROT_NONE` pages, where `process_vm_readv` fails and falls back. So both are needed. AI-assisted: yes
MarcZX10 commented 2026-10-15 01:10:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T01:10:39Z.


Carried the focused cache and invalidation fix as PR #6184, preserving Cesar Rodriguez as the commit author. I built the targeted graphics test and passed conventions locally; its runtime aborts at the host CPU guard before test code runs on this Xeon. The performance and title results in the issue remain the reporter’s results, not a local reproduction.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6182055747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6183#issuecomment-6182055747). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-15T01:10:39Z. --- Carried the focused cache and invalidation fix as PR #6184, preserving Cesar Rodriguez as the commit author. I built the targeted graphics test and passed conventions locally; its runtime aborts at the host CPU guard before test code runs on this Xeon. The performance and title results in the issue remain the reporter’s results, not a local reproduction.
oneandonlydean commented 2026-10-20 06:52:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T06:52:21Z.


The last open part of this, main-executable addresses going to the host on Linux, is covered by #7788 (713ee693e), which caches the image's page states. Closing. If the title still crawls on a kernel before 6.11 with current main, please reopen with a trace.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6285198775 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6183#issuecomment-6285198775). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T06:52:21Z. --- The last open part of this, main-executable addresses going to the host on Linux, is covered by #7788 (713ee693e), which caches the image's page states. Closing. If the title still crawls on a kernel before 6.11 with current main, please reopen with a trace.
Sign in to join this conversation.
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#6183
No description provided.