perf(agc): take the /proc/self/maps fallback off the draw path on kernels without PROCMAP_QUERY #25446

Merged
oneandonlydean merged 2 commits from upstream-pr/25446 into main 2026-11-22 21:30:43 +00:00
oneandonlydean commented 2026-11-22 03:47:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-22T03:47:03Z.


What

On Linux kernels without the PROCMAP_QUERY ioctl (before 6.11, for example Ubuntu 24.04 on 6.8) describePages answers from the text of /proc/self/maps. Two callers reach that scan on the draw path, and on PPSA21564 it costs two thirds of the frame rate (#25359 is the same scan seen by the allocation census).

Sampling the scans on PPSA21564 with APS5_NO_PROCMAP_QUERY=1 (about 138000 in a 170 s run, all for addresses outside the guest arena and the main image, so the page table next to them cannot remember the answer):

  • 55 percent come from CompareMapped, called by capturedMemoryChanged on every draw for captured shader memory that lives in host mappings. Each one reads the whole file, about 2400 lines.
  • 45 percent are 4 byte probes of near-null addresses from the shader evaluator (ShaderMemory::accessible), answered by the first line.

This PR changes two things, both only where the ioctl is unavailable:

  • CompareMapped compares a range that lies outside the guest arena and the main image through GuestCopyInUnsynced, the fault-checked copy CopyMapped already uses, in 16 KiB pieces. A piece that cannot be copied falls back to the scan, so the answer is the same as before in every case. APS5_NO_COPY_COMPARE restores the scan per comparison.
  • The scan itself no longer builds an ifstream and one istringstream per line. It reads the file into a per-thread buffer, parses the two addresses and the permissions by hand and stops at the first mapping above the cursor. The first read asks for 256 bytes, so a near-null probe does not make the kernel format a page of mappings. The [guestmem] profile line now counts these scans as query, as it does for VirtualQuery on Windows.

Nothing is cached, so there is no snapshot that could go stale. With the ioctl available the only added work is one test of the cached query descriptor per comparison.

#25115 (closed) kept the parsed file per mapping generation and recovered most of the time, which is what pointed at the scan. I did not take that route because the costly queries are for host memory, where no generation or access event tells a snapshot that a mapping changed. #14473 records readable mappings into the page table and does not reduce these scans (it read slower than main on this title).

Tested

Linux, kernel 7.2, NVIDIA GeForce RTX 4090, built on 8bd65f7dd2. The fallback is forced with APS5_NO_PROCMAP_QUERY=1.

PPSA21564, level big_hand_pirate_island, one exclusive window, 240 s arms, unprofiled, order main, PR, main, PR on the fallback, then the PR once on the default path. Frame p50, median over the 10 s rows of the steady level:

arm first 30 s steady level
main, fallback 16.7 ms 671.6 ms / 678.6 ms
this PR, fallback 16.7 ms 210.7 ms / 211.0 ms
this PR, default path 16.7 ms 207.5 ms

Presents per 10 s go from about 15 to about 47. GPU time per present is the same on all arms (about 83 ms) and the level draws correctly on each. A profiled arm of this PR on the fallback counts about 600 scans per 10 s in the level, 0.3 s in all.

Tests, with APS5_NO_PROCMAP_QUERY=1: agc_driver_draw_allocations, agc_driver_draw_allocations_draw_pipeline and agc_driver_draw_allocations_plan_verify fail on 8bd65f7dd2 (516, 521 and 522 allocations per warmed dispatch against limits of 10 and 13) and pass on this branch. agc_driver_graphics, agc_driver_graphics_maps_fallback and guest_sysmodule_maps_scan pass, and the three census tests pass without the switch. The second commit adds checks of CompareMapped on host pages to the gap test (equal, different, across an unmapped page, a difference before the gap, and a range longer than one piece); they run in both graphics tests, so the copy path and the query path are held to the same answers. The title numbers were taken on the first commit; the second changes tests only.

Not tested: a kernel that really lacks the ioctl (the switch disables it at its source, HostMapping::QueryFd), other titles, Windows (the changed code is not built there).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: Fixes #25359
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4090, driver 610.57.04, Linux
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5435464750 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25446). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-22T03:47:03Z. --- ### What On Linux kernels without the `PROCMAP_QUERY` ioctl (before 6.11, for example Ubuntu 24.04 on 6.8) `describePages` answers from the text of `/proc/self/maps`. Two callers reach that scan on the draw path, and on PPSA21564 it costs two thirds of the frame rate (#25359 is the same scan seen by the allocation census). Sampling the scans on PPSA21564 with `APS5_NO_PROCMAP_QUERY=1` (about 138000 in a 170 s run, all for addresses outside the guest arena and the main image, so the page table next to them cannot remember the answer): - 55 percent come from `CompareMapped`, called by `capturedMemoryChanged` on every draw for captured shader memory that lives in host mappings. Each one reads the whole file, about 2400 lines. - 45 percent are 4 byte probes of near-null addresses from the shader evaluator (`ShaderMemory::accessible`), answered by the first line. This PR changes two things, both only where the ioctl is unavailable: - `CompareMapped` compares a range that lies outside the guest arena and the main image through `GuestCopyInUnsynced`, the fault-checked copy `CopyMapped` already uses, in 16 KiB pieces. A piece that cannot be copied falls back to the scan, so the answer is the same as before in every case. `APS5_NO_COPY_COMPARE` restores the scan per comparison. - The scan itself no longer builds an `ifstream` and one `istringstream` per line. It reads the file into a per-thread buffer, parses the two addresses and the permissions by hand and stops at the first mapping above the cursor. The first read asks for 256 bytes, so a near-null probe does not make the kernel format a page of mappings. The `[guestmem]` profile line now counts these scans as `query`, as it does for `VirtualQuery` on Windows. Nothing is cached, so there is no snapshot that could go stale. With the ioctl available the only added work is one test of the cached query descriptor per comparison. #25115 (closed) kept the parsed file per mapping generation and recovered most of the time, which is what pointed at the scan. I did not take that route because the costly queries are for host memory, where no generation or access event tells a snapshot that a mapping changed. #14473 records readable mappings into the page table and does not reduce these scans (it read slower than `main` on this title). ### Tested Linux, kernel 7.2, NVIDIA GeForce RTX 4090, built on `8bd65f7dd2`. The fallback is forced with `APS5_NO_PROCMAP_QUERY=1`. PPSA21564, level `big_hand_pirate_island`, one exclusive window, 240 s arms, unprofiled, order main, PR, main, PR on the fallback, then the PR once on the default path. Frame p50, median over the 10 s rows of the steady level: | arm | first 30 s | steady level | |---|---|---| | `main`, fallback | 16.7 ms | 671.6 ms / 678.6 ms | | this PR, fallback | 16.7 ms | 210.7 ms / 211.0 ms | | this PR, default path | 16.7 ms | 207.5 ms | Presents per 10 s go from about 15 to about 47. GPU time per present is the same on all arms (about 83 ms) and the level draws correctly on each. A profiled arm of this PR on the fallback counts about 600 scans per 10 s in the level, 0.3 s in all. Tests, with `APS5_NO_PROCMAP_QUERY=1`: `agc_driver_draw_allocations`, `agc_driver_draw_allocations_draw_pipeline` and `agc_driver_draw_allocations_plan_verify` fail on `8bd65f7dd2` (516, 521 and 522 allocations per warmed dispatch against limits of 10 and 13) and pass on this branch. `agc_driver_graphics`, `agc_driver_graphics_maps_fallback` and `guest_sysmodule_maps_scan` pass, and the three census tests pass without the switch. The second commit adds checks of `CompareMapped` on host pages to the gap test (equal, different, across an unmapped page, a difference before the gap, and a range longer than one piece); they run in both graphics tests, so the copy path and the query path are held to the same answers. The title numbers were taken on the first commit; the second changes tests only. Not tested: a kernel that really lacks the ioctl (the switch disables it at its source, `HostMapping::QueryFd`), other titles, Windows (the changed code is not built there). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: Fixes #25359 - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4090, driver 610.57.04, Linux - [x] AI-assisted: yes
MarcZX10 commented 2026-11-22 06:15:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T06:15:04Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed implementation preserves the checked-copy fallback and the maps-scan path for unsupported cases.

What I ran

Reviewed head d4f745c427b4454990278354f19bbb64f22eaa63. I read the prepared description, commits, manifest, diff, and all changed lines in the three changed files, then inspected the called copy helper. No build or tests were run.

Results

Check Result Note
Changed code review passed Logic and edge cases inspected
Tests and build not run No commands executed

Findings

Blocking

None.

Non-blocking

None.

Not verified

No runtime validation was performed, including on a kernel without PROCMAP_QUERY; the author reports that environment as untested. No build or tests were run. The three changed files listed in the manifest were read; there were no excluded changed files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6010697550 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25446#pullrequestreview-6010697550). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T06:15:04Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed implementation preserves the checked-copy fallback and the maps-scan path for unsupported cases. ## What I ran Reviewed head `d4f745c427b4454990278354f19bbb64f22eaa63`. I read the prepared description, commits, manifest, diff, and all changed lines in the three changed files, then inspected the called copy helper. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Logic and edge cases inspected | | Tests and build | not run | No commands executed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No runtime validation was performed, including on a kernel without `PROCMAP_QUERY`; the author reports that environment as untested. No build or tests were run. The three changed files listed in the manifest were read; there were no excluded changed files. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
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!25446
No description provided.