perf(agc): reuse a cached address space's committed pages on a hit #6955

Merged
alfalfa-star merged 4 commits from upstream-pr/6955 into main 2026-10-19 15:33:02 +00:00
alfalfa-star commented 2026-10-16 21:04:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-16T21:04:28Z.


What

The read-only V# address-space cache (#5428) lets a draw reuse the address space built for an earlier draw that bound the same buffer. On each hit, every host import of the space was stamped with a new use count, a loop over all of the space's imports under the imports mutex. Kena: Bridge of Spirits (PPSA01802) hits this cache on almost every address-based build (about 6,100 per 10 s), so the loop cost about 58 us per build.

The space is now stamped once per hit: an import remembers the serial of the cached space that stamped it, and its last use is the later of its own stamp and that space's last hit (effectiveUse). Only the current cached space can hit, so the space that stamped an import last is the one whose hits keep it alive. The last hits of the 64 most recently hit spaces are kept; when one more is added, the space hit longest ago is dropped and its last hit is written back into its imports, so effectiveUse always equals the per-hit stamp it replaces. APS5_NO_SPACE_STAMP_ONCE=1 restores the per-import stamp.

Tested

AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Arch Linux (kernel 7.2.9), Kena: Bridge of Spirits (PPSA01802).

  • Kena forest title scene on main f8b22edfb, no input, APS5_TRACE_SECONDS=100:30, three alternating rounds: main 216 / 325* / 254 presents, this PR 315 / 271 / 303 (* that run had 48 ms GPU busy per present instead of about 80, a lighter stretch of the scene). With APS5_PROFILE_DRAW=1, the [address] line's lease time per address-based build is 58-59 us on main and 0 us with this PR. Summary lines in the review reply.
  • agc_driver_graphics passes, including a new case that commits pages of a registered sparse range between two hits and requires the next builds to read them. ctest -R '^agc_' (on the previous revision, which also had a committed-page memo): 619 of 620 pass; agc_driver_tessellation segfaults on main too.

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
  • 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
  • Unblocks: none (performance of PPSA01802)
  • GPUs tested: AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Arch Linux (kernel 7.2.9)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4894257771 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-16T21:04:28Z. --- ### What The read-only V# address-space cache (#5428) lets a draw reuse the address space built for an earlier draw that bound the same buffer. On each hit, every host import of the space was stamped with a new use count, a loop over all of the space's imports under the imports mutex. Kena: Bridge of Spirits (PPSA01802) hits this cache on almost every address-based build (about 6,100 per 10 s), so the loop cost about 58 us per build. The space is now stamped once per hit: an import remembers the serial of the cached space that stamped it, and its last use is the later of its own stamp and that space's last hit (`effectiveUse`). Only the current cached space can hit, so the space that stamped an import last is the one whose hits keep it alive. The last hits of the 64 most recently hit spaces are kept; when one more is added, the space hit longest ago is dropped and its last hit is written back into its imports, so `effectiveUse` always equals the per-hit stamp it replaces. `APS5_NO_SPACE_STAMP_ONCE=1` restores the per-import stamp. ### Tested AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Arch Linux (kernel 7.2.9), Kena: Bridge of Spirits (PPSA01802). - Kena forest title scene on `main` f8b22edfb, no input, `APS5_TRACE_SECONDS=100:30`, three alternating rounds: `main` 216 / 325* / 254 presents, this PR 315 / 271 / 303 (* that run had 48 ms GPU busy per present instead of about 80, a lighter stretch of the scene). With `APS5_PROFILE_DRAW=1`, the `[address]` line's lease time per address-based build is 58-59 us on `main` and 0 us with this PR. Summary lines in the review reply. - `agc_driver_graphics` passes, including a new case that commits pages of a registered sparse range between two hits and requires the next builds to read them. `ctest -R '^agc_'` (on the previous revision, which also had a committed-page memo): 619 of 620 pass; `agc_driver_tessellation` segfaults on `main` too. ### 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) - [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] Unblocks: none (performance of PPSA01802) - [x] GPUs tested: AMD Radeon RX 9070 XT (RADV GFX1201), Mesa 26.2.4, Arch Linux (kernel 7.2.9) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-16 21:27:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T21:27:27Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 2434 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L241
