perf(libkernel): find guest allocations and direct mappings by address #4216
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4216"
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 Mouad-Scriptz-0 on 2026-10-12T01:39:35Z.
What
sceKernelVirtualQuery,sceKernelMunmap,sceKernelReleaseDirectMemoryand the reservation paths copied the whole allocation registry (or walked every direct mapping) under one lock on each call. Minecraft (PPSA17221) holds about 7,000 direct mappings and spent its world generation in these walks:free()→sceKernelVirtualQuery/sceKernelReleaseDirectMemorydominated every thread's stacks (eu-stack), and the render thread blocked on the registry lock behind them.GuestAllocationsLookup_nid_postfix(address, next)answers "which range holds this address" (and the find-next flag ofsceKernelVirtualQuery) from the registry's ordered map;sceKernelVirtualQueryuses it instead of acquiring a copy of all ranges.RangePatch(ranges to erase, ranges to insert) and applies it to the live map instead of rebuilding the map;allocationRemainsandCoversstart from the containing range.main's physical-span index (5b7cb8d1, consulted byWatchMappingfor shared backings) now also answersErasePhysMappings(sceKernelReleaseDirectMemory) andDirectMemoryViewsthrough oneMappingsSharingPhyshelper, so a release touches only the mappings over the released range; the index is kept on every platform for that instead of Linux only.guest_memorygains two cases:sceKernelVirtualQueryfinds the containing range, the split aftersceKernelMprotect, and the next range after a hole (flags1); releasing a physical range in the middle of 48 separately mapped pages plus an alias unmaps exactly those views.Behaviour is unchanged; only the lookups are. With #4118 and the flip event PR, Minecraft goes from a crawl in world generation to playable.
Tested
Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, Intel Arc Meteor Lake, Mesa 26.2.3), rebased ontomainc36fd0a0:guest_memory,guest_memory_pool_stats,guest_reallocalign,agc_write_tracking,agc_write_watch_coveragepass;tools/check_conventions.py --base origin/mainandgit diff --checkpass. Minecraft (PPSA17221) and Zombie Cure Lab (PPSA22623) run with it (Linux). Not tested on Windows.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 Pacuka on 2026-10-12T16:18:28Z.
Data point from Minecraft (PPSA17221) on Linux / AMD: CachyOS kernel 7.2.2, RX 6650 XT (RADV, Mesa 26.2.4), GCC 16.2.1, Release. Base: main
d592d54e1+ #4215 #4218 #454 #3633 #3604. Host import on.Without this PR the render thread spent most of its time in
HostImportFor. About 3% of the lookups found the registry generation changed, and thenGuestAllocationsAcquire_nid_postfixcopied all ~7,000 ranges. That took ~3.6 ms per lease and 111 s in total over a ~3 min run, about 125 us on average per in-place draw input. With this PR the same counter is 6 s over a comparable run. The in-game FPS counter went from ~2 to ~6 in a world.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T16:27:15Z.
Windows test of head
327e3b810merged onto currentmain(2a5eca11c, clean merge; built together with two other open PRs, so the run is for the combination): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build 0 errors,-j2.guest_memory(the test this PR changes) passes. The 25 tests matching^(guest_memory|guest_np_auth|windows_exceptions|guest_exception|guest_kernel)all pass.Not checked: that the test fails without the change, Linux, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T00:33:12Z.
Needs a rebase:
docs/dev/TechnicalDebt.mdwas split intodocs/dev/debt/, and that is the only conflict. Please drop the entry instead of moving it; it describes the index, not a gap.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T10:32:44Z.
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.
main)core/libs/prx/libc/src/GuestAllocations.cppL427-428core/libs/tests/GuestMemory.cppL2151core/libs/prx/libkernel/DirectMemory/DirectMemory.cppL349-351Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T11:09:51Z.
Rebased onto main
77b9f7270cand force-pushed. The only conflict wasdocs/dev/TechnicalDebt.md; the physical index entry is dropped rather than moved todocs/dev/debt/, since it describes the index, not a gap. No code changes; the commit keeps your authorship.guest_memory,guest_memory_pool_stats,guest_reallocalign,agc_write_tracking,agc_write_watch_coverageand theagc_/guest_ctest set pass on Linux. Merging.