fix(agc): cache Linux /proc/self/maps regions for describePages #1114
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1114"
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?
Imported from boykopovar/AnyPS5. Originally posted by prompterror on 2026-10-07T12:57:22Z.
What
On Linux the AGC driver's guest memory is ordinary host memory (
malloc/mmap), so a page's protection comes from/proc/self/mapsrather than a Windows-style reserved arena.describePagesre-read and re-parsed that file for every range the driver verified — no caching, unlike the Windows path (VirtualQueryarena table).Measured in Dreaming Sarah (2D title, otherwise reaches 60 FPS):
read()/s + ~1,600openat+close/s on one hot thread re-reading all of/proc/self/mapsverifywindow took ~7 s of thatFix
Adds
LinuxPageCache:std::mapof parsed regions keyed by begin address, guarded by ashared_mutexForgetPages) is registered unconditionally on Linux and drops only the affected ranges (splitting/re-inserting partial regions), matching the existing arena/image escape hatchesResult:
verifywindow ~7 s → ~0.1 s, title back to 59.96 FPS on the same profile run. Windows path untouched (#ifdef _WIN32/#elsesplit).Testing
GuestMemory.cppcompiles clean (-std=c++20,-Wallset from CI's flags) against currentmainImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T02:05:02Z.
Review: COMMENTED
This breaks an existing test on Linux — the platform the change is for — so it is blocking in my reading. I bisected it to
GuestMemory.cpprather than guessing.Failing test:
agc_driver_graphics,1 of 395on this branch:Bisection. Same tree, only
GuestMemory.cppswapped to the commit's parent:So it is this file, and it reproduces on every run — not a flake.
The assertion is
tests/LiveStack.cpp:69, after a stack is built and one thread has run on it:The block is
mmaped read-write and then both guard pages aremprotected toPROT_NONE(lines 45–47). The middle must report accessible and the two guards must report inaccessible. One of those two negatives now reports positive through the new cache.Why I think the cache is the cause.
LinuxPageCache::findreturns a region that covers the address, and the refresh happens only on a miss:A stale entry that still covers the queried address is a hit, so nothing is re-read — and that is the one case where the answer is wrong. This test is close to a worst case for it: the block is freshly
mmaped and can reuse an address the cache still describes from an earlier, differently-protected mapping. A negative answer (guard page not accessible) is exactly what a stale positive turns into a wrong one. I did not instrument which of the three conditions fails, so treat the mechanism as the explanation consistent with the evidence rather than as measured; the bisection and the reproduction are measured.Direction, if it helps. Refreshing on miss cannot see a change at an address the cache believes it covers, so the hit path has to be able to revalidate — which is awkward here because this test (and anything else using raw
mmap/mprotect) never callsForgetPages, so the invalidator cannot be relied on. Two shapes that would both be sound: revalidate a hit against/proc/self/maps(the cache then caches the parse, not the answer), or keep the answer cache but give it a bounded lifetime/generation so a stale region cannot be trusted indefinitely. Making the test callForgetPageswould hide the problem rather than fix it, since the failure case is precisely a mapping the registry never saw.Environment, so you can reproduce exactly: Linux (CachyOS), GCC, Release, NVIDIA RTX 3080 Ti. I ran the suite with
APS5_WRITE_WATCH_IMPORTS=watchbecause this branch predates the dma-buf gating in #1329; without it the NVIDIA probe failures mask other results. The other 394 tests pass, so the rest of the change is clean here.Happy to bisect further or instrument which condition fails if that is useful — say the word.
This is a comment, not an approval — I have no merge rights here.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T02:44:09Z.
Closing as a duplicate of #157, which removes the same
/proc/self/mapsre-read withPROCMAP_QUERYand keeps no cache that can go stale; the stale hit is also what failsagc_driver_graphicsin the review above. If #157 misses a case you hit, please comment on #157 with what it misses.Pull request closed