fix(agc): hash the pages of an import window instead of copying them #7981
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7981"
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 fisherjoey on 2026-10-19T16:46:46Z.
What
ImportWatchedkeeps a copy of every non-zero page of the range it imports, so that afterwards it can tell a page the write watch reported from a page that still holds its old bytes (#3874, #5698). The copy is as big as the range. A first import of a 0.5 to 3 GiB guest heap holds that much host memory while the import runs (#7980).With this change the window keeps a 64-bit digest of each 4 KiB page (
HashPage, four xxHash64 lanes merged the way xxHash64 merges them) andWindowCopy::Holdscompares digests rather than bytes. That is 8 bytes per page, 1/512 of the range: a 3 GiB import holds 6 MiB rather than 3 GiB.Fixes #7980
ZeroPageandWindowCopy::Zeroare removed.Tested
CheckImportWindowFootprintinagc_write_tracking(glibc only, since it readsmallinfo2). It imports a 64 MiB watched range, all non-zero, and requires the heap growth seen inside the import to stay at or below 1 MiB. On main it fails withan import window over 64 MiB held 64 MiB of host memory during the import. With this change it passes. It then re-imports the range, writes the same byte to one page and a new byte to another, and checks that the first page reads as unchanged and the second as written.agc_write_tracking,agc_import_watchand the other 50 tests run byagc_write_tracking_testsandagc_driver_recorder_tests(52 in all) on this branch, based on maindbac9fa15, Linux, Release, GCC 16. On lavapipe (Mesa llvmpipe): 47 pass and 5 are skipped for missing capabilities. On an NVIDIA GeForce RTX 5070 Ti (driver 595.91.07): all 52 pass.93e54ceddplus #6280, a cherry-pick of #6567, a local texture-snapshot reuse patch, a local stencil-export workaround, and a local job-worker idle patch run withAPS5_JOB_IDLE_SLEEP=1, which loads faster and makes the load burst sharper. I compared the same set with and without this commit and sampled host memory every 5 to 10 s:ImportWatchedallocation. Another had a 2.9 GiB anonymous block appear in the 10 s before the host OOM killer stopped it.676269473plus #6280, #6926, #7844 and the stencil workaround, without the job-idle patch), with only this driver swapped in: the load started, no crash, full 900 s. The largest 10 s host jump during the load was +1.86 GB, against +1.69 and +2.08 GB without the change. At main's normal load speed Demon's Souls does not show the burst, so this shows the change is safe there but not a measurable benefit.Related
ImportWatched's unwatch and save paths near these lines (#6308's unwatch hook edits the same fallback block). None of them replaces the copy, so they don't overlap with this, but whichever lands second may have a textual conflict. I'll rebase if needed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); this change adds no stubs.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T17:01:32Z.
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.
core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/WriteTracking.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T18:27:41Z.
One overlap detail for the integration note: the overlap check also flags open #6308 in
GuestMemory.cpp. Its unwatch-hook change is separate from the digest change, so I do not see duplicate behavior in the diff, but both edit theImportWatchedfallback and may need a textual rebase or careful combination. Could you include #6308 in the related/rebase notes?Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T18:41:57Z.
#6308 was already in the related notes, but I've made it clearer that its unwatch hook edits the same
ImportWatchedfallback block, so a rebase there needs both changes combined by hand.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T19:29:48Z.
A run on a current-main base, for honesty about where this matters.
Base:
main676269473plus #6280, #6926, #7844 and a local stencil-export workaround (not in any PR), with only this PR's driver swapped in. Demon's Souls, RTX 5070 Ti, 900 s, without our local job-idle patch. The level load started, no crash, and the run went the full 900 s.The largest 10 s host memory jump during the level load was +1.86 GB with this PR, against +1.69 GB and +2.08 GB in two runs of the same base without it. So at main's normal load speed, Demon's Souls does not show the multi-GB burst, and this run shows the change is safe there but not a measurable benefit. The +3 to +19 GB jumps in the description come from the faster loads with the job-idle patch. My guess is that several of the 0.5 to 3 GiB imports overlap there, but I have not measured that. The copy itself is still on main (the footprint test fails there with "held 64 MiB"), so a title or machine that loads faster can still hit it.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T00:30:27Z.
Update: I discarded the first tracker-level approach because it conflicted with #6308 and #7505. The current local two-commit candidate instead filters coalesced runs in
importRunwhen a run crosses existing write-watch gaps, leavingImportWatchedsemantics unchanged; it has a Windows fixture for the reported layout. That now overlaps theimportRunrefactor in #6951, so I asked there about coordination. Neither version has been pushed or opened, and this alternative still needs a write-watch-capable Windows run.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T07:08:17Z.
Thanks for your patience on this. #8172 (the fix for the #8103 regression) has merged, and it also rewrites
ImportWatched's window copy inGuestMemory.cpp, so this branch now conflicts there.The two changes fit together: #8172 splits a partly watched range into runs of covered 64 KiB blocks that stay watched, and your per-page hashing can apply within those spans. Could you rebase onto current main and redo your change on top of #8172's version of that code? We'll review the rebase and run CI on it as soon as it's up.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-20T08:14:08Z.
Rebase handoff — rebased onto current
main(3fd1cc393, authorship unchanged). This PR andmainevolved the same import-window path in different directions (main's71fd1c0e5copies only nonzero pages with 4-byte slots; you replace the copies with 8-byte xxHash64 page digests), so the resolution unites them:main's span-based flow is kept — partial coverage (an import over an unwatched block) still builds covered spans, drops unchanged ones viaerase_if, and unwatches per span — but each page now records yourHashPagedigest instead of a slot plus a copied page. Your hash-basedWindowCopyandHashPage(which merged cleanly) drive the re-walk.main'sCheckImportWindowOverUnwatchedBlocktest (the spans path) and yourCheckImportWindowFootprinttest are both kept and both pass.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds;agc_write_trackingpasses; 1673/1676 — green apart from the three knownmainfailures (#7584 BDA, #7784 guest-memory, tessellation), none from this PR; conventions pass.To pick it up:
Head is
0460baa6f.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-20T15:11:58Z.
Rebased onto current main (
75787d2f6), on top of #8172. New head is 4d893a936.I used @blawesom's resolution as is. Thanks for doing the merge. It keeps #8172's span flow (covered 64 KiB runs, the
erase_if, unwatching per span), and each page in a span now records itsHashPagedigest in place of a slot and a copied page. Main hasn't touchedGuestMemory.cpporWriteTracking.cppsince their base3fd1cc393, so the commit moved over unchanged.Built on Linux and
check_conventions.py --base origin/mainpasses.agc_write_tracking(which runsCheckImportWindowFootprintandCheckImportWindowOverUnwatchedBlock) andagc_import_watchpass on lavapipe and on an RTX 5070 Ti.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T18:06:24Z.
Checked the diff against main (on top of #8172's span flow):
HashPagedigests replace the page copies,Holdscompares digests,ZeroPage/WindowCopy::Zerohave no remaining uses.CheckImportWindowFootprintpins a ≤ 1 MiB heap growth over a 64 MiB import (main copies the range, so it fails there) and the unchanged/written page decision; the full Build runs the test; merged.