fix(libc): find mspace chunks for minimum-aligned allocations by index #4280
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4280"
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 codingreapermaps on 2026-10-12T03:59:28Z.
What
sceLibcMspace*carves chunks in 16-byte granules, but every allocation is aligned to at least 32 bytes. Each allocation taken from a chunk that starts off a 32-byte boundary leaves a 16-byte free chunk that no later allocation can use, and the best-fit search walked past all of these on everymalloc,callocandrealloc. Allocation time therefore grew with the number of live allocations: PPSA99007 (Yamagi Quake II homebrew) spent its whole start-up insideAllocateand never reached its renderer.Free chunks are now also indexed by the bytes they hold from their first 32-byte boundary, and minimum-aligned allocations take the first entry that fits, so the search is logarithmic. Allocations with a larger alignment keep the existing search. Chunk sizes, usable sizes and in-place
reallocare unchanged.Tested
Windows 11, MinGW-w64 GCC 15.2.0.
mspace, theapplication_heap_*tests,guest_heap_rounding_overflowandagc_driver_typed_heapspass;tools/check_conventions.pypasses.Allocating 32000 live blocks of 8 to 112 bytes in batches of 4000, timed per batch:
PPSA99007 v0.2.0-alpha.1: before, the main thread stayed in
Allocatewith no window (confirmed withAPS5_HANG_DUMP_SECSandAPS5_TRACE_CALLS); after, it finishes loading in about 4.5 s and reaches renderer start-up. Presenting frames needs separate changes outside this PR.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T03:59:46Z.
Thank you for your contribution! Authors with no pull requests merged into
maincan have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T00:22:56Z.
Thanks for this. The same problem was fixed on main by #4407, and with that in place main stays flat where this branch's base grew from 15 to 259 ms per batch, so we're closing this one. Thanks again for tracking it down.
Pull request closed