PR 6479 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L241
PR 6730 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L241, L1354-1355
PR 7466 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L1348
PR 7922 docs/dev/ENVIRONMENT.md L294

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1191 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 1324 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 5431 docs/dev/ENVIRONMENT.md
PR 6146 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6177 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6185 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 6292 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6457 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 6548 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6615 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6628 core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 6636 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
docs/dev/ENVIRONMENT.md
PR 6924 docs/dev/ENVIRONMENT.md
PR 6946 docs/dev/ENVIRONMENT.md
PR 6947 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/ENVIRONMENT.md
PR 7201 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 7233 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7292 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 7332 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
docs/dev/ENVIRONMENT.md
PR 7417 docs/dev/ENVIRONMENT.md
PR 7427 docs/dev/ENVIRONMENT.md
PR 7446 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7457 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/ENVIRONMENT.md
PR 7473 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7484 docs/dev/ENVIRONMENT.md
PR 7514 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7604 docs/dev/ENVIRONMENT.md
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
docs/dev/ENVIRONMENT.md
PR 7683 docs/dev/ENVIRONMENT.md
PR 7844 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6225028234 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955#issuecomment-6225028234). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T21:27:27Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 2434](https://www.github.com/boykopovar/AnyPS5/pull/2434) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L241](https://github.com/boykopovar/AnyPS5/blob/00d7e611efc97d3d1a1c80e79115a1a1955b2267/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L241) | | | | [PR 6479](https://www.github.com/boykopovar/AnyPS5/pull/6479) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L241](https://github.com/boykopovar/AnyPS5/blob/00d7e611efc97d3d1a1c80e79115a1a1955b2267/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L241) | | | | [PR 6730](https://www.github.com/boykopovar/AnyPS5/pull/6730) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L241](https://github.com/boykopovar/AnyPS5/blob/00d7e611efc97d3d1a1c80e79115a1a1955b2267/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L241), [L1354-1355](https://github.com/boykopovar/AnyPS5/blob/00d7e611efc97d3d1a1c80e79115a1a1955b2267/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L1354-L1355) | | | | [PR 7466](https://www.github.com/boykopovar/AnyPS5/pull/7466) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` [L1348](https://github.com/boykopovar/AnyPS5/blob/00d7e611efc97d3d1a1c80e79115a1a1955b2267/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp#L1348) | | | | [PR 7922](https://www.github.com/boykopovar/AnyPS5/pull/7922) | `docs/dev/ENVIRONMENT.md` [L294](https://github.com/boykopovar/AnyPS5/blob/00d7e611efc97d3d1a1c80e79115a1a1955b2267/docs/dev/ENVIRONMENT.md#L294) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 1191](https://www.github.com/boykopovar/AnyPS5/pull/1191) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 1324](https://www.github.com/boykopovar/AnyPS5/pull/1324) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 4448](https://www.github.com/boykopovar/AnyPS5/pull/4448) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` | | [PR 5431](https://www.github.com/boykopovar/AnyPS5/pull/5431) | `docs/dev/ENVIRONMENT.md` | | [PR 6146](https://www.github.com/boykopovar/AnyPS5/pull/6146) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 6185](https://www.github.com/boykopovar/AnyPS5/pull/6185) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 6186](https://www.github.com/boykopovar/AnyPS5/pull/6186) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 6197](https://www.github.com/boykopovar/AnyPS5/pull/6197) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` | | [PR 6292](https://www.github.com/boykopovar/AnyPS5/pull/6292) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 6457](https://www.github.com/boykopovar/AnyPS5/pull/6457) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` | | [PR 6548](https://www.github.com/boykopovar/AnyPS5/pull/6548) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 6615](https://www.github.com/boykopovar/AnyPS5/pull/6615) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 6628](https://www.github.com/boykopovar/AnyPS5/pull/6628) | `core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` | | [PR 6636](https://www.github.com/boykopovar/AnyPS5/pull/6636) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp`<br>`docs/dev/ENVIRONMENT.md` | | [PR 6924](https://www.github.com/boykopovar/AnyPS5/pull/6924) | `docs/dev/ENVIRONMENT.md` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `docs/dev/ENVIRONMENT.md` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`docs/dev/ENVIRONMENT.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` | | [PR 7233](https://www.github.com/boykopovar/AnyPS5/pull/7233) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 7292](https://www.github.com/boykopovar/AnyPS5/pull/7292) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp`<br>`docs/dev/ENVIRONMENT.md` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `docs/dev/ENVIRONMENT.md` | | [PR 7427](https://www.github.com/boykopovar/AnyPS5/pull/7427) | `docs/dev/ENVIRONMENT.md` | | [PR 7446](https://www.github.com/boykopovar/AnyPS5/pull/7446) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 7457](https://www.github.com/boykopovar/AnyPS5/pull/7457) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`docs/dev/ENVIRONMENT.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 7484](https://www.github.com/boykopovar/AnyPS5/pull/7484) | `docs/dev/ENVIRONMENT.md` | | [PR 7514](https://www.github.com/boykopovar/AnyPS5/pull/7514) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` | | [PR 7604](https://www.github.com/boykopovar/AnyPS5/pull/7604) | `docs/dev/ENVIRONMENT.md` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp`<br>`core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp`<br>`docs/dev/ENVIRONMENT.md` | | [PR 7683](https://www.github.com/boykopovar/AnyPS5/pull/7683) | `docs/dev/ENVIRONMENT.md` | | [PR 7844](https://www.github.com/boykopovar/AnyPS5/pull/7844) | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` |
CnRJay commented 2026-10-16 21:55:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-16T21:55:10Z.

