perf(agc): retry hot heap mirrors as host imports behind a switch #22438

Merged
oneandonlydean merged 7 commits from upstream-pr/22438 into main 2026-11-20 09:59:55 +00:00
oneandonlydean commented 2026-11-17 15:54:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-17T15:54:53Z.


What

An experiment for #22339, behind APS5_HEAP_MIRROR_RETRY=1. Without the variable nothing changes.

Background: a registered heap that was refused as a host import once (budget full) is heap mirrored. While it stays write-watched, a cached address space keeps the mirror and never asks for the import again; only a rebuild of the space does. Since #15919 an import change patches the space instead of rebuilding it, and since #16751 nothing is evicted while recorded work is active, because the retired bytes stay pinned until that work is released. On PPSA06866 this leaves a hot heap mirrored for the whole run: it is refreshed on every address-based build and each refresh writes pending images back.

With the switch:

  • Every 64 address-based builds served by the cached space, a heap mirror that was refilled in at least 32 of them is tried as a host import again, with eviction of idle imports allowed.
  • When recorded work is active and the idle imports would make room, they are retired ahead and the heap is owed its import. Until then other requesters (access windows, joins, color targets) cannot take the owed room. The space is rebuilt once the retired bytes are released, and that build imports the heap. An owed heap expires after 64 builds, so a heap that never fits costs one round of idle imports per 64 builds at most.
  • A cached space that holds heap mirrors is rebuilt after an import change instead of patched, as before #15919.

The [address] profile line gains heap mirror retries N (imported N, owed N).

Tested

Linux, built on e7988a85b0. agc_driver_graphics passes with the new heapMirrorRetryTests, which runs both arms on a write-watched block: without recorded work the retried heap replaces an idle import at once; with a recorder active the idle import is retired ahead, the heap stays mirrored while the bytes are held, and the first build after their release rebuilds the space and imports the heap. Without the switch 140 builds leave the mirror and the idle import alone. The test body is not built on Windows.

Not tested: no title was run. PPSA06866 is not available on my machine, so there are no performance numbers. The run that would settle it is the scene of #22339 (phoenix-31) with APS5_PROFILE_DRAW=1, three arms on this branch: default, APS5_HEAP_MIRROR_RETRY=1, and APS5_HEAP_MIRROR_RETRY=1 with APS5_NO_SPACE_PATCH=1. The [address] and [buffers] image mirrors lines of each arm show whether the heap leaves the mirror (retries, imported, owed, heap MiB) and what it does to the frame time.

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; silent stubs are listed under Silent stubs in their library's technical debt
  • 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: none (see #22339)
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4090, driver 610.57.04, Linux
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5360210161 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22438). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-17T15:54:53Z. --- ### What An experiment for #22339, behind `APS5_HEAP_MIRROR_RETRY=1`. Without the variable nothing changes. Background: a registered heap that was refused as a host import once (budget full) is heap mirrored. While it stays write-watched, a cached address space keeps the mirror and never asks for the import again; only a rebuild of the space does. Since #15919 an import change patches the space instead of rebuilding it, and since #16751 nothing is evicted while recorded work is active, because the retired bytes stay pinned until that work is released. On PPSA06866 this leaves a hot heap mirrored for the whole run: it is refreshed on every address-based build and each refresh writes pending images back. With the switch: - Every 64 address-based builds served by the cached space, a heap mirror that was refilled in at least 32 of them is tried as a host import again, with eviction of idle imports allowed. - When recorded work is active and the idle imports would make room, they are retired ahead and the heap is owed its import. Until then other requesters (access windows, joins, color targets) cannot take the owed room. The space is rebuilt once the retired bytes are released, and that build imports the heap. An owed heap expires after 64 builds, so a heap that never fits costs one round of idle imports per 64 builds at most. - A cached space that holds heap mirrors is rebuilt after an import change instead of patched, as before #15919. The `[address]` profile line gains `heap mirror retries N (imported N, owed N)`. ### Tested Linux, built on `e7988a85b0`. `agc_driver_graphics` passes with the new `heapMirrorRetryTests`, which runs both arms on a write-watched block: without recorded work the retried heap replaces an idle import at once; with a recorder active the idle import is retired ahead, the heap stays mirrored while the bytes are held, and the first build after their release rebuilds the space and imports the heap. Without the switch 140 builds leave the mirror and the idle import alone. The test body is not built on Windows. Not tested: no title was run. PPSA06866 is not available on my machine, so there are no performance numbers. The run that would settle it is the scene of #22339 (`phoenix-31`) with `APS5_PROFILE_DRAW=1`, three arms on this branch: default, `APS5_HEAP_MIRROR_RETRY=1`, and `APS5_HEAP_MIRROR_RETRY=1` with `APS5_NO_SPACE_PATCH=1`. The `[address]` and `[buffers] image mirrors` lines of each arm show whether the heap leaves the mirror (retries, imported, owed, heap MiB) and what it does to the frame time. ### 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; silent stubs are listed under Silent stubs in their library's technical debt - [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: none (see #22339) - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4090, driver 610.57.04, Linux - [x] AI-assisted: yes
MarcZX10 commented 2026-11-18 12:04:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T12:04:53Z.

