Skip to content

fix(agc): put a retired import's unchanged ranges back in the write watch - #8926

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
EagleBearerYS:fix/agc-retired-import-rewatch
Oct 26, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
EagleBearerYS:fix/agc-retired-import-rewatch

Conversation

@EagleBearerYS

@EagleBearerYS EagleBearerYS commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

On main, Resident Evil Village (PPSA01556) aborts in its intro, between 0:43 and 6:37, with:

FATAL: 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) 0x20c0430000+0x10000 (0.1 MiB committed, outside the write-watched arena) ...

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:

The change:

  • When an unwatched import retires, refreshImports and 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).
  • They're skipped 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.
  • Imports made to replace the retired ones (the larger block) aren't changed.

Linux: imports stay watched there unless the import probe or APS5_WRITE_WATCH_IMPORTS=unwatch says otherwise, and Rewatch is 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-cost 4ef027a, which is acc7b17, the same code as this PR's head a356b6a, plus a test-only benchmark commit; one run with main'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.

  • Refresh work: about 2.8 s in all with this PR (2.78 to 2.80 s, a median of 620 µs per refresh), against 9.3 ms on main, which leaves those ranges unwatched. The whole workload takes 13.1 s, against 5.2 s.
  • Per-build copies: a repeat build over a retired 64 KiB piece takes 9 µs instead of 367 µs (medians), since the piece is watched again. The first build after the retirement takes about 470 µs either way.
  • Collects: a 32 MiB collect right after a refresh that put ranges back takes about 150 µs, against 0.3 µs.
  • A refresh that retires one piece takes about 440 µs (medians of 445 to 451 µs), more than expected for one 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-tree against this head.

Tested

Checklist

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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 9402 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp L2088-2091, L2101-2107

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 2434 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 4449 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 5372 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6548 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6918 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 7201 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 7457 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7514 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 8896 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9176 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9287 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9289 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 9852 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp
PR 10194 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/BdaResources.cpp

…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>
@janzezno

Copy link
Copy Markdown
Contributor

@EagleBearerYS #9402 overlaps this PR in refreshImports: it replaces the loop over every import with a check lambda, which a full walk and a new incremental walk (only the imports a registry change can reach) both call. check is the only place either walk retires an import, so your two additions go in one place each:

    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 retireLeastRecent change doesn't touch #9402. Neither PR depends on the other, so I'd propose no Depends on in either and that the one that merges second rebases into this shape. If #8926 lands first, I'll rebase #9402. Is that OK with you?

@EagleBearerYS

Copy link
Copy Markdown
Contributor Author

@janzezno thanks, that's right. This PR adds exactly those two calls in refreshImports: noteRetiredUnwatched before the retire, and rewatchRetired after the walk. In your check lambda each gets one place, and an import the incremental walk doesn't reach isn't retired, so there's nothing to put back for it. Agreed: no Depends on either way, and whichever merges second rebases into that shape. It's in this PR's Overlap now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants