Repository navigation
fix(agc): put a retired import's unchanged ranges back in the write watch - #8926
Conversation
|
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.
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.
|
…atch On Windows a host import under 1 MiB leaves the write watch when it is made, and comes back only when its deferred settle read completes. retireImport drops the pending settle and never restores the watch, so an import retired before it settled left its range outside the write watch for good. Once no import fit the budget, an address-based build could neither import such a range nor heap mirror it (CollectWrites returned 0), and copied it. Since aligned block imports (boykopovar#6457), this happens to every 64 KiB piece a title maps one at a time: the piece is imported by the map, and when its neighbour is registered its run grows into a larger aligned block, so refreshImports retires the piece's import ("the range was mapped again", though the range is unchanged). Resident Evil Village (PPSA01556) on main 6696def aborted in its intro at 0:43 to 6:37 with "an address-based build copies 185 MiB of 2960 registered ranges, past 64 MiB (APS5_ADDRESS_COPY_MAX_MIB); the largest: 0x20c0c20000+ 0x10000 (0.1 MiB committed, outside the write-watched arena) ...". An import trace showed each copied page imported by the map, retired when its run grew, and never imported or watched again. refreshImports and the budget eviction now note the ranges of each unwatched import they retire that are still registered as the same range, and rewatch them once the import is gone: as a settled import does, except where another unwatched import or a live storage texture still covers them. Rewatch stamps the range as written, so the next build reads it in full. Ranges the guest mapped again or released keep the existing path. Tested: agc_driver_graphics gains retiredImportWatchTests (Windows): a 64 KiB piece imported on its own, then its neighbour registered and the budget cut below one piece. The piece must be back in the write watch and both pieces heap mirrored. Without the fix the piece stays unwatched and is copied. Co-authored-by: keravyn-ops <342686842+keravyn-ops@users.noreply.github.com>
acc7b17 to
a356b6a
Compare
|
@EagleBearerYS #9402 overlaps this PR in std::vector<std::pair<std::uint64_t, std::uint64_t>> unwatched;
const auto check = [&](std::map<std::uint64_t, HostImport>::iterator it) {
if (sameRange(it->second, lease, budget)) {
if (it->second.unwatched) GuestMemory::Unwatch(it->first, it->second.bytes);
return std::next(it);
}
...
const auto next = std::next(it);
noteRetiredUnwatched(unwatched, it->second, lease);
retireImport(context.device, state, it, lease);
return next;
};
if (whole) {
...
} else {
...
}
rewatchRetired(state, std::move(unwatched));An import the incremental walk doesn't reach is not retired, so it has nothing to put back in the write watch. Your |
|
@janzezno thanks, that's right. This PR adds exactly those two calls in |
What
On main, Resident Evil Village (PPSA01556) aborts in its intro, between 0:43 and 6:37, with:
on main 6696def. The regression is from our #6457, "import adjacent registered ranges as aligned power-of-two blocks". It was merged on 2026-10-19. Boots of main with #6730, then with #6730 and #6479 reverted still abort. Main with all three of #6457, #6479 and #6730 reverted doesn't.
Cause:
retireImportdrops the pending settle and never restores the watch. An import retired before it settles therefore leaves its range outside the write watch for good.CollectWritesreturns 0, soacquireMirrorrefuses it. The build copies it, and enough of those copies reachAPS5_ADDRESS_COPY_MAX_MIB.refreshImportsretires the piece's import, before it has settled. The trace prints that as "the range was mapped again", although the range is unchanged.APS5_TRACE_HOST_IMPORT=1shows each page the FATAL lists, e.g. 0x2098900000+0x10000, as "ok … by map", then "retired: the range was mapped again", and never imported or watched again.The change:
refreshImportsand the budget eviction (retireLeastRecent) note its ranges that are still registered as the same range. Once the import is gone, those ranges go back into the write watch, as a settled import's do (GuestMemory::Rewatch).Rewatchstamps the range as written, so the next build reads it in full.Linux: imports stay watched there unless the import probe or
APS5_WRITE_WATCH_IMPORTS=unwatchsays otherwise, andRewatchis Windows-only. So this changes nothing on Linux, and the new case is Windows-only.Cost, measured on GitHub's Windows runner with a mock device (run, bench
exp/rewatch-cost4ef027a, which is acc7b17, the same code as this PR's head a356b6a, plus a test-only benchmark commit; one run withmain's code and three with this PR). The bench replays a Resident Evil Village-sized load: 2,077 refreshes that retire 5,765 unwatched imports (2,278 MiB), with the CPU storing to every 4th page of each imported piece.main, which leaves those ranges unwatched. The whole workload takes 13.1 s, against 5.2 s.Rewatch. That is being looked at as a separate follow-up.Overlap with open PRs on the same path. Each was checked with
git merge-treeagainst this head.Rewatch. This PR covers the two existing retirements, when the run changes and on eviction.mainin the same two files with or without this PR.RetireIdleImportscan userewatchRetiredand get the same skips.refreshImportschange removes the trimmed-import reattach and keeps the retire loop this PR adds to. The two merge cleanly.refreshImportsit only clears its new set where the device changes, not in the retire loop this PR adds to. The two merge cleanly.refreshImports' loop over every import with achecklambda, which a full walk and a new incremental walk (only the imports a registry change can reach) both call.checkis the only place either walk retires an import, so this PR'snoteRetiredUnwatchedgoes there before the retire, andrewatchRetiredafter the walk (janzezno's composition). An import the incremental walk doesn't reach isn't retired, so it has nothing to put back.retireLeastRecentisn't touched by perf(agc): re-check only the host imports a registry change can reach #9402. The two conflict textually inGuestBufferMemory.cpp; whichever merges second rebases into that shape, agreed in this thread.refreshImports' retirement nor the budget eviction. Each conflicts withmainin the same files with or without this PR.Tested
agc_driver_graphics, newretiredImportWatchTests(Windows):GuestBufferMemory.cpp: "AGC graphics: a 64 KiB piece whose import retired when its run grew into a block stayed outside the write watch", in 3 of 3 runs.GitHub's runners (run), targeted build of the graphics tests:
agc_driver_graphicsand theagc_heap_mirror_*tests, 27 tests. The libc and libkernel suites pass.mainstops attests/execution/ImageArrayWindowPastLayerLimit.cpp:33("requested alignment '65536' exceeds object file maximum 8192", MinGW), so the runs build the tested targets only.Resident Evil Village (PPSA01556) on Windows (RTX 3070), on main 1ff5c8a plus 63d5414 (this commit's code; the head differs only in its test), warm shader cache,
APS5_TRACE_HOST_IMPORT=1: no copy-cap FATAL and no "outside the write-watched arena" copy in 43 minutes.SILENT HILL: Townfall (PPSA33286), by @keravyn-ops (comment), with perf(agc): import a range mapped again on first use instead of at map #8622 (not ours).
-nothreadtimeout.APS5_PROFILE_DRAW=1,APS5_ADDRESS_COPY_MAX_MIB=8192, the default import budget (1056 MiB) unless stated, warm shader cache, no input, 360 s per run, one run per row.maincecb540, with perf(agc): import a range mapped again on first use instead of at map #8622 at bf66eec and this PR at acc7b17 (the same code as a356b6a), each merged onto thatmain. GPU clocks weren't reported.mainand 1.17–1.32 with perf(agc): import a range mapped again on first use instead of at map #8622, with 6.19 M and 5.53 M CPU-copy operations. The rows with this PR:unwatched heapsmain+ this PRmain+ perf(agc): import a range mapped again on first use instead of at map #8622 + this PRmain+ perf(agc): import a range mapped again on first use instead of at map #8622 + this PR,APS5_HOST_IMPORT_MIB=1536main+ this PR row "is a single run that hit the intermittent Palworld (PPSA23126): abort at compute shader 0x15c1486e00, "storing storage image results pending over memory outside the write watch without the guest bytes saved before them is not implemented" #7017 abort before the first frame, so it says nothing about fix(agc): put a retired import's unchanged ranges back in the write watch #8926 alone".APS5_HOST_IMPORT_MIB=2600runs on AGC: on a Radeon 780M APU (Windows) the 3 GiB host heap is exhausted by heap mirrors and imports while the device-local heap stays half empty #7047 did: avkAllocateMemoryof a 256 MiB device buffer fails (initialResult=-2), with heap 1 at 6221 of 2949 MiB.Checklist
main1ff5c8a, and merges cleanly withmain0aa55ef; no other open PR implements the same functions (see Overlap)NotImplemented_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)