AGC: ImportWatched copies every non-zero page of the range, so a 3 GiB first import holds 3 GiB of host memory #7980
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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:41Z.
Problem
ImportWatched(core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp) copies every non-zero page of the range it imports into a host vector, and holds that copy for the whole import. When a title imports a large guest heap for the first time, host memory goes up by the size of that heap.Demon's Souls (PPSA01341 v1.07) does its first imports when a level loads, and they are 0.5 to 3 GiB each. On Linux (RTX 5070 Ti, glibc) that showed up as host memory bursts right at the load:
GuestMemory::ImportWatched <- importRunAt <- importAllocation <- GuestBufferMemory::AcquireRegistered <- prepareAddressBindings.Mechanism
From #3874 the import window compares pages after the import, so a page the write watch reports during the import can be told apart from one that still holds its bytes (a write of the same bytes, or the import's own touch). #5698 made it copy only the non-zero pages. On main (
dbac9fa15):ImportWatched, GuestMemory.cpp:1525-1536: when the range is covered and stays watched, every page is checked againstZeroPage, and every non-zero page is appended tosavedwithsaved.insert(...).savediskept * 4096bytes.WindowCopy::Holds, GuestMemory.cpp:791-802: after the import, each page the watch reports ismemcmp'd against its saved copy, or againstZeroPage.The window only needs to know, per page, whether the bytes are the same as before, and it keeps a full copy of the range to answer that. A heap the title has already filled, which is the normal case for a large first import, is almost all non-zero pages, and the zero-page filter from #5698 saves very little there.
Expected
An import should hold a small fraction of the range, not a copy of it. A 64-bit digest per 4 KiB page gives the same decision for each page (short of a 64-bit collision) at 1/512 of the range's size: 6 MiB for a 3 GiB import instead of 3 GiB. A fix with a failing-first test follows in a PR.
AI-assisted: yes