fix(libkernel): map AMM pages from a fragmented pool #11838
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11838"
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 oneandonlydean on 2026-10-27T09:25:13Z.
What
A map into the AMM from the pool used to need one contiguous free run, and threw
AMM: no free run of N bytes in the direct memory given to the mapperwhen the pool was fragmented, which aborts the process. The PS5 maps the mapper's pages through page tables, so a fragmented pool still serves the map. When no single run fits, the map now takes pages from several runs (first fit) and maps each contiguous group. If the pool holds fewer bytes than the map needs, it throws the same message as before.The page bookkeeping lives in
AmmPool.hpp. A map plans its pages without changing the pool, stages the page and reference records in their own maps, maps the runs, and only then splits the pool and moves the records in with no allocation, so a failed map (an allocation failure or a host map failure after some runs) leaves the pool and the records as they were. Adding a page inserts its reference record first and undoes it if the page record throws. Allocating pages for an unbacked part of a PRT range goes through the same staging, and puts the zero pages back if it fails.Based on work by @BiladeiroSupremo in AnyPS5Wolverine (
github.com/BiladeiroSupremo/AnyPS5Wolverine@c205785bab). The first commit is theirs; the others are ours: the original's log line and comment removed, a regression test for the map, and a fix that makes the page bookkeeping exception-safe (see below). The author reported the abort on an 11 MB map in a title (PPSA03671) about four minutes into a load.Tested
74ad6b1a5fon main5bc84038c4: fullninjaandninja libsbuild rc 0;ctest -R '^(guest_amm|guest_ampr)|public_headers': rc 0, 5 AMM/AMPR tests (includingguest_amm_pooland the happy-path scattered map inguest_ampr_markers) and 65 of 65public_headerstests passed.guest_ampr_markersalso allocates more pages for a PRT range than the pool holds and checks the range still reads zeros with the PRT protection afterwards, then allocates one page and writes it; with the previous behaviour (range left reserved) that check fails.guest_amm_pooldrives the bookkeeping directly with no host calls and replacesoperator newto fail each allocation in turn: a three-page scatter over three single-page runs, a scatter that splits a run, a host map that fails after each run (including a PRT-style allocation over runs of 2, 1 and 2 pages), and page insertion. After every failure the pool and the page and reference records equal their snapshot and a following map succeeds; a map of one page more than the pool holds is still refused. The same test aborts on the earlier algorithm (a page released without its reference record under ASan, records changed after a failed allocation without it) and passes under ASan, UBSan and leak checking.tools/check_conventions.pypasses. Not tested: Windows and macOS (left to CI), and the title run the author reports.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T09:32:42Z.
Review: CHANGES_REQUESTED
I reviewed the fragmented-pool path and the new regression case. One failure path needs another pass: if
_mapRunsucceeds for a scattered run but a later_addPagethrows while registering that run,mappedstill points to the beginning of the run. The catch first calls_forgetPages, which releases already-registered pages from that run back intostate.pool, then returns every page frommappedonward again. That can insert duplicate/overlapping free ranges and make later allocations reuse the same physical pages. Please make the rollback track exactly which pages were registered/released (including partial registration within a run), and add a focused failure-injection test if the allocator boundary can be injected. The ordinary successful fragmented-map test does not exercise this cleanup path. I have not approved; Windows is still pending and the Linux product test is skipped.