fix(agc): cache Linux describePages results #1810
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1810"
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 Swastik-51 on 2026-10-08T19:59:52Z.
What
Fixes #1791.
On Linux,
describePagesqueriedPROCMAP_QUERY(or/proc/self/maps) but did not store the readable pages it found in the page table, so every uncached guest-range check repeated the query.PageStates::record(), shared by both platforms, to populate the cached page state.VirtualQuerypath already does.PROCMAP_QUERYresults in the page table, and does the same for the/proc/self/mapspath.Depends on #861: on current
mainthe Linux arena span is empty, so the cache stays inactive on Linux until #861 lands.Tested
python -m unittest discover tools/tests: 14/14 passed.python tools/check_conventions.py --base upstream/main: passed.git diff --check: passed.tools/check_test_registration.py(no Ninja/CMake build tree) and the Linux C++ build/tests (Windows environment).agc_driver_graphics).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:34:31Z.
I traced the current-main dependency before reviewing the cache path. On Linux,
GuestArena::Arenastill leaves_baseand_endat zero;GuestMemory::PageStates::initialize()therefore gets an empty arena span, and the image span is initialized only under_WIN32. The new Linuxpages.record()calls consequently have no span to populate on this base. The new arena test also returns early whenGuestArenaAvailable_nid_postfix()is false, so it does not exercise the cache on current Linux main.This change needs #861 first to make its intended Linux arena behavior active. CONTRIBUTING asks dependent PRs to say so explicitly; please add
Depends on #861to the body and make the test evidence clear that Linux cache behavior is gated until that dependency lands. I have not approved the PR: its check rollup is empty, and the body says the Linux C++ build/tests were unavailable locally.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:49:36Z.
Thanks for adding
Depends on #861and clarifying the gated Linux behavior. I checked the new upstream workflow attempts for head8dc179c; Build, Conventions and Progress are allaction_required, so no upstream checks have run yet. CONTRIBUTING says a maintainer must approve fork workflows. Since #861 is still open, this PR remains dependent on it even after the checks are approved.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:55:26Z.
I checked the branch base against current upstream
main0447793: head8dc179cdiverges by 2 commits ahead and 4 behind. CONTRIBUTING requires PRs to be based on currentmain; please rebase when refreshing and rerun upstream checks after a maintainer approves the fork workflows. Keep theDepends on #861note because that PR is still required for the Linux arena path.Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-09T13:44:22Z.
Linux results, since the PR could only be tested on Windows: this fixes a large slowdown on kernels before 6.11.
Setup. Ubuntu 24.04.5, kernel 6.8 (no
PROCMAP_QUERY), i3-12100, RX 7600 (RADV, Mesa 25.2.8), GCC 13.3 Release. Title: Disney Epic Mickey: Rebrushed (PPSA15657, UE4), on a stack of open PRs that gets it to the title screen (see #2255). Both runs below use the same build, 25 minutes, headless. The only difference is this PR plus #861.Before.
perf recordon the busiest thread: about 85% of its time was underGuestMemory::(anon)::describePages, 74% fromverify()and 11% fromCompareMapped(). Nearly all of it wasstd::istringstreamparsing/proc/self/maps. The process has about 5,400 mappings (518 KB of text), re-read for every uncached query. That thread sat at 100% while the CPU as a whole was about 80% idle.With the change,
describePagesno longer shows up. The busiest thread is about 64% busy, and its time is now in GPU submission ioctls underRecorder::Submit.On kernel 7.0, where
PROCMAP_QUERYis available, the build without this PR runs about the same as the build with it on 6.8 (logos ~60 fps, title screen ~10.6 fps). So the gain is on kernels before 6.11, which includes Ubuntu 24.04's default 6.8.Tests on Linux (main + #861 + #1810):
agc_driver_graphics_testsandguest_memorypass. One thing to check: the new arena test intests/GuestAllocations.cppreturns early, becauseGuestArenaAvailable_nid_postfix()is false in the test binary even with #861. The same run printsguest arena unavailable or not write-watched: heap mirrors not tested. So the Linux path passes without being exercised there. In the title's process, where the arena is set up, the cache clearly works (the numbers above).Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-09T14:43:11Z.
Independent confirmation on a second title, with a measured frame-rate outcome, and one thing this change
appears to still need.
The measurement. A retail title (
PPSA28997) on Linux, NVIDIA RTX 4070 Laptop, Hyprland/XWayland.perf recordon the two hot threads during gameplay: 50.8 % of all samples were insidelibstdc++std::istream, top self symbolstd::istreambuf_iteratorat 19.7 %, callersdescribePages->verify/DescribeCommittedUncached/CompareMapped. The game's own module was 3.0 %. Counted directly:1,172,045 map queries and 64,207,427 parsed lines in one run, because the page table was never populated.
After the store-back fix, on the same tree, same seed, same input, three runs per arm:
query 0 calls)Zero fatal lines over a 13 minute soak with continuous input, and screenshots showed correct scenes
throughout.
One thing this change seems not to cover on its own. The store-back only helps if a span exists to store
into, and on Linux
PageStates::initializegetsbase = 0 size = 0fromGuestArenaRange, because theArenaconstructor incore/libs/prx/libc/src/GuestArena.cppis entirely inside#ifdef _WIN32.PageSpan::allocate()returns false onsize == 0,spanOf()answers null, and the store has nowhere togo. #1791 says the same thing ("the Linux arena span is empty ... so the table is not used on Linux at
all"), so this may just be a note that #1810 depends on #861 to be effective on Linux rather than a gap in
the diff. It is worth stating in the PR description either way, because with #1810 alone on current
mainthe measurable effect on Linux is nil.
A second, smaller gap. Two
munmapcalls incore/libs/prx/libkernel/DirectMemory/DirectMemory.cpptrim the alignment prefix and suffix inside the aligned-mapping helper, and that helper runs outside any
GuestAllocations::Mutation.GuestAllocationsEndis what fires the registered invalidator, so those tworanges are unmapped without
ForgetPagesever seeing them. Once readable bits can be cached, a bit set fora prefix or suffix range before it is trimmed would survive the trim. Invalidating both ranges explicitly
closes it; that is two calls, and I can send them as a commit on this branch if useful.
One consequence worth knowing: enabling the span also activates the invalidator, because
PageStates::initializeonly registersForgetPageswhen a span actually allocated. Before this, noinvalidation was installed on Linux at all.
Written with AI assistance; the numbers above were measured on the hardware listed.
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:23:00Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
966d503a, merged ontomaind70b8998in one build with 33 other AGC/shader PRs that had no Windows run.agc_driver_graphics. None of them reported skipping a case.agc_driver_graphics(which includesGuestAllocations.cpp) passes.PATHsetup.No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:16:47Z.
Conventions fails because the description isn't in the PR template: it needs the What, Tested and Checklist sections (including AI-assisted yes/no). The change itself waits on #861, since the Linux arena span is empty without it.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:12:10Z.
Review: CHANGES_REQUESTED
Thanks for this, the Linux measurements in the thread (@johnmaia, @jeffrey12cali) show it is worth landing. Ran build + the AgcDriver ctest scope here: green. What's left:
### What,### Testedand### Checklistsections (template in.github/pull_request_template.md). Please move the text under those headings.core/libs/prx/libSceAgcDriver/tests/GuestAllocations.cpp:190): it returns whenGuestArenaAvailable_nid_postfix()is false, soagc_driver_graphicsalso passes withGuestMemory.cppreverted. Either make it exercise the cache without the arena (e.g. a span that doesn't depend on #861), or land it after #861 and show it failing without the change.core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp:523-531): the prefix/suffixmunmapcalls run outside anyGuestAllocations::Mutation, soForgetPagesnever sees them. Once readable bits are cached they can outlive the unmap. Invalidate both ranges (as @jeffrey12cali offered) or explain why it can't matter.Depends on #861: on currentmainthe Linux span is empty and this change is inactive. It can merge once #861 does.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T10:04:55Z.
@Swastik-51 Rebased onto current main and pushed to the branch; your commits are unchanged. One commit on top:
gpuargument thatMutation::Add/Protecttake sincec11a9cb59f(it didn't compile on main).mprotectbehind the registry and requires the stored answer. With theGuestMemory.cppchange reverted it fails ("a checked arena page was queried again instead of read from the page table"). With #861 the arena block runs on Linux; on main alone it still returns early.Alignment trim (
DirectMemory.cppprefix/suffixmunmap): with #861 that path is unreachable on Linux.MapPlacedreturns through the arena first, and the arena either initialises or throws, so no cached page can outlive a trim.Linux, GCC, Release: ctest 694/695 on main + #861 + this branch, and on main + this branch.
agc_driver_graphicspasses in both. The one failure,agc_driver_dcc_keys_first_write, fails the same way on main.I also moved the description into the PR template so
conventionscan pass. Please fill in the AI-assisted answer at the end; only you can answer that.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:22:22Z.
Review: CHANGES_REQUESTED
The code is fine: build and the AgcDriver ctest scope are green, and
agc_driver_graphicsfails with theGuestMemory.cppchange reverted, so the cache test pins the fix.One thing left: Conventions fails with
Fill in the pull request template: answer AI-assisted with yes or no. @Swastik-51 please replace<!-- yes / no -->in theAI-assisted:line of the description with yes or no. Once that check is green this can be merged.Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-11T00:54:37Z.
@Swastik-51 I tried this in Hades II (PPSA36082) on my machine.
Setup: Linux, RTX 4090, Ryzen 7 7800X3D, main
aa79dbdfplus a few local changes the game needs to get in game, with this PR's head (6f82d9f6) merged on top. Warm caches, standing still in the hub for 20 s, one run each, same session:That's about 27% faster. It merged cleanly onto current main.
LLM assistance used.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T11:03:46Z.
One status update from the current branch: #861 merged into main on October 10, so the stated dependency has landed. The latest conventions run still fails because the
AI-assisted:line remains the template placeholder. The new overlap notice for #3454 is for the same GuestMemory.cpp file; #3454 extracts the procmap query helper while this PR adds the page-state cache, so they are distinct changes but the later merge may need a rebase.Imported from boykopovar/AnyPS5. Originally posted by eliyarson on 2026-10-12T05:42:49Z.
Another Hades II (PPSA36082) measurement, on different hardware from @Raghav314's.
Setup: Linux (CachyOS, KDE Wayland), Ryzen 9 5950X, RTX 3080 Ti (NVIDIA 610.57.04), Release build. Base:
main0a8b1d32bplus #3850, #419, #2169 and #2121's own commit, which the title needs to reach gameplay. This PR's three commits were cherry-picked on top, resolving theProcMapsQueryFd()→HostMapping::QueryFd()rename from #3454 by keeping main's name. A/B in one session with the same runtime and onlylibSceAgcDriver.prxswapped, standing still in the Crossroads hub, nothing else compiling,APS5_PROFILE_DRAW=1:Before the change
ioctl(PROCMAP_QUERY fromdescribePages) was the top frame in 116 of 400 gdb samples of the AGC worker thread.agc_driver_graphicsfails with theGuestMemory.cppchange reverted and passes with it. The worker thread stays at ~100% of one core afterwards, so the title remains CPU-bound on draw submission, but this is the largest single cost we found.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T09:12:30Z.
Closing: carried in #4395 with your commits and authorship kept, rebased over #3454, because the AI-assisted line here was never answered and only you can fill it in.
Pull request closed