fix(agc): throw instead of aborting when a heap mirror cannot be made #1085

Merged
Celegans12 merged 1 commit from upstream-pr/1085 into main 2026-10-09 19:05:48 +00:00
Celegans12 commented 2026-10-07 10:13:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T10:13:03Z.


What

When the device refused a heap mirror's buffer, or a new mirror would go past APS5_HEAP_MIRROR_MIB, acquireMirror printed a FATAL line and called abort(), so one address-based build short of host memory ended the process. PPSA26344 v1.008 hit it at 478 s, with 6.8 GiB of heap mirrors next to the host imports in the 16 GiB host-visible heap.

  • A mirror that would go past APS5_HEAP_MIRROR_MIB first sweeps the mirrors whose range the guest freed since the last build's sweep, before its allocation. If it still does not fit, the build throws heap mirror of 0x...+0x...: past the budget; heap mirrors hold ....
  • The mirror is allocated once. A refusal throws heap mirror of 0x...+0x...: vkAllocateMemory buffer: Vulkan result -2; heap mirrors hold ..., so the draw or dispatch fails like any other allocation; there is no second try. Nothing is registered for the range.
  • Nothing changes while memory suffices.
  • #290 edits other functions of the file, and this commit applies on top of it cleanly. #1410 and #1411 (ours) change sweepMirrors and acquireMirror elsewhere; both merge cleanly, and the tests pass merged with them.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 9619edff: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 406/406 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 405/405 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • agc_driver_graphics (APS5_HEAP_MIRROR_MIB=4, mock memory limit): a mirror past the budget is made in the memory of the expired mirror swept first; a refused one fails its build with Vulkan result -2 after one allocation attempt, and is made once the limit is lifted. Fails on main: FATAL: heap mirror of ...: past the budget, then abort().
  • PPSA26344 v1.008 with #290 (previous revision, same until a refusal): no FATAL in 900 s, host memory peaked at 13.1 of 15.9 GiB.
  • Not tested: Linux (CI), console behaviour.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4771153111 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1085). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T10:13:03Z. --- ### What When the device refused a heap mirror's buffer, or a new mirror would go past `APS5_HEAP_MIRROR_MIB`, `acquireMirror` printed a FATAL line and called `abort()`, so one address-based build short of host memory ended the process. PPSA26344 v1.008 hit it at 478 s, with 6.8 GiB of heap mirrors next to the host imports in the 16 GiB host-visible heap. - A mirror that would go past `APS5_HEAP_MIRROR_MIB` first sweeps the mirrors whose range the guest freed since the last build's sweep, before its allocation. If it still does not fit, the build throws `heap mirror of 0x...+0x...: past the budget; heap mirrors hold ...`. - The mirror is allocated once. A refusal throws `heap mirror of 0x...+0x...: vkAllocateMemory buffer: Vulkan result -2; heap mirrors hold ...`, so the draw or dispatch fails like any other allocation; there is no second try. Nothing is registered for the range. - Nothing changes while memory suffices. - #290 edits other functions of the file, and this commit applies on top of it cleanly. #1410 and #1411 (ours) change `sweepMirrors` and `acquireMirror` elsewhere; both merge cleanly, and the tests pass merged with them. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 9619edff: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 406/406 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 405/405 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - `agc_driver_graphics` (`APS5_HEAP_MIRROR_MIB=4`, mock memory limit): a mirror past the budget is made in the memory of the expired mirror swept first; a refused one fails its build with `Vulkan result -2` after one allocation attempt, and is made once the limit is lifted. Fails on main: `FATAL: heap mirror of ...: past the budget`, then `abort()`. - PPSA26344 v1.008 with #290 (previous revision, same until a refusal): no FATAL in 900 s, host memory peaked at 13.1 of 15.9 GiB. - Not tested: Linux (CI), console behaviour. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
oneandonlydean commented 2026-10-08 03:25:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:25:36Z.


acquireMirror retries the allocation after the device refuses it (GuestBufferMemory.cpp:793-811). Retrying after an error isn't allowed here (#182); please sweep before the first allocation if you want the sweep, and keep the throw. The runtime_error instead of abort() is good.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051537791 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1085#issuecomment-6051537791). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T03:25:36Z. --- `acquireMirror` retries the allocation after the device refuses it (`GuestBufferMemory.cpp:793-811`). Retrying after an error isn't allowed here (#182); please sweep before the first allocation if you want the sweep, and keep the throw. The `runtime_error` instead of `abort()` is good.
Celegans12 commented 2026-10-08 04:17:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T04:17:05Z.


Thanks for pointing me at #182, I hadn't counted a retry after the device refuses as an error-driven fallback, but it is one. I've dropped it in 6ab850ec9: when a new heap mirror would go past APS5_HEAP_MIRROR_MIB, acquireMirror now sweeps the mirrors whose range is gone before the first and only allocation, and a refusal throws the runtime_error straight away. The test counts allocation attempts now and checks that a refused mirror fails after exactly one. If you'd rather not have the sweep there at all, I can take it out too.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052100729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1085#issuecomment-6052100729). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-08T04:17:05Z. --- Thanks for pointing me at #182, I hadn't counted a retry after the device refuses as an error-driven fallback, but it is one. I've dropped it in 6ab850ec9: when a new heap mirror would go past `APS5_HEAP_MIRROR_MIB`, `acquireMirror` now sweeps the mirrors whose range is gone before the first and only allocation, and a refusal throws the `runtime_error` straight away. The test counts allocation attempts now and checks that a refused mirror fails after exactly one. If you'd rather not have the sweep there at all, I can take it out too.
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!1085
No description provided.