Review: COMMENTED


Reviewed — no blocking findings

The targeted inspection found no verified blocking defect in the retry and retire-credit paths at head e01b313b65eac44edeeba8be5003614ac9678af3; executable checks were not run.

What I ran

  • Read the prepared description, commit list, manifest, and diff; inspected the changed import-budget and address-space retry logic at the pinned head.
  • No build or tests run. No repository changes made.

Results

Check Result Note
Diff and changed code passed Key retry and credit paths inspected
Build and tests not run No executable checks performed

Findings

Blocking

None verified in the inspected code.

Non-blocking

  • The description reports Linux coverage and explicitly notes that no title or performance run was available. The intended PPSA06866 comparison remains unverified; it would establish the experiment’s practical impact.

Not verified

  • GuestBufferMemory.cpp was read only in targeted ranges because its full text was excluded as too large. Thus this is not a complete review of that file or every changed hunk.
  • BdaResources.cpp and docs/dev/ENVIRONMENT.md are listed as included in the manifest but their full texts were not inspected; the test implementation was read from the diff only.
  • No build, tests, title run, Windows run, or performance measurements were performed by this reviewer. Author-reported Linux test results were not independently verified.
  • review/files.json could not be read through the available reader; the manifest shows GuestBufferMemory.cpp excluded for size and the other two changed files included.

To get this to a good state

Nothing is required. Optional: run the documented PPSA06866 three-arm comparison and report the profile and frame-time results.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956204017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22438#pullrequestreview-5956204017). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T12:04:53Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The targeted inspection found no verified blocking defect in the retry and retire-credit paths at head `e01b313b65eac44edeeba8be5003614ac9678af3`; executable checks were not run. ## What I ran - Read the prepared description, commit list, manifest, and diff; inspected the changed import-budget and address-space retry logic at the pinned head. - No build or tests run. No repository changes made. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Key retry and credit paths inspected | | Build and tests | not run | No executable checks performed | ## Findings ### Blocking None verified in the inspected code. ### Non-blocking - The description reports Linux coverage and explicitly notes that no title or performance run was available. The intended PPSA06866 comparison remains unverified; it would establish the experiment’s practical impact. ## Not verified - `GuestBufferMemory.cpp` was read only in targeted ranges because its full text was excluded as too large. Thus this is not a complete review of that file or every changed hunk. - `BdaResources.cpp` and `docs/dev/ENVIRONMENT.md` are listed as included in the manifest but their full texts were not inspected; the test implementation was read from the diff only. - No build, tests, title run, Windows run, or performance measurements were performed by this reviewer. Author-reported Linux test results were not independently verified. - `review/files.json` could not be read through the available reader; the manifest shows `GuestBufferMemory.cpp` excluded for size and the other two changed files included. ## To get this to a good state Nothing is required. Optional: run the documented PPSA06866 three-arm comparison and report the profile and frame-time results.
MarcZX10 commented 2026-11-18 13:43:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T13:43:32Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: fix the host import retry path so a retry can admit the heap after retiring idle imports, and keep the retry guard active through the import attempt.

What I ran

Reviewed head e179f36c12f0ac2c023ba53e973438c48c8dcb57. No commands or tests were run; the prepared reader was used to inspect the diff and source.

Results

Check Result Note
Source review failed Two retry-path defects verified
Build and tests not run Author reports Linux tests; not independently run
Windows and title behavior not run No Windows build or title run confirmed

Findings

Blocking

  • core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:2450: When an owed heap retry finds enough idle imports, evictable is capped to the retire-credit allowance. With retire credit disabled, or when retired + replaced exceeds the allowance, this cap is zero. The subsequent test at lines 2451–2460 uses the uncapped idle amount to retire imports and record the heap as owed, but then returns without importing it. On the next build the owed bytes are cleared because the range is not yet imported; the heap can therefore remain mirrored despite available idle imports. The retry path should allow retiring the idle imports needed for the heap attempt, while preserving the recorded-work pinning rules.
  • core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:5416: The retry flag is cleared immediately after importsNow, before the import allocation path runs. The special idle-import retirement branch at line 2452 checks this flag, so a retry that reaches importRunAt cannot activate the branch. Keep the retry context active through the complete attempt, including allocation, and clear it reliably afterward.

Non-blocking

None.

Not verified

The full source file GuestBufferMemory.cpp was excluded from the prepared files because it was too large; relevant functions and call sites were read through repo_read.py. The included files GuestBufferMemory.hpp, BdaResources.cpp, and docs/dev/ENVIRONMENT.md were read. No other changed files were listed in the manifest. Build, tests, Windows behavior, and title/performance behavior were not verified.

To get this to a good state

