Repository navigation
perf(libkernel): find guest allocations and direct mappings by address - #4216
Conversation
f28e12a to
327e3b8
Compare
|
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 Without this PR the render thread spent most of its time in |
|
Windows test of head
Not checked: that the test fails without the change, Linux, a title run. AI-assisted (Claude Code). |
|
Needs a rebase: |
sceKernelVirtualQuery, sceKernelMunmap, sceKernelReleaseDirectMemory and the reservation paths walked a copy of the whole allocation registry or of every direct mapping under one lock on each call. The registry now answers lookups from its ordered map, applies range replacements as patches instead of rebuilding the map, and direct mappings carry an index by physical offset so a release finds only the mappings it covers. Minecraft (PPSA17221) holds about 7,000 direct mappings and spent its world generation in these walks. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
327e3b8 to
df3d027
Compare
|
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.
|
|
Rebased onto main 77b9f72 and force-pushed. The only conflict was |
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 (5b7cb8d, 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 ontomainc36fd0a: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