fix(libkernel): scope flexible release to tracked ranges with release-then-record #7112
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7112"
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 Pouare514 on 2026-10-17T12:05:09Z.
What
core/libs/prx/libkernel/DirectMemory/Export.cpp: extracted_releaseFlexibleLocked()(same interval erase/split),_releaseFlexible()locks + delegates.sceKernelMunmapof a non-flexible (direct/reserved) range no longer over-releases the flexible budget._mapFlexible(flexible-over-flexible, fixes double-charge/leak),sceKernelMapDirectMemory/2,sceKernelMapNamedDirectMemory,sceKernelReserveVirtualRange,sceKernelBatchMap2/OpMapDirect(direct/reserved-over-flexible clears stale entries, so a later munmap of that range leavesAvailableunchanged).actual = total - flexAvailable - table[6]vs budget 140 MB; the log showsIt is 17592186044416.xxx(= 2^64, wrapped negative), i.e.AvailableFlexibleis overstated by untracked releases. No title-specific code, no budget-math changes, no new tracing infra.Tested
CheckFlexibleFixedReplacement+CheckMunmapScopedFlexibleReleaseinguest_memory: flexible map dropsAvailableby N; fixed-remap keepsbefore-4p; munmap of direct/reserve leavesAvailableunchanged; flexible subrange munmap reclaims exactly. Fail without (abort0xc0000409) / pass with.guest_memorygreen post-rebase (WinLibs GCC 15.2, Release); neighborsguest_kernel_sys,guest_memory_pool_stats,guest_jit_shared_memory,guest_flexible_memory_*green.check_conventions.pyclean,git diff --checkclean.libkernel.prxinto run dir, runtlou.exe, theCode and Dataline must stop wrapping 2^64).Checklist
main; no other open PR implements the same change_mapFlexiblehunk and #6491 budgetreplacedsubtraction — both open)Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-17T12:05:33Z.
Manual overlap check for this PR's files (Export.cpp, GuestMemory.cpp): _releaseFlexible scoping + release-then-record. _releaseFlexibleLocked helper duplicates #6491's same helper textually - #6491's budget replaced subtraction deliberately NOT duplicated here (tight-budget same-range remap still needs #6491); whichever lands first, the other rebases the helper. #6311 routes POSIX munmap through sceKernelMunmap (PosixMemory.cpp) - complementary, different path, rebase-only. #7105 shares the _mapFlexible success-insert hunk textually (lock-split vs release-then-record) - coordinate at merge; all other hunks disjoint. Correction to the PR body checklist: #6515 (open) implements the same direct-over-flexible release idea for the 4 MapDirect callsites via a _mapDirect helper - partial overlap, not full duplication (this PR additionally scopes _releaseFlexible to tracked ranges, covers _mapFlexible + ReserveVirtualRange, and pins behavior in guest_memory). Rebase plan: if #6515 lands first, this PR adopts the _mapDirect helper shape and keeps scoping + tests; if this lands first, #6515 rebases onto it.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T12:17:03Z.
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/libkernel/DirectMemory/Export.cppL107, L118, L124-134core/libs/prx/libkernel/DirectMemory/Export.cppL231, L236, L247, L507Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/tests/GuestMemory.cppcore/libs/prx/libkernel/DirectMemory/Export.cppcore/libs/tests/GuestMemory.cppcore/libs/tests/GuestMemory.cppcore/libs/prx/libkernel/DirectMemory/Export.cppcore/libs/tests/GuestMemory.cppcore/libs/prx/libkernel/DirectMemory/Export.cppcore/libs/prx/libkernel/DirectMemory/Export.cppcore/libs/tests/GuestMemory.cppImported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-17T12:41:35Z.
Manual overlap check for this PR's files (Export.cpp release paths, GuestMemory.cpp tests): #6491 true partial overlap - identical _releaseFlexibleLocked helper + identical release-then-record in _mapFlexible (theirs adds budget replaced subtraction, deliberately not duplicated here); whoever lands first, the other drops the duplicated hunk. #6515 true partial overlap - same direct-over-flexible release (their _mapDirect helper vs my inline calls); heads-up already exchanged both ways. #5021 same main() region (their GuestArenaAvailable guards vs my 2 test calls) - textual conflict possible, mechanical merge. #6044 moves GuestMemory.cpp to memory/ - path move only, my tests follow on rebase. #4449/#6565 additive tests under different names - clean. #6222 macOS VirtualQuery + includes - disjoint hunks. #6311 different file and path (PosixMemory munmap routing) - complementary. Depends on stays none (no build dependency; merge-order coordination as above). On #7120: gap 1 (MAP_FIXED via sceKernelMmap/file maps over flexible keeps its charge) is the same bug class in paths this PR doesn't touch - happy to take it as a follow-up once this lands. Gap 2 (anonymous mmap charging) needs the hardware-behavior answer first.
Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-17T12:43:32Z.
CI note: conventions/eligibility/intake green; unit pins (guest_memory + flexible-budget neighbors) verified green on Windows locally. The full Linux + Windows builds need collaborator dispatch (automatic full builds only run on main) - requesting dispatch when review allows. A TLOU game-run proof (Code-and-Data wrap check) is in progress and will be reported here.
Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-17T12:49:26Z.
Game-run proof (replacing the pending note in the body): TLOU run dir with PR-head libs (fresh nid-patched libkernel.prx + libc.prx; libc refresh was loader-compat only - fresh libkernel imports AddPathProvider_nid_no_patch, absent from the stale deployed libc). BEFORE (stale libs): Code and Data section is too large. It is 17592186044416.016 and should be 140.000, then FATAL 0xc0000005 at tlou.exe+0x1a5ffaf. AFTER: no assert fires, sane Code And Global Data: 97.28 MB / Free Flex Mem: 60.72 MB, execution continues past 0x1A5FFAF/0x1A600B1 to tlou.exe+0x1a69806, where it stops on the pre-existing unrelated sceSslLoadCert throwing stub (merged in #519). Wrap fixed; next wall is a known stub, not a memory regression. Logs: tlou-base.log / tlou-flex.log in the run dir.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T18:44:55Z.
I am evaluating the separate #7120 gap: successful
MAP_FIXEDanonymous/file mappings replace flexible pages without updatingg_flexibleRanges. Your current diff handles fixed flexible/direct/reserved mappings but not the POSIX mmap paths. I have a minimal draft calling the existing interval release helper only after successful fixed mmap and a regression for replacing the middle of a three-page flexible range. Since this touchesDirectMemory/Export.cpp/accounting helpers, would you prefer I hold it for a follow-up based on your merged head, or do you see a conflict with your intended changes? I have not published or pushed it.Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-18T00:33:20Z.
Thanks for checking first, and for scoping it to the POSIX mmap paths this PR deliberately doesn't touch. Hold it for a follow-up based on the merged head: your draft (interval release after successful fixed mmap + middle-of-three-pages regression) is complementary, not conflicting. Note it will build on this PR's _releaseFlexibleLocked helper - I'll keep that hunk stable; if this PR changes shape during review I'll flag you. Happy to review the draft whenever ready.