Review: COMMENTED


Two correctness questions on the on-by-default part, and no measurement yet.

  • HostImport::spaceSerial holds one serial, but a HostImport is shared by every cached space that binds the same buffer. region.direct->spaceSerial = current->serial is written only on the first hit of a space (spaceUse == 0). If space A is stamped, then space B stamps the same import and overwrites the serial, later hits on A update spaceUses[A] only, so effectiveUse for that import follows B. Once B stops hitting, pointerHeld is false for an import that A's draws still read, and evictable can retire it after 256 uses. Please say why that cannot happen, or keep the stamp per import (the old loop) and only skip the ones already at the current stamp.
  • spaceUses is trimmed with erase(begin()) above 64 entries, i.e. the lowest serial, which is the oldest space and not the least recently hit one. A long-lived hot space is the first to lose its protection.
  • copiedCommitted is computed once per space. These ranges are reserved heaps committed on demand ("committed pages only" in addCopiedRange), so the committed set can grow after the space was built. What invalidates the memo when pages are committed or decommitted? If nothing does, a hit serves the old page list, which is the stale-data case the per-hit DescribeCommitted call was there to prevent.
  • New std::mutex locked on every hit, held across the addCopiedRange loop. A hit is the hot path the PR is about; a lock-free read of an immutable vector published once would do.