Correct both retry-path issues, then rerun the reported agc_driver_graphics coverage on the updated head, including heap retry with recorded work and with enough idle imports.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5957821151 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22438#pullrequestreview-5957821151). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T13:43:32Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: fix the host import retry path so a retry can admit the heap after retiring idle imports, and keep the retry guard active through the import attempt. ## What I ran Reviewed head `e179f36c12f0ac2c023ba53e973438c48c8dcb57`. No commands or tests were run; the prepared reader was used to inspect the diff and source. ## Results | Check | Result | Note | |---|---|---| | Source review | failed | Two retry-path defects verified | | Build and tests | not run | Author reports Linux tests; not independently run | | Windows and title behavior | not run | No Windows build or title run confirmed | ## Findings ### Blocking - `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:2450`: When an owed heap retry finds enough idle imports, `evictable` is capped to the retire-credit allowance. With retire credit disabled, or when `retired + replaced` exceeds the allowance, this cap is zero. The subsequent test at lines 2451–2460 uses the uncapped idle amount to retire imports and record the heap as owed, but then returns without importing it. On the next build the owed bytes are cleared because the range is not yet imported; the heap can therefore remain mirrored despite available idle imports. The retry path should allow retiring the idle imports needed for the heap attempt, while preserving the recorded-work pinning rules. - `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp:5416`: The retry flag is cleared immediately after `importsNow`, before the import allocation path runs. The special idle-import retirement branch at line 2452 checks this flag, so a retry that reaches `importRunAt` cannot activate the branch. Keep the retry context active through the complete attempt, including allocation, and clear it reliably afterward. ### Non-blocking None. ## Not verified The full source file `GuestBufferMemory.cpp` was excluded from the prepared files because it was too large; relevant functions and call sites were read through `repo_read.py`. The included files `GuestBufferMemory.hpp`, `BdaResources.cpp`, and `docs/dev/ENVIRONMENT.md` were read. No other changed files were listed in the manifest. Build, tests, Windows behavior, and title/performance behavior were not verified. ## To get this to a good state Correct both retry-path issues, then rerun the reported `agc_driver_graphics` coverage on the updated head, including heap retry with recorded work and with enough idle imports.
MarcZX10 commented 2026-11-19 12:26:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T12:26:46Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks merging based on the code inspected; the experiment’s behavior is gated by environment switches, and I found no verified blocking defect.

What I ran

Reviewed head 9986d0ec58a95d2a28e114ef3744cb40ff8b7034 using the prepared diff and repo_read.py for targeted source ranges. No build or tests were run. The description reports Linux build and test results; these were not independently verified.

Results

Check Result Note
Diff and targeted source review passed Retry and retire-credit paths inspected
Build and tests not run Author reports Linux results
Runtime performance not run No title run or performance captures reported

Findings

Blocking

None.

Non-blocking

  • The retry behavior is an experiment without title-level performance measurements. The description identifies the Phoenix scene and profile counters needed to assess whether it improves frame time; sharing those captures would help establish the change’s value.

Not verified

  • GuestBufferMemory.cpp was read through targeted ranges with repo_read.py; its full 8,409-line text was not read. BdaResources.cpp was read over the changed test range. The prepared diff and manifest were read. GuestBufferMemory.hpp and ENVIRONMENT.md were not fully read; their changed lines were reviewed in the diff and the documentation range was checked. No other files were listed in the manifest.
  • Build, tests, Windows behavior, console behavior, and performance were not independently verified.

To get this to a good state

Nothing is required. Optional: report the Phoenix scene profile captures described in the PR description.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5974986521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22438#pullrequestreview-5974986521). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T12:26:46Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks merging based on the code inspected; the experiment’s behavior is gated by environment switches, and I found no verified blocking defect. ## What I ran Reviewed head `9986d0ec58a95d2a28e114ef3744cb40ff8b7034` using the prepared diff and `repo_read.py` for targeted source ranges. No build or tests were run. The description reports Linux build and test results; these were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Retry and retire-credit paths inspected | | Build and tests | not run | Author reports Linux results | | Runtime performance | not run | No title run or performance captures reported | ## Findings ### Blocking None. ### Non-blocking - The retry behavior is an experiment without title-level performance measurements. The description identifies the Phoenix scene and profile counters needed to assess whether it improves frame time; sharing those captures would help establish the change’s value. ## Not verified - `GuestBufferMemory.cpp` was read through targeted ranges with `repo_read.py`; its full 8,409-line text was not read. `BdaResources.cpp` was read over the changed test range. The prepared diff and manifest were read. `GuestBufferMemory.hpp` and `ENVIRONMENT.md` were not fully read; their changed lines were reviewed in the diff and the documentation range was checked. No other files were listed in the manifest. - Build, tests, Windows behavior, console behavior, and performance were not independently verified. ## To get this to a good state Nothing is required. Optional: report the Phoenix scene profile captures described in the PR description.
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!22438
No description provided.