fix(agc): an address-based build evicts idle imports instead of copying past the cap #9514
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9514"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T23:59:46Z.
What
An address-based build (
AcquireRegistered) imports each registered GPU range whole and never evicts to do it. When the host import budget refuses a range and no heap mirror serves it, the build copies the range, and copies pastAPS5_ADDRESS_COPY_MAX_MIB(64 MiB by default) abort the process inAddressCopyOverflow. Onmaina6dcea9279the pass still imports without eviction, and the cap still aborts.Titles that abort this way on
main:main36f60df9e(discussion #1283, Mouhand-Kaddo):maina569f47cb(discussion #357, frankea). In Sky Garden the budget refuses 7 to 11 imports, thenFATAL: an address-based build copies 1099 MiB of 1 registered ranges(2 runs of 2; 285 MiB in a second run). That post doesn't give the reason part of the line.main0c6a5bd59, New Game from the title (parl0v's runs, discussion #7657):FATAL: an address-based build copies 118 MiB of 1812 registered ranges, past 64 MiB (APS5_ADDRESS_COPY_MAX_MIB), with the host import budget at 4054 of 4055 MiB. With this PR (307bf8157a, onmaina6dcea9279), the build logsimported by evicting idle imports, as copying it would pass APS5_ADDRESS_COPY_MAX_MIBand doesn't abort. The load then runs out of host-visible memory (vkAllocateMemory ... heap 1 7704/7448 MiB), whichmainalso reaches withAPS5_ADDRESS_COPY_MAX_MIB=1024, so that's a separate limit.The change (three commits, and a debt entry):
7d6c475b95, the fix. The pass retries a refused range's import with eviction only when copying it would take the build's copies past the cap, i.e. only when the build would abort otherwise.buildFloor) and are never evicted.Uploadand the address-space cache already honour.[gpu] host import budget: 0x…+0x… imported by evicting idle imports, as copying it would pass APS5_ADDRESS_COPY_MAX_MIB.SetAddressCopyLimit) is read once with the env cap, so eviction triggers exactly where the abort would.6fcf7b6573, the tests.agc_address_copy_capbuilds over a partly unwatched heap whose import the budget refuses, so no mirror serves it, while idle imports hold the budget.agc_address_copy_cap_rememberedis the same build answered from the remembered refusal. Both run on the mock device.307bf8157a. A heap's copy reason askedGuestMemory::Watchedfor every copied heap range on every plan. That takes the tracker's global mutex and walks its coverage, only to label a FATAL line. Now a copy records that it is a heap and whether the budget refused it, andAddressCopyOverflownames the reason only for the copies its report lists. The report's text is unchanged.f2e4290e9c, a debt entry. A registered range larger than the device's largest allocation is imported in pieces since #7292. If the budget refuses a piece, the range is mirrored or copied without this PR's evicting retry, so such a copy can still exceedAPS5_ADDRESS_COPY_MAX_MIBand end the build. The entry says so; covering it needsimportPiecesto evict, which is a follow-up after this PR.Related: #7844 (Mouhand-Kaddo) raises the host import budget on hosts with a large heap, which makes this refusal rarer there. This PR removes the abort when a refusal still happens, so the two compose. They share one line of the debt entry; this PR goes after #7844 and resolves it.
Overlap: checked with
git merge-treeagainst every open PR touching these files, onmaina6dcea9279. The conflicts are on adjacent lines:mainitself.HostImports. The cache is dropped whenever the import epoch or the number of imports changes, which this PR's evicting import changes, so it never returns a retired import. The conflict is the adjacent fields.importRunAtandretireImporttoo, on other lines. It records pending imports, andretireImportdrops them, which covers this PR's evicting import as well. The conflict is a neighbouring line of the debt file.WriteBack, which this PR doesn't touch. The conflict is a test declaration inBdaTests.hpp.Tested
main'sGuestBufferMemory.cppand this PR's tests:FATAL: an address-based build copies 2 MiB of 1 registered ranges, past 1 MiB (APS5_ADDRESS_COPY_MAX_MIB); the largest: 0x…+0x200000 (2.0 MiB committed, outside the write-watched arena).6fcf7b6573), both pass 10/10 on Windows and Linux, and the libc and libkernel suites pass (Windows 142 and 207, Linux 115 and 197).precise_wait, a timing test that flakes on that runner.307bf8157a(Ubuntu 24.04, GCC 13.3, lavapipe, unprivileged user):agc_driver_sgpr_pattern_fill_keysis a load flake thatmainshares; it then passed ×20 alone.guest_socket_stream_options,guest_socket_address_lengthandguest_tcpfail because that machine has no IPv6.check_test_registration.py: none new.check_skips.py:guest_sce_netskipped, for the same IPv6 reason.ctest -R '^agc_(address|heap_mirror|driver_bda|driver_graphics)': 11/11, 13/13, and 13/13 ×5.agc_address_copy_cap_rememberedaborts 3/3.agc_driver_graphicsfails: "the copy limit does not name a copied heap's reason".AcquireRegistered+Upload+WriteBack,mainand this PR alternated over two rounds, with the address-space cache on and off. Later builds agree within 0.1–3 µs. First-of-epoch builds scatter ±15% on both sides alike.mainatab347d144d(f7d4e920ca, no conflicts, the PR's own diff unchanged), on GitHub's runners (run): the focused tests pass 10 runs in a row on Linux and Windows, and the libc and libkernel suites pass on both (116 and 197 on Linux, 143 and 207 on Windows).mainagainst this PR (CONTRIBUTING's AGC rule), on one GitHub Linux runner (run). Both runs usedVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andctest -V, withVK_LOADER_DEBUG=layerto show the layer loading. The device was llvmpipe (LLVM 20.1.2) on Mesa 25.2.8, Ubuntu 24.04.5, Khronos validation layers 1.3.275.agc_driver_guest_memory_lifetime_{copy,direct,locked,heap,heap_uncached},agc_driver_host_import_lifetime,agc_driver_host_import_mutation_raceandagc_driver_host_import_failure_handles.main's tree ran these tests once and this PR's three times. The loader insertedVK_LAYER_KHRONOS_validationin every test process, 8 times onmainand 24 with this PR, and neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-VkDeviceCreateInfo-pNext-pNext, for a device-creation structure newer than that layer version. This PR adds noVUID-message.check_conventions.py: no errors and no comment lines added. One warning,debt-length, on the host import entry: 3,911 characters, against 3,708 onmain.maind6eafa54d, with and without this PR and #7844, a warm-up and two interleaved rounds each.mainand with this PR, and nothing logscopies ... past 64 MiBor this PR's eviction line.a0885b0c08and846f95650a, merges ofmain938812df14and then4997726a5f. The first conflict was the debt file, wheremainadded aDevice-local stagingentry next to this PR's sentence inHost import windows and budget; both are kept. The second wasGuestBufferMemory.cpp's address-based pass, where #7292 added its piece import next to this PR'soverBudgetflag; both are kept, and this PR's copy-limit override variable is renamed fromlimittocopyOverride, so #7292'slimitin the loop doesn't shadow it. Apart from that rename, the PR's own changes are unchanged. On GitHub's runners (run), the two copy-cap tests and the heap-mirror, BDA, graphics and host-import tests the harness maps from the changed files pass 10 runs in a row: on Linux 36 of 36; on Windows 32 of 35, with 3 skipped without a Vulkan device; none fail. The libc and libkernel suites pass on both (119 and 201 tests on Linux, 146 and 211 on Windows), run withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.041df5af17onmain941ace5f34with #6182, 7 minutes per run, no input.imported by evicting idle imports, as copying it would pass APS5_ADDRESS_COPY_MAX_MIBline.--frame-red-zone, both runs then crash in the title's mixer thread (SceSndzAudioOutMain). That's the Windows red-zone problem from #361: a leaf keeps a pointer at[rsp-0x20], and a resumed write fault overwrites it. Relinked with--frame-red-zone(#5640), the same build reaches the title screen at about 10 FPS with no crash, with the eviction taking place (1 run).--frame-red-zone, which is opt-in. Chronyyx then measured the eviction's part (comment), in 150 s runs without--frame-red-zone. This PR's retry retires 3 idle imports for the 1 GiB range, none of them holding the mixer's buffer, and fills the budget. About 2 s later,main's least-recently-used eviction retires about 25 more for an 88 MiB import, one of them holding the mixer's output buffer, and the re-import of that range is refused. Resumed write faults go from 16 in each of two runs with a larger budget and no eviction to 169–189 with it, all after this PR's eviction line, and the mixer's next store faults into #361's red-zone damage. The sound crash came in 5 of 6 runs with the eviction and 0 of 1 without; with--frame-red-zone, in 0 of 4 runs with the eviction. By his reading, nothing in this PR needs to change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T00:09:48Z.
Before marking this ready, please bring the checklist into line with the repository rules in two places:
Unblocksnames Demon’s Souls and ASTRO BOT and the body links their Game bring-up discussions (#1283 and #357), but the checklist needs each title ID paired with its discussion, e.g.Unblocks: PPSA01342 #1283, PPSA21564 #357.Depends on: none.CONTRIBUTING.mdasks authors to agree on order for reported overlaps and declare the agreed dependencies. Please coordinate with the affected authors, then update the dependency line and overlap notes to reflect the agreed merge order.I have not reviewed or rerun the full implementation/tests yet; this note is limited to the template and overlap requirements visible in the current draft.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:05:40Z.
The title unblock checklist is now correct, and #7844 is declared. I reviewed the live functional overlaps: #8380 and #7292 modify the same import path with piece imports, and your description proposes that #9514 merge first so those branches rebase afterward. The proposal is technically plausible from the adjacent branches, but I do not see either author agreeing in the PR threads. Please get explicit confirmation from both authors (or revise the order and dependency entries to their agreed sequence) before merge. For #8896, #8874, #9402 and #8104, please document which are behavioral overlaps requiring ordering and which are adjacent/test/debt edits that only need a rebase; “whichever lands second” by itself does not record an agreed order. #7978 appears to be a separate debt-line edit, while #7844 is now declared.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T02:12:28Z.
Thanks, @MarcZX10. The Overlap section now separates the two kinds:
retireImport, which this PR's eviction goes through;WriteBack, with only a test declaration next to ours;Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-22T02:42:44Z.
I tested this on Sword of the Sea (PPSA25344, 01.510.000), starting New Game from the title. My machine: RTX 4060 8 GB, i5-14400F, 16 GB RAM, Windows 10. Same relinked executable for every run,
APS5_PROFILE_DRAW=1, no other env.0c6a5bd59FATAL: an address-based build copies 118 MiB of 1812 registered ranges, past 64 MiB (APS5_ADDRESS_COPY_MAX_MIB); host import budget 4054 of 4055 MiB live, 11414 imports (4410 MiB) refused0c6a5bd59+APS5_ADDRESS_COPY_MAX_MIB=1024vkAllocateMemory buffer slab ... heap 1 7704/7448 MiB307bf8157)imported by evicting idle imports, as copying it would pass APS5_ADDRESS_COPY_MAX_MIBlogged, no copy-cap abort; 10068 imports (3813 MiB) refused; thenheap mirror of 0x32af9e0000+0x100000: vkAllocateMemory buffer ... heap 1 7704/7448 MiB; heap mirrors hold 2858 MiBSo on this title the PR does what it says: the cap abort is gone. The load then runs out of host-visible memory (heap 1), which also happens on main once the cap is raised. That looks like a separate limit, so it shouldn't block this PR. The main runs are on
0c6a5bd59and the PR is ona6dcea927, so the bases differ by the main commits in between; none of those touch the relinker.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T02:49:54Z.
@parl0v thanks for the three runs on Sword of the Sea (PPSA25344), and for keeping the relinked executable and the env the same in all of them. They show what the PR is for: on
mainthe New Game load aborts at the copy cap, and with the PR the build imports by evicting instead, with no abort. Agreed that the host-visible heap running out afterwards is a separate limit, sincemainreaches it too once the cap is raised. Your runs are in the description now, and the title is on the Unblocks line.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T02:55:35Z.
@parl0v if you'd like to try one more thing: two open PRs target the heap 1 stop you hit next. #7647 (fma-rc) binds heap mirrors in device-local memory, only where the guest holds bytes, when the GPU reports sparse aliased buffers. #8016 (PayloadAnim) falls back to device-local heap mirrors when the host-visible allocation fails. A run of this PR with either one on Sword of the Sea (PPSA25344) would show whether the load gets further. Nothing here waits on it.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:20:27Z.
Review: DISMISSED
I reviewed the implementation and reported regressions. The cap is reused for both the decision to evict and the final fatal check; imported ranges already held by the build are retained, and the tests exercise both fresh and remembered budget refusals. The Sword of the Sea report usefully shows this removes the copy-cap abort while clearly separating the later heap-allocation failure.
I’m requesting changes for these remaining repository requirements:
a6dcea9279, while current upstream main isc61d20f548. Please update the branch and rerun the focused regression and required validation checks against that current base.The existing report includes extensive focused tests and title evidence; I did not rerun them locally. Hosted checks shown here are policy checks only, with product jobs skipped.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T05:46:54Z.
Thanks, @MarcZX10. On your three points:
mainatab347d144dmerged in (f7d4e920ca), with the PR's own diff unchanged, and the focused tests pass 10 runs in a row on both runners (run).mainand on this PR, on one Linux runner, with llvmpipe on Mesa 25.2.8 and Ubuntu 24.04.5. The layer loaded in every test process on both sides, and the only message,VUID-VkDeviceCreateInfo-pNext-pNext, appears on both. This PR's own tests run on the mock device, so the comparison adds the real-device guest-memory and host-import tests on the same path.Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-22T09:11:55Z.
A Linux/RADV data point for the ASTRO BOT Sky Garden case, since the description's ASTRO BOT run is Windows/NVIDIA.
Setup: ASTRO BOT PPSA21567 01.019.000,
-lvl underwater_aerial_garden, no input, Ryzen 7 7800X3D, 31 GiB, RX 9070 XT (RADV Mesa 26.2.4), CachyOS kernel 7.3.0. Headless gamescope at 3840x2160,APS5_TRACE_SECONDS=90:50, default host import budget (7807 MiB onmainhere). All builds are onmaind6eafa54d:main, + this PR (f7d4e920c), + #7844, + both (only a doc conflict). One warm-up run per build, then two rounds interleaved. Frame p50 in ms:mainAddressCopyOverflow: the budget refuses 22–24 imports onmainand with this PR, but nothing logscopies ... past 64 MiBor the PR's eviction line.mainare not a regression of a merge: at the default budget Sky Garden lands at random in a fast (~0.7 s) or slow (~4.5 s) state on the same build, which explainsmain's spread here. Details on #7844.Tested and written by Claude (AI assistant) on a contributor's machine.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T09:30:03Z.
@EdouardSence thanks for the Linux/RADV run of ASTRO BOT (PPSA21567)'s Sky Garden, with #7844 alongside. That the cap never trips there, and that the two together give #7844's numbers, is in Tested and on the GPUs tested line now.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T01:39:13Z.
Review: CHANGES_REQUESTED
The full Build of this head merged onto current
mainfails on Windows only:agc_driver_graphics(run 40046736775, Linux green; bothagc_address_copy_cap*tests pass on Windows in that run). The output ends at the failed requirementAGC graphics: the unregistered heap copy range is write-watched, i.e.Require(!AgcDriver::GuestMemory::Watched(0x10000, 0x20000), ...)attests/BdaResources.cpp:3852, added in307bf8157a.Watchedanswers from the tracker's coverage (GuestMemory.cppcovers:coverage.Covers(...)), which earlier tests in the same process leave behind, so the precondition depends on test order and on whatmaincurrently registers. Please make it independent of global state: drop it,Unwatch(0x10000, 0x20000)before the check, or use a range no test can have watched.heapCopiesreasons) as they are.The rest of the diff is unchanged from the last review.