The description gives no numbers: "about 24 fps in our local test stack" is not a measurement of this change. Per the Performance report form, please add the summary lines of main and this PR from the same scene in PPSA01802, without any APS5_PROFILE_* switch, with the per-draw time this removes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5554133852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955#pullrequestreview-5554133852). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-16T21:55:10Z. **Review:** COMMENTED --- Two correctness questions on the on-by-default part, and no measurement yet. - `HostImport::spaceSerial` holds one serial, but a `HostImport` is shared by every cached space that binds the same buffer. `region.direct->spaceSerial = current->serial` is written only on the first hit of a space (`spaceUse == 0`). If space A is stamped, then space B stamps the same import and overwrites the serial, later hits on A update `spaceUses[A]` only, so `effectiveUse` for that import follows B. Once B stops hitting, `pointerHeld` is false for an import that A's draws still read, and `evictable` can retire it after 256 uses. Please say why that cannot happen, or keep the stamp per import (the old loop) and only skip the ones already at the current stamp. - `spaceUses` is trimmed with `erase(begin())` above 64 entries, i.e. the lowest serial, which is the oldest space and not the least recently hit one. A long-lived hot space is the first to lose its protection. - `copiedCommitted` is computed once per space. These ranges are reserved heaps committed on demand ("committed pages only" in `addCopiedRange`), so the committed set can grow after the space was built. What invalidates the memo when pages are committed or decommitted? If nothing does, a hit serves the old page list, which is the stale-data case the per-hit `DescribeCommitted` call was there to prevent. - New `std::mutex` locked on every hit, held across the `addCopiedRange` loop. A hit is the hot path the PR is about; a lock-free read of an immutable vector published once would do. The description gives no numbers: "about 24 fps in our local test stack" is not a measurement of this change. Per the Performance report form, please add the summary lines of main and this PR from the same scene in PPSA01802, without any `APS5_PROFILE_*` switch, with the per-draw time this removes.
parl0v commented 2026-10-17 00:05:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-17T00:05:15Z.


Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows, APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1; main af0fff762 vs main + this PR, interleaved with five other PRs in one batch, two rounds. FPS is the mean of the last 10 [present] windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (44-47 ms of idle gaps per frame).

libs FPS GPU busy idle gaps
main 6.61 / 6.76 105 / 104 ms 46 / 44 ms
+ this PR (b3e5e71aa) 6.69 / 6.68 (0.0 %) 105 / 104 ms 45 / 46 ms

Within the run-to-run spread (main itself moved 6.61 -> 6.76 between rounds), no regression, 0 fatal.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227056929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955#issuecomment-6227056929). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-17T00:05:15Z. --- Data point from a CPU-bound scene on Windows: RTX 3060 12 GB (NVIDIA 617.42), i5-12400F, Windows 10 19045, MinGW GCC Release. Minecraft Dungeons II (PPSA16064 01.100.100), title screen, no input, 200 s rows, `APS5_PROFILE_DRAW=1 APS5_PROFILE_GPU=1`; `main` af0fff762 vs `main` + this PR, interleaved with five other PRs in one batch, two rounds. FPS is the mean of the last 10 `[present]` windows, GPU busy and idle gaps per frame over the last 8. This scene is CPU-bound on this machine (44-47 ms of idle gaps per frame). | libs | FPS | GPU busy | idle gaps | |---|---|---|---| | `main` | 6.61 / 6.76 | 105 / 104 ms | 46 / 44 ms | | + this PR (b3e5e71aa) | 6.69 / 6.68 (0.0 %) | 105 / 104 ms | 45 / 46 ms | Within the run-to-run spread (`main` itself moved 6.61 -> 6.76 between rounds), no regression, 0 fatal. AI-assisted: yes (Claude Code)
alfalfa-star commented 2026-10-17 10:36:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-17T10:36:31Z.


Thanks. Changes in 5b01fb212 and 6877d954c (pushed on top, no rebase):

Shared spaceSerial. The scenario needs space A to hit again after B has stamped the shared import. That can't happen: the cache holds one space (Spaces().current), and only that one is looked up and stamped. Once B replaces A, A is never hit again; a build that still holds A doesn't stamp. While B is current, the imports it shares with A carry B's serial, and their effectiveUse follows B's hits. The imports only A used keep A's serial and A's last hit, which is when they were last used through a space. So effectiveUse equals what the old per-hit stamp would have written.

Trimming spaceUses. You're right that erasing the lowest serial isn't LRU. Serials are taken before spaces.current.store, so two concurrent builds can publish out of order. It now drops the entry with the oldest last hit, and writes that hit back into the lastUse of the imports still carrying that serial (clearing it). Trimming never loses protection, and the current space always has the newest hit, so it's never the one dropped.

