perf(agc): cache the parsed /proc/self/maps across describePages calls #25115

Closed
tablefrogpillow wants to merge 1 commit from upstream-pr/25115 into main
tablefrogpillow commented 2026-11-21 16:56:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tablefrogpillow on 2026-11-21T16:56:38Z.


What

On Linux without PROCMAP_QUERY (kernels before 6.11, e.g. the 6.8 kernel of Ubuntu 22.04/24.04 and the CI target), describePages answered every page-cache miss by reading /proc/self/maps from the top, and the outer loop reopened the file for each run. A title that imports many buffer-device addresses over a large, fragmented address space reparses the whole map thousands of times per burst.

Jedi Survivor (PPSA07783) reopened a 13k–16k line map ~2000 times in a 30 s window, spent 36–43 s in a single address-bindings pass, and lost the device to the amdgpu hang timeout (#25019).

This parses the map once into a sorted snapshot keyed on the guest-allocation generation and binary-searches it, rebuilding only when the generation changes. A miss or gap forces one fresh reparse before it is trusted, so a readable mapping that appeared without a generation bump (a raw mmap, as GuestWriteWatch registrations make) is still found — this keeps agc_write_tracking and the other guest-memory tests correct.

It does not build on #14473 (which caches the page-states a scan passes); for this title that cache is invalidated by the access-serial churn before it is reused, so the scan reran regardless (measured: no change on Jedi). Coordinated with @oneandonlydean on #25019.

Tested

RX Vega 56 (gfx900, Mesa RADV), Linux 6.8. Same machine and scene (Jedi PPSA07783 boot), APS5_PROFILE_DRAW=1, headless weston:

worst address bindings (bda) median /proc/self/maps reopens (30 s) result
main 36.4–43.7 s — ~2000–2300 VK_ERROR_DEVICE_LOST
this PR 8.2 s 0.58 s 1086 no device-loss; reaches 321 draws

Correctness: ctest -R 'agc_driver_bda|agc_bda|guest_memory|shared_writes|write_tracking|mapped_copy|collect_memo' — 36/36 pass on Vega with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (1.4.x), no new VUID-. agc_write_tracking specifically exercises the raw-mmap-without-generation-bump path and passes.

The remaining 8.2 s is the cold first import (empty cache) and the 1086 reopens are the verify-negatives reparses; a follow-up can bound those further, but the device-loss is already gone.

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
  • 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: #25019
  • Unblocks: PPSA07783 #25019
  • GPUs tested: AGC — AMD Radeon RX Vega 56 (gfx900), Mesa RADV, Linux 6.8
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5430249160 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25115). Originally posted by [tablefrogpillow](https://github.com/tablefrogpillow) on 2026-11-21T16:56:38Z. --- ### What On Linux without `PROCMAP_QUERY` (kernels before 6.11, e.g. the 6.8 kernel of Ubuntu 22.04/24.04 and the CI target), `describePages` answered every page-cache miss by reading `/proc/self/maps` from the top, and the outer loop reopened the file for each run. A title that imports many buffer-device addresses over a large, fragmented address space reparses the whole map thousands of times per burst. Jedi Survivor (PPSA07783) reopened a 13k–16k line map ~2000 times in a 30 s window, spent **36–43 s in a single address-bindings pass**, and lost the device to the amdgpu hang timeout (#25019). This parses the map once into a sorted snapshot keyed on the guest-allocation generation and binary-searches it, rebuilding only when the generation changes. A miss or gap forces **one** fresh reparse before it is trusted, so a readable mapping that appeared without a generation bump (a raw `mmap`, as `GuestWriteWatch` registrations make) is still found — this keeps `agc_write_tracking` and the other guest-memory tests correct. It does **not** build on #14473 (which caches the page-states a scan passes); for this title that cache is invalidated by the access-serial churn before it is reused, so the scan reran regardless (measured: no change on Jedi). Coordinated with @oneandonlydean on #25019. ### Tested RX Vega 56 (gfx900, Mesa RADV), Linux 6.8. Same machine and scene (Jedi PPSA07783 boot), `APS5_PROFILE_DRAW=1`, headless weston: | | worst `address bindings (bda)` | median | `/proc/self/maps` reopens (30 s) | result | |---|---|---|---|---| | `main` | 36.4–43.7 s | — | ~2000–2300 | `VK_ERROR_DEVICE_LOST` | | this PR | **8.2 s** | **0.58 s** | 1086 | no device-loss; reaches 321 draws | Correctness: `ctest -R 'agc_driver_bda|agc_bda|guest_memory|shared_writes|write_tracking|mapped_copy|collect_memo'` — **36/36 pass** on Vega with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (1.4.x), no new `VUID-`. `agc_write_tracking` specifically exercises the raw-`mmap`-without-generation-bump path and passes. The remaining 8.2 s is the cold first import (empty cache) and the 1086 reopens are the verify-negatives reparses; a follow-up can bound those further, but the device-loss is already gone. ### 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 and the licence notice of code adapted from upstream - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [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: #25019 - [x] Unblocks: PPSA07783 #25019 - [x] GPUs tested: AGC — AMD Radeon RX Vega 56 (gfx900), Mesa RADV, Linux 6.8 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull request closed

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!25115
No description provided.