AGC: on Linux, describePages never stores PROCMAP_QUERY results in the page table, so every uncached guest-range check is an ioctl #1791
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 fisherjoey on 2026-10-08T19:16:24Z.
Summary
describePages(Execution/src/GuestMemory.cpp:536onmain6b56175a) looks pages up in the arena/image page table first. On Windows, aVirtualQuerymiss stores the readable pages it found (:578-584), under the generation check, and the registry's invalidator (ForgetPages) clears them on unmap and protect. The Linux branch (:589-611) issuesPROCMAP_QUERYand stores nothing, so the table never fills and every check that reaches it is a syscall.On
maintoday the Linux arena span is empty (GuestArenaRangereturns size 0 without #861), so the table is not used on Linux at all. With #861 the span covers the PS5 window, and every check in it that misses the table becomes an ioctl.Evidence
Demon's Souls (PPSA01341 v1.07), tutorial level, queue 0, bpftrace on the syscall tracepoints over 20 s: 2.1M
PROCMAP_QUERYcalls, 1.67 s. Syscalls were 27.7% of queue 0's on-CPU samples, most of them these queries. Measured on our local build (an oldermainplus #157, #861 and our own patches). The query path there is the same code asmain's.#1330 adds a per-thread cache of up to 64 permission runs inside registered allocations. On a later build I ran it in place of the change below, and it still left 495k-502k queries per 10 s (0.8 s per 10 s). This title verifies more distinct ranges per frame than 64 runs hold.
Fix
After a successful
PROCMAP_QUERY, store the readable pages the request covers in the arena/image table, the same way the Windows branch does: same values, same generation check, and the sameForgetPagesinvalidation. It stores only the pages of the request, not the whole VMA (an arena VMA can span GiBs).Measured on the same build, 20 s windows:
PROCMAP_QUERYon queue 0Queue 0 then got through ~75k draw packets per 10 s instead of ~53k (that run also enlarged the staging pool). On a later build, single runs in the level: this change 2.20 fps, #1330 instead of it 1.80, both 2.00 (9.9k queries per 10 s).
The stale-hit question raised on #1114 applies here as it does to the Windows table: a page the store covers that changes protection outside the registry stays cached until the next invalidation. The table only covers the guest arena, and guest mappings there change through the registry. If that's not enough, the store could also skip host regions inside the window.
The fix is ready on a branch: https://github.com/boykopovar/AnyPS5/compare/main...fisherjoey:AnyPS5:perf/linux-page-cache
It depends on #861: on
mainalone the arena span is empty and the change stores nothing.The branch adds a Linux case to
RunUnmappedGapTests. It maps two arena pages, registers them, protects one read-only through the registry and checks that the cached access follows, then unmaps both and checks again. It is skipped while the arena is unavailable.Tests: the 195
agc_drivertests pass on the branch (rebased on6b56175a). With #861 merged locally,agc_driver_graphicspasses, and it fails on the new check ifForgetPagesstops clearing the table.Found on Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), with Demon's Souls PPSA01341 v1.07.
I'll open the PR if the approach looks right.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-09T14:46:46Z.
Second title, same diagnosis, and a frame-rate number for it.
A retail title (
PPSA28997) on Linux, RTX 4070 Laptop, Hyprland/XWayland.perf recordon the hot threadsduring gameplay put 50.8 % of all samples inside
libstdc++std::istream, called fromdescribePagesthrough
verify/DescribeCommittedUncached/CompareMapped. Counting the queries directly:1,172,045 map queries and 64,207,427 parsed lines in one run, with the page table never populated. The
game's own module accounted for 3.0 %.
Populating the table moved the CPU-bound frame rate from 7.40 to 60.32 FPS (56.5 median over three runs),
the query count to zero, and 42,772 verifications to 0.1 s total. No fatal lines over a 13 minute
soak.
Two details from this diagnosis that may matter to #1810:
PageStates::initializegetsbase = 0 size = 0fromGuestArenaRange, because theArenaconstructor inlibc/src/GuestArena.cppisentirely inside
#ifdef _WIN32, soPageSpan::allocate()fails onsize == 0. Your issue already saysthis depends on #861; on this tree, which predates it, we had to fall back to the window libkernel really
does reserve (
0x200000000, size0x400000000) to get any effect at all.initializeonly registersForgetPageswhen a span allocated, sobefore this there was no invalidation installed on Linux at all. After it, the counters report
forgets 715 (2377 MiB)during a run.Written with AI assistance; the numbers were measured on the hardware listed.
Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-10T11:01:08Z.
Corroborated on a second title, with one addition: the store-back alone does not remove the decay
Our fork is pinned to
c8830699(2026-10-04), which predates #157, so we implemented both halvesindependently: the
PROCMAP_QUERYswitch and the store-back into the arena/image table. The title is a 2DIL2CPP title,
PPSA28997, on an RTX 4070 Laptop with driver 615.71.09.A cheap diagnostic for this cause. Sample the process mapping count and the frame counter together. If the
product stays constant, the cost is a per-mapping scan and this is the issue:
The constant is about 1.1e5 here, which is roughly 9.5 microseconds per mapping per frame. A
perfcall graphplaced 43.4 % of samples in
libstdc++stream extraction underdescribePages.The addition, and the reason I would not close this issue with the store-back alone. On our build the
store-back fixed the boot-time cost but not the decay:
7.40 FPS to 60.32 FPS at the main menu. Over the following minutes the frame rate still fell from 44.7 FPS
to 9.5 FPS as mappings grew.
PROCMAP_QUERY: no decay. Two 15-minute runs held a mean of 57 to 59 FPS, and four runstotalling 50 minutes of scripted gameplay produced no monotonic decline.
The reason is that the table only answers probes inside the arena and image spans. Our counters recorded
26,398 probes at addresses outside those spans, plus every probe of an unmapped hole. Each of those still
reaches the query path, so with a text parse each one cost a full scan, and the cost still grew with the
mapping count. Storing the request's pages fixes the mapped-and-in-span case, which is the majority by count
but not the one that paces the frame.
So the two changes are complementary rather than alternative: #157 makes the residual probes cheap, and the
store-back removes the probes that dominate by count. If #1791 is intended to be sufficient on its own, it is
worth deciding explicitly whether out-of-span and unmapped probes should also be cached, or left to the ioctl.
One semantic note on the gap case, relevant to #442. An earlier revision of our change treated an
unmapped address as a hole to walk past, continuing into the next mapping rather than ending the walk with the
remainder reported unreadable. That is a guest-visible change, and it coincided with the only permanent stall
we saw: the frame counter stopped at frame 8953 during a boss fight, all 93 threads were parked on a futex,
and the last rendered frame was a correct gameplay image. Restoring the end-the-walk behaviour removed it, in
four subsequent runs without a recurrence. Single instance, so it is a lead rather than a proven cause, but I
would not want a caching change to reintroduce it.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-10T11:42:15Z.
@jeffrey12cali thanks, the mappings × FPS product is a neat check. On current
mainboth halves are covered by separate changes: #157 (merged 2026-10-08) switched LinuxdescribePagestoPROCMAP_QUERYthrough a cached fd, so the out-of-span and unmapped probes go to the ioctl instead of a text parse. #1810 (open, with #861, now merged) adds the store-back for in-span pages. So the case you saw decay on, store-back withoutPROCMAP_QUERY, shouldn't occur onmainwith #1810. Whether out-of-span and unmapped probes should also be cached is a question for #1810. Your note on ending the walk at an unmapped address is worth keeping there too.AI-assisted: yes