copiedCommitted. I checked what invalidates it. Every page-state change of registered memory goes through a GuestAllocations mutation (map, mprotect, munmap, reserve) or GuestAllocationsInvalidate; both advance the generation a hit checks, and a mutation over a leased range first drops the cached space through the pin waiter. The one exception was GuestArenaCommit on Windows outside a mutation. But measuring the parts separately showed the memo saved nothing in Kena: its hits have no copied ranges ("imports pass" is 0 us per build with and without it). So I removed it in 6877d954c, together with the lock it needed. That leaves this PR with one on-by-default change. The test I wrote for it stays: spaceCommittedPagesTests commits pages of a registered sparse range between two hits and requires the next first build and hit to read them.

Mutex on every hit. It went with the memo.

Measurement. Kena (PPSA01802), forest title scene, no input. main f8b22edfb with and without this PR, warm cache, APS5_TRACE_SECONDS=100:30 and no other switch. Three rounds, rotated with another build. Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4, Release.

build presents in 30 s p50 frame ms GPU busy ms per present
main 216 / 325* / 254 130.2 / 87.8 / 117.3 78.2 / 48.4 / 82.2
this PR 315 / 271 / 303 95.5 / 111.3 / 98.7 78.7 / 80.8 / 74.5

* That run reached a lighter stretch of the scene (48 ms GPU busy instead of about 80), so it isn't comparable. Per-draw time removed: APS5_PROFILE_DRAW=1 runs of the same scene give, in the [address] line, a lease time per address-based build of 58–59 us on main and 0 us with this PR, at about 6,100 builds per 10 s. An earlier batch (same scene, with the memo still in) had main 165 / 175 / 181 against 208 / 298 / 218.

