libkernel: every direct-memory map/remap walks the phys range page-by-page — quadratic on sliding-window remap patterns #10521
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 akkadbakkad89 on 2026-10-24T07:55:13Z.
What happens
Every
sceKernelMapDirectMemory/ remap over a physical range iteratesg_physPages— astd::mapwith one node per 16 KiB page — twice: once inValidatePhysicalRange(containsper page) and once inAddMapping(atper page for backing-coalescing). A 13.5 GiB range is ~880k node lookups per call. A title that slides a 64 KiB-stepped remap window over a ~13.5 GiB arena issues ~216k such calls — O(pages²) total, the title effectively hangs insideremap fixedduring boot.Additionally,
sceKernelAllocateDirectMemoryitself inserts onephysPagesnode per page inCreateDirectMemoryBacking, so the 13.5 GiB arena alloc pays ~880k map inserts up front — and on Windows nothing downstream ever readsphysPages(onlySharedBacking/WriteSharedBacking, which are Linux-only, consume it).Title, test or build step
Grand Theft Auto: Vice City – The Definitive Edition,
PPSA0353001.00 — the sliding-window pass is part of its UE4 heap arena setup during boot. Reproducible withAPS5_TRACE_MEMORY=1: ~216k[memory] remap fixed <va>+<len>lines withlenshrinking by 64 KiB each call. Bring-up thread: https://github.com/boykopovar/AnyPS5/discussions/10520AnyPS5 commit
Observed on
4883171f9ffc+ (the per-page bookkeeping predates this); reproduced while investigating on a stacked branch.System
Windows 11, MinGW build, RTX 3070.
Proposed direction (already working locally, happy to PR)
Keep a block-level interval index (
g_physBlocks, one entry per pool_commit, split on partial free) next to the page map:ValidatePhysicalRangeandAddMappingthen run O(#committed blocks) instead of O(#16 KiB pages), andCreateDirectMemoryBacking/ForgetDirectMemorymaintain both.physPagesstays populated only whereSharedBacking/WriteSharedBackingneed it (Linux).Two further observations from the same storm:
remap fixedon a range that is already covered by a mapping with identical phys alignment — a no-op shortcut inRemapFixedIntoRegisteredskips the OS teardown/rebuild entirely and is a pure win independent of the index.0x9000000000reading one qword past a 32 KiB map when phys reaches ~15.75 GiB) is a separate semantic question — raised in the discussion thread above rather than here.