perf(libc): edit the guest allocation registry in place #2668
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2668"
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 ps54all on 2026-10-10T10:30:37Z.
What
Every
protect,unmapand fixed remap of a guest allocation went throughreplaceRange, which copied the whole registered-range map (auto replacement = registry().ranges;), edited the copy and swapped it in.GuestAllocationsCovers,OverlapsandRequireAvailablewalked the map from its first entry. All of this runs under the registry mutex that every guest map call takes, so each call costs O(registered ranges) and serialises the mapping threads. Titles that remap in small steps (Unreal's binned allocator) register tens of thousands of ranges.replaceRangenow returns aRangeEdit(keys to erase, ranges to add) for the affected span only.applyEditapplies it after the caller'sapplysucceeded, so a throwingapplystill leaves the registry untouched, as before.Unmapdecides whether a piece is the allocation's last one withallocationRemainsAfter, which looks only inside the allocation's extent, instead of scanning the whole copied map.Covers,OverlapsandRequireAvailablestart at the first entry that can overlap (upper_bound, one step back) instead of the first entry.Tested
Windows 11, MinGW-w64 GCC 15.2.0, Release,
BUILD_TESTING=ON, onmaina29ef592.New
guest_memorycaseCheckRegistryEditsBetweenManyRanges: two adjacent allocations, one split into 32 ranges by protecting every other page; a protect whoseapplythrows leaves all 32 ranges as they were; an unmap across both allocations reportslast == falsefor both pieces, and unmapping the rest reportslast == truefor each. The case passes on unmodifiedmainas well, which is the point: it pins the behaviour the rewrite must keep.Cost per call with 20,000 registered one-page ranges (scratch benchmark, not committed: 4,000 protects at spread positions, then 20,000 unmaps; three runs each, all within 2%):
mainAn earlier measurement on Split Fiction (PPSA08560, Unreal Engine 5) on a local integration branch with the same change: map calls taking 5 ms or more in the first 90 s went from 398 to 77 (scratch timer around
DoMapDirect). Not re-measured on this branch.ctest: all 326
agc_/video_out/guest_videotests passed (run on6675e60b, before the rebase); ona29ef592, of the other 378, three fail and fail the same way onmainon this machine:guest_memoryat the existing read-onlysceKernelPreadcheck (after the new case, which passes),guest_file_vector(/dev/urandomreads) andguest_sce_net(DNS timeout).tools/check_conventions.py --base origin/mainandtools/check_test_registration.pypass.Not tested: Linux, macOS.
Overlap: #1961 (open) also edits
replaceRangeandUnmap, to carry its GPU-mapping note. A trial merge of #1961 onto this branch mergesGuestAllocations.cppcleanly; onlycore/libs/tests/GuestMemory.cppconflicts, where both add test functions next to each other. Whichever lands second needs that one-line rebase; happy to do it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T10:30:46Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Pull request closed