Summary lines
{"commit":"f8b22edfb7f5","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":771,"ms":30041.458},"presents":216,"frame_ms":{"p50":130.2,"p90":161.713,"p99":275.775,"max":455.902},"gpu_busy_ms_per_present":78.23,"trace":"aps5-trace-f8b22edfb7f5-370363.json.gz"}
{"commit":"5221bc40b19d","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1154,"ms":30067.057},"presents":315,"frame_ms":{"p50":95.542,"p90":98.399,"p99":103.768,"max":124.719},"gpu_busy_ms_per_present":78.708,"trace":"aps5-trace-5221bc40b19d-374016.json.gz"}
{"commit":"f8b22edfb7f5","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1182,"ms":30102.816},"presents":325,"frame_ms":{"p50":87.85,"p90":113.641,"p99":120.253,"max":122.562},"gpu_busy_ms_per_present":48.443,"trace":"aps5-trace-f8b22edfb7f5-388013.json.gz"}
{"commit":"5221bc40b19d","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1030,"ms":30032.77},"presents":271,"frame_ms":{"p50":111.271,"p90":123.356,"p99":145.241,"max":157.55},"gpu_busy_ms_per_present":80.807,"trace":"aps5-trace-5221bc40b19d-380974.json.gz"}
{"commit":"f8b22edfb7f5","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1032,"ms":30016.046},"presents":254,"frame_ms":{"p50":117.267,"p90":121.144,"p99":147.852,"max":152.264},"gpu_busy_ms_per_present":82.231,"trace":"aps5-trace-f8b22edfb7f5-395030.json.gz"}
{"commit":"5221bc40b19d","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1119,"ms":30005.825},"presents":303,"frame_ms":{"p50":98.707,"p90":101.665,"p99":106.324,"max":136.453},"gpu_busy_ms_per_present":74.487,"trace":"aps5-trace-5221bc40b19d-398911.json.gz"}

The traces are kept locally; I can attach any of them.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6232888107 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955#issuecomment-6232888107). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-17T10:36:31Z. --- Thanks. Changes in `5b01fb212` and `6877d954c` (pushed on top, no rebase): **Shared `spaceSerial`.** The scenario needs space A to hit again after B has stamped the shared import. That can't happen: the cache holds one space (`Spaces().current`), and only that one is looked up and stamped. Once B replaces A, A is never hit again; a build that still holds A doesn't stamp. While B is current, the imports it shares with A carry B's serial, and their `effectiveUse` follows B's hits. The imports only A used keep A's serial and A's last hit, which is when they were last used through a space. So `effectiveUse` equals what the old per-hit stamp would have written. **Trimming `spaceUses`.** You're right that erasing the lowest serial isn't LRU. Serials are taken before `spaces.current.store`, so two concurrent builds can publish out of order. It now drops the entry with the oldest last hit, and writes that hit back into the `lastUse` of the imports still carrying that serial (clearing it). Trimming never loses protection, and the current space always has the newest hit, so it's never the one dropped. **`copiedCommitted`.** I checked what invalidates it. Every page-state change of registered memory goes through a `GuestAllocations` mutation (map, mprotect, munmap, reserve) or `GuestAllocationsInvalidate`; both advance the generation a hit checks, and a mutation over a leased range first drops the cached space through the pin waiter. The one exception was `GuestArenaCommit` on Windows outside a mutation. But measuring the parts separately showed the memo saved nothing in Kena: its hits have no copied ranges ("imports pass" is 0 us per build with and without it). So I removed it in `6877d954c`, together with the lock it needed. That leaves this PR with one on-by-default change. The test I wrote for it stays: `spaceCommittedPagesTests` commits pages of a registered sparse range between two hits and requires the next first build and hit to read them. **Mutex on every hit.** It went with the memo. **Measurement.** Kena (PPSA01802), forest title scene, no input. `main` f8b22edfb with and without this PR, warm cache, `APS5_TRACE_SECONDS=100:30` and no other switch. Three rounds, rotated with another build. Linux 7.2.9, RX 9070 XT, RADV Mesa 26.2.4, Release. | build | presents in 30 s | p50 frame ms | GPU busy ms per present | |---|---|---|---| | `main` | 216 / 325* / 254 | 130.2 / 87.8 / 117.3 | 78.2 / 48.4 / 82.2 | | this PR | 315 / 271 / 303 | 95.5 / 111.3 / 98.7 | 78.7 / 80.8 / 74.5 | \* That run reached a lighter stretch of the scene (48 ms GPU busy instead of about 80), so it isn't comparable. Per-draw time removed: `APS5_PROFILE_DRAW=1` runs of the same scene give, in the `[address]` line, a lease time per address-based build of 58–59 us on `main` and 0 us with this PR, at about 6,100 builds per 10 s. An earlier batch (same scene, with the memo still in) had `main` 165 / 175 / 181 against 208 / 298 / 218. <details><summary>Summary lines</summary> ```json {"commit":"f8b22edfb7f5","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":771,"ms":30041.458},"presents":216,"frame_ms":{"p50":130.2,"p90":161.713,"p99":275.775,"max":455.902},"gpu_busy_ms_per_present":78.23,"trace":"aps5-trace-f8b22edfb7f5-370363.json.gz"} {"commit":"5221bc40b19d","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1154,"ms":30067.057},"presents":315,"frame_ms":{"p50":95.542,"p90":98.399,"p99":103.768,"max":124.719},"gpu_busy_ms_per_present":78.708,"trace":"aps5-trace-5221bc40b19d-374016.json.gz"} {"commit":"f8b22edfb7f5","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1182,"ms":30102.816},"presents":325,"frame_ms":{"p50":87.85,"p90":113.641,"p99":120.253,"max":122.562},"gpu_busy_ms_per_present":48.443,"trace":"aps5-trace-f8b22edfb7f5-388013.json.gz"} {"commit":"5221bc40b19d","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1030,"ms":30032.77},"presents":271,"frame_ms":{"p50":111.271,"p90":123.356,"p99":145.241,"max":157.55},"gpu_busy_ms_per_present":80.807,"trace":"aps5-trace-5221bc40b19d-380974.json.gz"} {"commit":"f8b22edfb7f5","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1032,"ms":30016.046},"presents":254,"frame_ms":{"p50":117.267,"p90":121.144,"p99":147.852,"max":152.264},"gpu_busy_ms_per_present":82.231,"trace":"aps5-trace-f8b22edfb7f5-395030.json.gz"} {"commit":"5221bc40b19d","dirty":false,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"100:30"},"gpu":"AMD Radeon RX 9070 XT (RADV GFX1201)","driver":"radv Mesa 26.2.4-arch1.1","os":"Linux 7.2.9-arch1-1","resolution":"3840x2160","window":{"spec":"seconds 100:30","first_present":1119,"ms":30005.825},"presents":303,"frame_ms":{"p50":98.707,"p90":101.665,"p99":106.324,"max":136.453},"gpu_busy_ms_per_present":74.487,"trace":"aps5-trace-5221bc40b19d-398911.json.gz"} ``` </details> The traces are kept locally; I can attach any of them. AI-assisted: yes (Claude Code)
alfalfa-star commented 2026-10-18 12:32:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-18T12:32:22Z.


Rebased on main 0d078f75d (f192d8564). The only conflict was HostImport in GuestBufferMemory.hpp: main added lead next to our spaceSerial, and both fields are kept. Main's new env-reference check also needed a row for APS5_NO_SPACE_STAMP_ONCE in docs/dev/ENVIRONMENT.md (021ed0a2a).

Tested: Release build plus ninja libs; ctest -j8: 1437 of 1438 pass. The one failure, agc_driver_tessellation, segfaults inside RADV 26.2.4 in LinkPipelineFromLibraries. It fails the same way with APS5_NO_GPL=1 and on a build of the older main without this PR, so it isn't from this change. Conventions check passes.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249953204 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955#issuecomment-6249953204). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-18T12:32:22Z. --- Rebased on `main` 0d078f75d (f192d8564). The only conflict was `HostImport` in `GuestBufferMemory.hpp`: main added `lead` next to our `spaceSerial`, and both fields are kept. Main's new env-reference check also needed a row for `APS5_NO_SPACE_STAMP_ONCE` in `docs/dev/ENVIRONMENT.md` (021ed0a2a). Tested: Release build plus `ninja libs`; `ctest -j8`: 1437 of 1438 pass. The one failure, `agc_driver_tessellation`, segfaults inside RADV 26.2.4 in `LinkPipelineFromLibraries`. It fails the same way with `APS5_NO_GPL=1` and on a build of the older main without this PR, so it isn't from this change. Conventions check passes. AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-19 12:26:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T12:26:07Z.


This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6267168950 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955#issuecomment-6267168950). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T12:26:07Z. --- <!-- pr-labels-perf --> This pull request is labeled `perf`, so it needs the summary line of a capture on `main` and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both `aps5-summary.jsonl` lines, attach the two traces and add the output of `tools/trace_digest.py`.
adriadam10 commented 2026-10-19 15:33:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T15:33:34Z.


Checked the net diff against main: stamping the cached space once per hit gives the same effectiveUse as the per-import stamp (only the current space can hit, shared imports move to the new space's serial with a newer lastUse, trimming writes the last hit back into the imports), the other lastUse writers only ever set a newer value, and the memo/mutex the earlier review questioned are gone. Rebased on main (only conflict: spaceSerial next to the new HostImport fields); net diff unchanged. Note that spaceCommittedPagesTests also passes without this change, so nothing pins the once-per-hit stamping yet; not blocking. Merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6271010665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6955#issuecomment-6271010665). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T15:33:34Z. --- Checked the net diff against `main`: stamping the cached space once per hit gives the same `effectiveUse` as the per-import stamp (only the current space can hit, shared imports move to the new space's serial with a newer `lastUse`, trimming writes the last hit back into the imports), the other `lastUse` writers only ever set a newer value, and the memo/mutex the earlier review questioned are gone. Rebased on `main` (only conflict: `spaceSerial` next to the new `HostImport` fields); net diff unchanged. Note that `spaceCommittedPagesTests` also passes without this change, so nothing pins the once-per-hit stamping yet; not blocking. Merged.
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!6955
No description provided.