perf(memory): restrict registry work to affected ranges #1324
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1324"
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 TibixDev on 2026-10-07T23:36:13Z.
Status after review
Awaiting a title profile showing registry cost.
Rechecked the motivation against current main. Host imports now have eager GPU-map observation and later span/lifetime fixes. The microbenchmark with empty host callbacks does not model those costs. The existing two-title review measured only −2.3% to +1.0%, within noise; no new isolated title gain has been established.
This pass removed the artificial downstream dependency: #1345, #1357, #1359 and #1366 now have standalone changes on main and do not require these targeted leases. A rebase of this optimization should follow a title/scene profile showing remaining full-registry work, with real callbacks included. No code push or renewed performance claim here.
What
Limit allocation lookup and mapping updates to the requested range. Host-import lookups lease one containing allocation when the registry is current. Protection and unmap changes prepare only affected fragments, then commit after the host operation succeeds.
Tested
Earlier branch-specific tests and measurements remain in the discussion. They have not been rerun on a redesigned current-main version of this PR. The review audit and shared NGS-assisted title exploration do not establish that this head is merge-ready. No full Linux/Windows platform CI was dispatched in this pass.
Checklist
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:26:16Z.
Could you measure main against main plus this PR alone, ideally frame time in a title? Perf PRs need before/after numbers for the change itself (#218); the 2,354 → 0.764 ms figure is a component run on the combined fork. The same goes for #1309, #1310, #1315, #1316, #1330 (against main plus #157), #1331, #1334 and #1335: their figures are component or combined-branch runs, or there are none.
Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-08T06:05:07Z.
Rebased on
e9846679with no production changes.Measured upstream
e9846679against the same revision plus this PR (1daa7f69). Fedora 44, GCC 16 Release, Ryzen 5 5600, CPU 3. Six processes per variant in ABBA × 3 order. Each process has one warmup and nine timed batches: 128 lookups or 64 mapping updates per batch. No game or build ran during timing.The same fixture calls
RegisteredReadableCovers,Mutation::Protect, andMutation::Unmapfollowed byAdd. It registers 1, 1,000, or 20,000 disjoint 64-byte ranges. Requests rotate through the registry. Host-operation callbacks are empty, so the figures measure registry work only. Both variants verify permissions, allocation release, and matching result counts.The one-range case has overlapping timing ranges; no gain is established there. The larger cases show that unrelated registry entries no longer dominate these operations. This does not measure Vulkan import creation or title frame time.
Graphics and guest-memory tests pass, including range boundaries, split mappings, permissions, unrelated leases, address reuse, and failed-host-operation rollback. Contribution checks pass. Windows was not tested. AI-assisted.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:01Z.
I measured this alone in two titles: frame time didn't change beyond run-to-run noise (-2.3 % to +1.0 % across three scenes in one, none in the other). Which title does it speed up?
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T16:07:08Z.
Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head
1daa7f69, merged ontomaind70b8998together with #2039, #2193 and #2247.agc_driver_graphics, which includes this PR'sGuestAllocations.cppchecks, passes. It didn't report skipping a case.No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:05:14Z.
Review: CHANGES_REQUESTED
Checked on current
main: build + ctest green locally (308/308 in the touched components); the new tests need the new API, and I found no logic problems in the registry changes (iterator ranges,Commit(),lastcomputation inUnmap, boundary cases).mainvsmain+ this PR alone shows a measurable difference (frame time or the time spent in these functions in a profile).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:52:55Z.
Review: CHANGES_REQUESTED
Still open after the last review:
mainvsmain+ this PR shows a measurable difference (frame time, or time spent in these functions in a profile).main; it needs a rebase (and a rerun ofguest_allocations/agc_driver_graphics) once the benefit is shown.Without a measurable gain in a real title this adds complexity to the registry for no benefit; it can be reopened when a case shows up.
Imported from boykopovar/AnyPS5. Originally posted by TibixDev on 2026-10-12T04:52:06Z.
Review-pass update:
Rechecked the motivation against current main. Host imports now have eager GPU-map observation and later span/lifetime fixes. The microbenchmark with empty host callbacks does not model those costs. The existing two-title review measured only −2.3% to +1.0%, within noise; no new isolated title gain has been established.
This pass removed the artificial downstream dependency: #1345, #1357, #1359 and #1366 now have standalone changes on main and do not require these targeted leases. A rebase of this optimization should follow a title/scene profile showing remaining full-registry work, with real callbacks included. No code push or renewed performance claim here.
I have updated the PR description to match this status. The PR remains open; the outstanding review requirements are not being marked resolved. AI-assisted audit.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-12T11:54:13Z.
Here is a title profile with registry cost, which this PR was waiting for.
Epic Mickey: Rebrushed (PPSA15657, Unreal Engine 4), first level, on Linux with an RX 7600 (RADV, Mesa 25.2.8, kernel 7.0). Base: main
e7c70a2df+ #3763, #2904, #425 and #4363, which it needs to reach the level. The level runs at about 3 FPS with the GPU submission thread at 81% CPU.LBR call stacks of that thread over 40 s:
GuestAllocationsAcquireplus freeing the lease is about 37% of the thread.GuestBufferMemory::UploadFinishis about 23%: regions that no registered run covers, so nothing is imported.HostImportFor(fromInPlaceDrawInput) is about 13%: mostly runs instate.failed, after 38 imports failed atvkAllocateMemory(-13).Counters per 5 s: about 2,900 full leases from
UploadFinishand 1,900 fromHostImportFor. The registry generation did not change once, so none of them was a refresh.I tried a narrow version of the host-import part only: a lease of the readable ranges adjacent to the address within the import window, which is what
importRunreads. When that run is uncovered, or failed or misaligned with no overlapping import, the full lease is skipped. The level goes from about 3.0 to 4.6 FPS, the thread drops to 33%, andGuestAllocationsAcquireleaves the profile. Full ctest is 949/949.Would you rather rebase this PR's host-import part with these numbers, or should I open the narrow version and link it here? I don't want to duplicate your work.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T17:26:11Z.
Issue #4634 now provides the requested title profile for Cyberpunk 2077 (PPSA04029). On main
d592d54eafter #4321, the title has about 35,000 live 64 KiB mappings and hits the 139 s EngineWatchdog with zero dispatches. Samples showDoMtypeprotect/DoMunmapthreads waiting inGuestAllocationsBegin, a lock holder in the range-tree operations underGuestAllocationsProtect, and the main thread later inGuestAllocationsRequireAvailable. The issue also identifies the full-map copy inreplaceRange/Protectand begin-based walks inRequireAvailable,OverlapsandAcquire; with #4216, cold runs still trip while warm reaches later shader work. This is title-profile evidence of registry cost, not a measured post-fix performance claim: https://github.com/boykopovar/AnyPS5/issues/4634Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T17:27:03Z.
Your Epic Mickey profile and isolated 3.0 → 4.6 FPS result are the direct title-level evidence this PR was waiting for. The Cyberpunk profile I linked separately shows another registry bottleneck, but does not establish a post-fix speedup. I would keep this as one focused, current-main host-import optimization rather than open a second PR that overlaps #1324; the broader registry work still needs its own measured benefit. If you publish the exact narrow branch or commit, it can be reviewed against this PR’s head and the current base without duplicating it.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-12T23:26:29Z.
Thanks. Here is the narrow change as a branch, without a separate PR:
perf/import-lease-around-main, one commit,e9ffb2eda, on main90c683946.GuestAllocationsAcquireAroundleases only the readable ranges next to the one holding an address, within the import window. That is allimportRunreads.HostImportForandUploadFinishuse it to decide that an import is refused before taking the full registry lease: the run is uncovered, or it is misaligned or failed and overlaps no import.GuestBufferMemory.cpp+20/-1,GuestAllocations.hpp/.cpp+21, and a test incore/libs/tests/GuestMemory.cpp(CheckAcquireAroundFollowsTheRun) +32.e9ffb2edaon Linux with an RX 7600 (RADV, Mesa 25.2.8).e7c70a2df. I haven't measured it again on this base.It touches the same lookups as this PR, so it can sit on top of it or replace part of it, whichever you prefer. I'm glad to rebase it onto this PR's head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T07:27:32Z.
Issue #4634 adds a Cyberpunk 2077 title trace relevant to this PR: with about 35,000 live 64 KiB mappings, sampled
sceKernelBatchMap2threads spend time inGuestAllocationsRequireAvailable/GuestAllocationsOverlapstree walks,GuestAllocationsAcquirerange copying, andGuestAllocationsProtectrange replacement. The report is stack-sample evidence, not an isolated per-function profile or measured benefit, so I am not treating it as satisfying the current profile gate. It may help target the next profiling pass: https://github.com/boykopovar/AnyPS5/issues/4634.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:16:42Z.
@MarcZX100 your Cyberpunk 2077 trace in #4634 (about 35,000 live mappings, time in the registry tree walks) is the title need this PR was missing. It conflicts with main now and adriadam10's two reviews are still open; would you carry it (rebase plus his points), with TibixDev credited?
Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-14T17:12:51Z.
Gap table for this PR against current
main(e34c47921), since @oneandonlydean asked @MarcZX100 to carry it. The branch conflicts withmainin all four files, and most of its registry half has already landed through #4216:maine34c47921Coversstarts atupper_boundreplaceRangestops copying the whole map;Protect/Unmapcommit only the replaced fragmentsRangePatch/applyPatch(L433-L472)Unmap'slastcheck scans only the allocationallocationRemains(L474-L485)RequireAvailablestarts atupper_boundbegin()(L358-L369)Overlaps(not in this PR)begin()(L371-L379)GuestAllocationsAcquireRangeand its use inHostImportFor,RegisteredReadableCoversandUploadFinishmainmoved under it. #4698 shares one lease snapshot until the registry changes (L534-L543), #4216 addedGuestAllocationsLookup, andGuestBufferMemory.cpphas changed a lot. @johnmaia'sGuestAllocationsAcquireAroundis the measured version of this part.That leaves two independent changes, each with its own title:
RequireAvailableandOverlapsstart at the range before the address, asCoversandRequireUnpinnedalready do.DoMapDirectruns both, under the registry lock, for a fixed mapping outside registered ranges (ReplaceFixedOverlap).DoMunmaprunsOverlapsfor every unmap (L1088). With #4216 applied, @snoozedDev's samples in #4634 still show these two walks underDoMapDirect(Cyberpunk 2077, PPSA04029). No new export, and no lease or pin change.AcquireAround(Epic Mickey: Rebrushed, PPSA15657, 3.0 to 4.6 FPS, measured one7c70a2df). His branch is now at8ba2d5b9a, with the same diffstat as thee9ffb2edahe posted, and againste34c47921it conflicts only inGuestBufferMemory.cpp. It changes which rangesHostImportForandUploadFinishlease, andRequireUnpinnedwaits on leases, so it needs a separate review from (a).@MarcZX100 @johnmaia, who takes which part? johnmaia's branch already is (b). If neither of you wants (a), I can open it as its own PR crediting @TibixDev, since the
RequireAvailablehunk is his. It is one commit ona453108cfthat merges cleanly intoe34c47921: nikowolf123/AnyPS5help/S3-registry-walks(b3f7b2c3c). It adds two tests toguest_memory:mainand passes with (a). With 32,768 ranges below, the cost is 32-39 times the cost with 1,024 onmainand 2.5-3.0 times with (a); the limit is 8.Component numbers only,
mainagainst (a):mainsceKernelMapDirectMemorycalls in address order, total (2 runs)sceKernelMunmapof all 35,000 in random order, totalOverlaps+RequireAvailablejust above 35,000 registered ranges, registry alone (median of 6)The registry-alone row on native Windows 11 (WinLibs GCC 15.2, pinned to logical CPUs 8-11) is 338 µs against 0.05 µs. The mapping rows come from a throwaway mode of
guest_memory_teststhat is not in the commit. It maps CPU-only memory without the AGC driver, so it leaves out the GPU-map observer.None of this shows that (a) gets Cyberpunk past the watchdog. Two full-registry copies that #4634 sampled are in neither part:
GuestAllocationsAcquirein the pin waiterWaitForLeasesAndImports(GuestBufferMemory.cpp#L1890).GuestAllocationsAcquireinImportMappedRanges(L2336-L2341).GuestAllocationsEndreaches it after every GPU mapping while host imports are on.Every mutation drops #4698's shared snapshot, so neither copy is avoided while the title keeps mapping. The #4634 runs were also on
d592d54e, without #4698 and with #4216 only cherry-picked. @snoozedDev, if you have time, could you do cold runs of currentmainand ofmain+ (a), and post the watchdog time or how far each gets? That would be the title number this PR's reviews ask for.AI-assisted: written with Claude Code; I checked this PR's diff hunk by hunk against
maine34c47921, the history ofGuestAllocations.cpp(#4216, #4698), johnmaia's branch, the callers inDirectMemory.cppandGuestBufferMemory.cpp, and #4634. I rangit merge-treeof this PR, of johnmaia's branch and of (a) againste34c47921. On a Linux (WSL) build I ranguest_memorywithmain'sGuestAllocations.cpp, where the new scaling check fails, and with (a), where it passes 20 of 20 repeats, plus a randomized check of both walks against a brute-force overlap model (about 1.2 million queries each onmainand on (a), no mismatch). I also ran the 908guest_*/agc_*ctests with (a) on lavapipe (0 failed, 40 skipped),tools/check_conventions.py, and the benchmarks above, Linux and native Windows. I did not run any title.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T18:01:52Z.
@nikowolf123 yes, please open (a) as its own PR crediting @TibixDev; (b) stays with @johnmaia's branch. Once both are open this one can close.
Imported from boykopovar/AnyPS5. Originally posted by snoozedDev on 2026-10-14T22:44:15Z.
@nikowolf123 Cyberpunk 2077 (PPSA04029), Linux, RTX 3090, NVIDIA 610.57.04, three cold runs and one warm run each on
main799982fac(with #4216 and #4698) and onmain+ (a) (b3f7b2c3c cherry-picked, no conflict;guest_memorypasses on Linux):mainmain+ (a)"watchdog" is
!!! EngineWatchdog timeout!; "first presentation" is the title's next stop onmain, a storage-image format refusal (#6119), which both trees reach with the same shader and exception text. Three runs per tree do not separate 2 of 3 from 1 of 3. On baremainthesceKernelBatchMap2threads were sampled inRequireAvailable, inOverlaps(fromReplaceFixedOverlapand fromDoMunmap) and inAcquire(fromWaitForLeasesAndImportsand fromImportMappedRanges); with (a) only in the twoAcquirecopies, and the one watchdog trip with (a) had no registry frame in its 150 s sample. Samples and run details in #4634.AI-assisted: yes (Claude Code, Claude Fable 5.1), operating under my supervision; I am accountable for this comment and will respond to review.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:05:27Z.
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/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/include/GuestAllocations.hppcore/libs/prx/libc/src/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/include/GuestAllocations.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libc/src/GuestAllocations.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppImported from boykopovar/AnyPS5. Originally posted by whamre on 2026-10-20T13:15:43Z.
A title profile with registry cost, as asked for in the status above. SILENT HILL: The Short Message (PPSA10112), Windows 11 (26300), RTX 2080 SUPER, NVIDIA 616.92, WinLibs GCC 15.2.0, Release,
main1edbe4b5e+ #8265.While the title loads its first scene, it changes the registry 1,800–2,800 times per 10 s (a local counter on
GuestAllocationsEnd; mostly 64 KiB mappings). Every change moves the generation, so the next address-based build rebuilds the cached address space. Each rebuild callsrefreshImports, which walks every import, thenimportAllocationonce per import. A local timer around both, per rebuild, over one run (10 s intervals):importAllocationcallsrefreshImportsSo the work per change grows with the whole registry, not with what changed. On
main43a2abaf7one run reached 62 ms per rebuild ([address] … imports pass 61722) at 94 rebuilds per 10 s, and the title then sits in loading until Unreal's 120 s render-thread check ends it. That happens in 2 of 3 runs on currentmain.As a local experiment (not a PR), I limited
refreshImportsto imports whose 8 MiB window holds a range that changed between two leases, and let a build reuse the import it took for an unchanged range. That brings the import part from about 11–14 ms to about 6 ms per rebuild over 16 runs. It doesn't end the stall, though: what's left is the per-range walk of the rebuild itself, at 300–500 rebuilds per 10 s. These callbacks and walks are real-title registry work of the kind this PR targets, but in the driver's address-space path rather than in lookup/protect/unmap. I can run a rebased head on this title.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T17:56:56Z.
Thanks for this. Its registry half has landed via #4216, and the remaining directory walk is in #6321, so this one is covered and now conflicts with main. Closing; thank you for getting it started.
Pull request closed