perf(libc): replace the mspace block list with an ordered allocator #55
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/55"
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-09-28T03:38:22Z.
Stacked on #49. Only the last commit is new.
What
The mspace allocator kept its blocks in a first-fit linked list stored inside the arena, so every
malloc,freeandreallocwalked all the blocks. A retail title creates a 1.9 GB global heap and makes a very large number of allocations from it. The cost was quadratic, and loading effectively hung.How
malloc/memaligntake the smallest free chunk that fits, then split off any alignment padding and the tail.freemerges the chunk with free neighbours.reallocgrows in place into a free following chunk when it can, and otherwise allocates, copies and frees. All three are O(log n).MallocUsableSizelooks up the pointer in the innermost arena that contains it, so it works for pointers from nested mspaces (#49).inUse/peakInUseand the nested-create check work as before, on the new chunks.Testing
The existing
mspacetest passes unchanged. Added checks:reallocgrows in place into free space.MallocUsableSizeworks for a pointer in a nested mspace and for that mspace's own block in the outer arena.Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-28T22:14:05Z.
After these changes, the agc_shader_memory test stopped working for me. It still passes on main.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T00:00:36Z.
Thanks for checking. I couldn't reproduce it:
agc_shader_memorypasses on Linux both on the old head and on that head merged intomainas of your comment. That test doesn't call into the mspace code, so I suspect a build of the branch at its old base rather than the allocator itself.I've rebased onto current
mainand portedsceLibcMspaceReallocalignfrom #107, which was written against the old block list, to the ordered allocator (the existing reallocalign tests pass). CI is green on Linux and Windows, includingagc_shader_memory. If it still fails for you, could you paste the output and your OS/toolchain?Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T00:31:11Z.
Found it:
agc_shader_memoryis flaky onmainitself, failing about once in 75 runs. The failure is "bindless: a table entry was not captured" and doesn't depend on this PR. A stack-placed T# entry sometimes straddles a page boundary, and the test's coverage check didn't accept two adjacent page regions. The fix is in #123.