perf(agc): keep the readable mappings a Linux maps scan passes #14473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14473"
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 msbutt1 on 2026-11-01T14:52:44Z.
What
On Linux without
PROCMAP_QUERY(kernels before 6.11, such as the 6.8 kernel of Ubuntu 22.04 and 24.04),describePagesanswers a page-cache miss by reading/proc/self/mapsfrom the top until it reaches the queried address, and keeps only the run it was asked about. Every mapping the scan passed on the way is parsed and thrown away. A title that maps thousands of ranges pays a full scan for almost every miss.This keeps every readable mapping the scan passes in the page-state cache. It goes through
PageStates::recordwith the generation and access snapshot already taken before the file is opened, the same check that guards the queried run, so a registry mutation or access change during the scan forgets these entries as it forgets that one. Inaccessible mappings and gaps the scan passes are not recorded and stay unknown: a title's reserved ranges are inaccessible mappings of hundreds of GiB (Sifu reserves0x1000000000 + 0x7fc0000000), and recording them would rewrite one cache byte per 4 KiB page of them on every scan. A version that also recorded them made each scan about four times slower.Sifu (PPSA03001) during loading, measured with a local probe in the fallback that is not part of this PR: 14,336 fallback scans in the first ~55 s, about 2.5 ms and 5,200 lines each, 36 s in total; 92% of them queried an address inside the cached arena or image span, and each scan passed about 4,700 mappings inside a cached span before reaching its own.
/proc/self/mapsreached 21,214 lines.RunPassedMappingTests(Linux,agc_driver_graphicsandagc_driver_graphics_maps_fallback) maps writable, read-only and inaccessible pages and an unmapped gap below a queried page, then checks that the readable ones are answered from the cache after a scan, that the inaccessible one and the gap are not recorded, and thatGuestAllocationsInvalidateand a registryProtectforget what was recorded. It returns early whenPROCMAP_QUERYis available, since the ioctl path records only the queried run.Tested
Ubuntu 22.04.5, Linux 6.8.0-138-generic (no
PROCMAP_QUERY), i7-11800H, NVIDIA GeForce RTX 3080 Laptop GPU with driver 580.178.04, AC power. Built with GCC 13.4 and the 6.8 kernel UAPI headers.agc_driver_graphicsandagc_driver_graphics_maps_fallbackpass (13.5 s each). Without the change inGuestMemory.cpp,agc_driver_graphics_maps_fallbackfails witha writable mapping the maps scan passed was queried again instead of read from the page table.ctest -j 8on this commit overe67cc81869: 3,140 tests, 5 failures, none from this change.agc_driver_htile_mask_lifetime,guest_standard_streamsandguest_runtime_lifecyclefail the same way onmainon this machine.agc_driver_dcc_keys_first_writefails withresident snapshot size mismatchwith or without theGuestMemory.cppchange on this base, and passed on26fa1212b8.build_eligibilityfails because its harness uses??, which this machine's Node 12 does not parse.mainand on this change from the same machine and GPU:ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^(agc_driver_graphics|agc_driver_graphics_maps_fallback|agc_driver_guest_memory_lifetime.*)$' -V. Both runs pass 9 of 9, neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS, and both report the sameVUID-lines (108VUID-VkDeviceCreateInfo-pNext-pNext, 54VUID-VkPhysicalDeviceProperties2-pNext-pNext, from the 1.3.204 layer not knowing newer structures); the change adds none.APS5_TRACE_SECONDS=0:45, warm caches (one run before the captures), captured A, B, A, B in one session, each in a terminal without a redirected log or otherAPS5_TRACE_*/APS5_PROFILE_*switches. Converted with--to-intel; the dump has no PlayGo metadata, soAPS5_PLAYGO_UNLISTED_CHUNKS=absentasdocs/user/USAGE.mdlists for this title. Both sides include #9915, becausemainalone stops this scene at about 30 s withvertex fetch exceeds descriptor record count: A ismain26fa1212b8with #9915 (bc4a8fcd8f), B is A with this commit (30629f3870). The commit was then rebased ontoe67cc81869without conflicts; the change since then inGuestMemory.cppadds a macOS branch ahead of the fallback.The loading stall, the longest interval between presents, goes from 30.6 s and 30.8 s to 17.1 s and 17.4 s, and the 45 s window closes about 10 s earlier. In that frame
Driver.Packet.memory_waiton queue worker 0x20 drops from 21,440 and 21,099 ms to 13,620 and 13,191 ms (trace_digest.py, slowest frames). The median frame is unchanged. p90 and p99 move in both directions across the two pairs; B's window ends sooner, so it holds a smaller share of the fast loading-screen frames, andgpu_busy_ms_per_presentrises for the same reason.performance_compare.py --require-matching-contextreportsframe_ms.max−44.1% and −43.5% andmean_frame_ms−11.5% and −9.7%. Summary lines, traces and digests are attached.Summary lines (aps5-summary.jsonl)
Traces:
aps5-trace-bc4a8fcd8f9c-278752.json.gzandaps5-trace-bc4a8fcd8f9c-281453.json.gz(main + #9915),aps5-trace-30629f3870c4-280109.json.gzandaps5-trace-30629f3870c4-282897.json.gz(this change), attached in a comment.Digest (
python3 tools/trace_digest.py <trace>)main + #9915 (A), capture 1
seconds 0:45 from present 0: 1172 presents, frame p50 16.7 / p90 33.1 / p99 84.4 / max 30633.1 ms, GPU busy 3.7 ms per present
NVIDIA GeForce RTX 3080 Laptop GPU, NVIDIA 580.178.04, Linux 6.8.0-138-generic, 3840x2160, commit bc4a8fcd8f9c, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 58.6, Driver.WorkerWait 25.3, Driver.WorkerWait.idle_and_completion_poll 25.3, Graphics.Draw 21.2, Driver.Packet.memory_wait 18.6, Driver.Packet.draw 18.2, Driver.Draw 18.2, VideoOut.Flip 15.6, Driver.Draw.draw_enqueued 14.2, Graphics.Draw.draw_and_resource_release 12.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
this change (B), capture 2
seconds 0:45 from present 0: 1073 presents, frame p50 16.7 / p90 40.2 / p99 108.4 / max 17110.1 ms, GPU busy 5.9 ms per present
NVIDIA GeForce RTX 3080 Laptop GPU, NVIDIA 580.178.04, Linux 6.8.0-138-generic, 3840x2160, commit 30629f3870c4, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 47.2, Driver.WorkerWait 26.2, Driver.WorkerWait.idle_and_completion_poll 26.2, VideoOut.Flip 15.8, Driver.Packet.memory_wait 13.3, Graphics.Draw 10.9, Driver.Packet.draw 10.3, Driver.Draw 10.3, Driver.Packet.pipeline_drain 9.1, batch 8.9
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
main + #9915 (A), capture 3
seconds 0:45 from present 0: 1185 presents, frame p50 16.7 / p90 33.6 / p99 73.0 / max 30806.1 ms, GPU busy 3.7 ms per present
NVIDIA GeForce RTX 3080 Laptop GPU, NVIDIA 580.178.04, Linux 6.8.0-138-generic, 3840x2160, commit bc4a8fcd8f9c, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 57.1, Driver.WorkerWait 27.0, Driver.WorkerWait.idle_and_completion_poll 27.0, Graphics.Draw 20.9, Driver.Packet.memory_wait 17.9, Driver.Packet.draw 17.4, Driver.Draw 17.4, VideoOut.Flip 15.7, Driver.Draw.draw_enqueued 13.6, Graphics.Draw.draw_and_resource_release 11.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
this change (B), capture 4
seconds 0:45 from present 0: 1107 presents, frame p50 16.7 / p90 36.4 / p99 65.9 / max 17395.1 ms, GPU busy 6.1 ms per present
NVIDIA GeForce RTX 3080 Laptop GPU, NVIDIA 580.178.04, Linux 6.8.0-138-generic, 3840x2160, commit 30629f3870c4, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 46.8, Driver.WorkerWait 26.6, Driver.WorkerWait.idle_and_completion_poll 26.6, VideoOut.Flip 15.6, Driver.Packet.memory_wait 12.6, Driver.Packet.draw 11.2, Driver.Draw 11.1, Graphics.Draw 10.6, Driver.Packet.pipeline_drain 9.3, batch 9.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T05:46:04Z.
Review: COMMENTED
Reviewed — no blocking findings
On Linux, the
/proc/self/mapsscan now records readable mappings that lie before the scan cursor, where the old code skipped them, so later access checks can read them from the page-state cache. The record goes through the same clipping and generation and access checks as the existing records, and thegenerationandaccessvalues are in scope in the Linux branch. Nothing has been run: the Windows check was cancelled and Linux is skipped on pull requests.What I ran
16744dcb1726eef8be4117faab0c8a89414d2fcc; basee4501451406e4d3516c5b0eaa854d6ec1a28082d. 4 files, +55/-3:Execution/src/GuestMemory.cpp(+9/-3),tests/GuestAllocations.cpp(+47, newRunPassedMappingTests),tests/BdaTests.hpp(+1 declaration),tests/Graphics.cpp(+1 call).describePages(GuestMemory.cpplines 748-779), the#ifdef/#elsestructure around it (lines 642, 678, 713, 747, 784) to confirm thatgenerationandaccess(lines 679-680) are in scope in the Linux branch, andPageStates::record(lines 503-515) with its clipping and generation and access checks. Read the cache's comment (lines 374-382) for its invariant.RunPassedMappingTestsin full.windowsis cancelled, so there is no CTest result for this head. Linux is skipped on pull requests.Results
generationandaccessin scope)#elsebranch as the Linux code; not compiledRunPassedMappingTestsHostMapping::QueryFd() >= 0windowscheck-run is cancelled; no CTest summaryRead-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed. Hosted:
gh api repos/boykopovar/AnyPS5/commits/16744dcb1726eef8be4117faab0c8a89414d2fcc/check-runs.Negative control
Not run here. A negative control needs a Linux build and run, and code from this head is not run here.
Findings
Blocking
None.
Non-blocking
RunPassedMappingTestschecks that a protection changed withmprotectoutside the registry is not seen: aftermprotect(guest, 2 * page, PROT_NONE)the test still expectsAccessible(guest, page, true). This follows the cache's stated assumption (GuestMemory.cpplines 374-382: protections change through registry mutations and libc invalidation), but the test documents that assumption rather than checking the production behaviour. The new records extend the assumption to pages the scan used to re-query, so a sentence in the cache comment would make the extension explicit.Sources
github.com/boykopovar/AnyPS5@16744dcb17/core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp(lines 642-784)github.com/boykopovar/AnyPS5@16744dcb17/core/libs/prx/libSceAgcDriver/tests/GuestAllocations.cpp(RunPassedMappingTests, added at line 391)Not verified
To get this to a good state
RunPassedMappingTestsat this head. Optionally, add a sentence to the cache comment that the new records follow the same invariant.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:45:31Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts inGuestMemory.cpp. The new test selects the textual maps fallback only when the query FD is unavailable, so cite the fallback configuration explicitly when rerunning it. Preserve the controls for a readable mapping passed en route, a read-only mapping, an unmapped gap, and invalidation through the guest registry. Any speed claim should use the same maps-path configuration for paired traces.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.