libkernel: anonymous mmap (MAP_PRIVATE|MAP_ANON) is not charged as flexible memory #7120
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 oneandonlydean on 2026-10-17T12:20:10Z.
Two gaps in flexible-memory accounting, found while reviewing #7112. Main (
c9e6c45de) behaves the same way, so neither is a regression from that PR, and neither is in the paths it changes.1. MAP_FIXED over flexible pages keeps their charge.
sceKernelMmapis a thin wrapper overmmap_nid_postfix. AMAP_PRIVATE|MAP_ANON|MAP_FIXEDmap inside the arena withoutMAP_EXCL(theDoMapAnon/GuestMapFixedplacement), or a file map withMAP_FIXED, can replace pages that were mapped as flexible. Neither path touchesg_flexibleRanges(DirectMemory/Export.cpp), so the replaced pages stay charged untilmunmap, and the used figure reads higher than what is actually mapped as flexible. It's the same overstated-used class that #7112 fixes for direct and reserved memory.2. Anonymous mmap is never charged as flexible. Plain anonymous
mmapdoesn't add tog_flexibleRangeson main. If anonymous maps draw from the flexible budget on real hardware, the used figure reads lower than a title would see. I haven't confirmed the hardware behaviour, so treat this point as a question.sceKernelJitMapSharedMemoryisn't affected by point 1:DoMapSharedcallsMapPlaced(*addr, len, PROT_NONE, 0, PS5_PAGE_SIZE)inDirectMemory/DirectMemory.cpp, so the address is only a hint, neverMAP_FIXED, and it can't land on a live flexible range.Why it matters: titles read the flexible figure at boot, so counting too much or too little can change what a title decides to allocate. I don't know of a title that hits either gap yet; this comes from reading the code.
Questions for whoever owns the kernel memory code: should
MAP_FIXEDover a flexible range release the replaced pages' charge? And should anonymousmmapbe recorded ing_flexibleRangesthe way the flexible map call is?Related: #5260 (munmap release of flexible memory), #7112 (release scoping).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T12:20:27Z.
I checked the current PR inventory and source paths. The
MAP_FIXEDreplacement accounting is already implemented by open #6491, and the current overlap report for #6491 shows shared edits with #7112 in the same flexible-range accounting helpers. I would avoid a competing patch there; #6491 needs to be coordinated/rebased with #7112.The anonymous
mmappoint remains a separate question, but the issue says its flexible-budget behavior on retail hardware is unconfirmed. Before changing accounting, could you provide a console/API observation or a title repro showing that anonymous mappings consume the flexible-memory budget? Without that evidence, charging every anonymous map risks changing the budget semantics based only on host mapping behavior.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T18:46:17Z.
Correction to my earlier overlap note: after inspecting the full #6491 diff, it fixes fixed replacement through
sceKernelMapFlexibleMemoryitself; it does not touchmmap_nid_postfixor the successfulMAP_FIXEDanonymous/file-backed paths described in point 1 here. So #6491 is related interval-accounting work, but it is not the same POSIX mmap fix. My current draft addresses only those successful fixed mmap paths (the unconfirmed anonymous-mmap charging question remains out of scope). It still shares the internal accounting helper/file with open #7112, so I have asked that PR author about sequencing before publishing.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T18:52:05Z.
Opened PR #7242 for the confirmed successful
MAP_FIXEDanonymous/file-backed mmap replacement gap. It releases the replaced flexible-accounting interval only after a successful mapping and adds accounting/content regressions for middle-page replacement. The separate question about charging ordinary anonymous mmap remains unchanged because its retail behavior is unconfirmed.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T05:42:20Z.
Update: #7242 was merged at
5a8677066, resolving the confirmedMAP_FIXEDreplacement-accounting gap in point 1. The separate question in point 2—whether ordinary anonymous mappings consume the flexible-memory budget on retail hardware—still lacks evidence, so I am leaving that behavior unclaimed.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T06:52:27Z.
Gap 1 (MAP_FIXED keeping the old flexible charge) was fixed by #7242 (
5a8677066). Gap 2, anonymous mmap not being charged as flexible, is still open as far as I can tell. Is that right, or did #7242 or another change cover it? If it's still open I'll keep this issue for gap 2 only.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:15:02Z.
I checked the current
mmap_nid_postfixpath on main after #7242. Successful fixed anonymous and file-backed mappings callReleaseFlexibleMappingRange, so the confirmed replacement-accounting gap is resolved. OrdinaryMAP_PRIVATE|MAP_ANONstill returns fromDoMapAnonwithout being added to the flexible-range tracker. So gap 2 remains open as a code observation, but its console budget semantics are still unverified; I would keep it as a question and not change accounting until we have a hardware/API measurement.