feat(libc): answer malloc_stats_fast for the default heap #6217
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6217"
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 milescoviello on 2026-10-15T04:23:11Z.
What
Ship of Harkinian (PPSA99320, catalog release) stops about 10 s after start-up on
main:The title uses the default allocator. Every 10 s it logs its heap use with
malloc_stats_fast: it fills insize= 0x28 andversion= 1, then printscurrentInuseSizeandcurrentSystemSize. Its struct is the same 0x28-byte layout thatsceLibcMspaceMallocStatsFastalready fills. So far only an application allocator's table entry 8 could answer the call.Now the default heap answers it too:
GuestHeapcounts the bytes it holds from the arena (the 1 MiB spans of its small-block classes and its committed large blocks, the cached free ones included) and the bytes of the blocks it has handed out (each at its size-class or 64 KiB-granule size, header included), with the peak of each. Without the arena, both count the host blocks.malloc_stats_fastwith the default allocator (table entry 8 ofdefaultApi) fills the block from those counts. A block smaller than 0x28 bytes, or a null pointer, returns 22, as the mspace version does.MallocManagedSizemoves fromMspace.cppinto a shared header, so both use one definition.The counters change on every heap
mallocandfree. Those calls already run under the guest allocation registry's lock (GuestAllocations::Mutation), so the four relaxed atomics add no new point of contention. I measured it with a temporary benchmark (not part of this PR) ofApplicationHeapAllocate/Freeof 32 to 543-byte blocks on the guest arena, 3 runs each. One thread: 112 ns per call onmain, 115 ns with this change. Eight threads: 900 ns onmain, 875 ns with this change, which is within noise.libc.mdrecords how these counts differ from Sony's allocator.Tested
Ubuntu 24.04, GCC 13.3, Release, on
maina077a88df:application_heap_stats_defaultnow checks the filled block with the default allocator. Its four sizes are ordered (max ≥ current, system ≥ in use). The in-use size grows by at least the 100,016 bytes of two blocks, returns to its earlier value when they are freed, and the peak keeps the high mark. Nothing past 0x28 bytes is written, and a short block or a null pointer gives 22. Withmain'sApplicationHeap.cppandGuestHeap.cppit fails with the title's message.application_heap_statsandapplication_heap_stats_missingstill pass.guest_*,application_heap*andmspacetests pass (385).--to-inteland run on Linux (RTX 4070 Ti) for 75 s without input. Onmainit stops at 11 s, on the first call. With this change it runs the whole 75 s at 60 FPS and logsperf: mem heap 0 MB, sys 3 MB, ...every 10 s. Screenshots at 20, 45 and 70 s show its "Game files needed" dialog, since the catalog build ships no ROM. When the 75 s timeout ends the run, its exit stops onMutex has been destroyed. A run with pad input stops the same way 8 s in, when the input starts. That's a separate issue, which this change doesn't touch.tools/check_conventions.py --base upstream/mainpasses, andtools/pr_overlap.py --branch fix/libc-malloc-stats-default-heapfinds no overlap.@nicolasfalesy found a catalog title that needs this: Ship of Harkinian, Vulkan (PPSA99320), on Linux with an Intel Arc GPU (Mesa ANV). On
main5d9dcc42dit stops withmalloc_stats_fast: implemented only for an application allocator that provides it. With this PR it renders for the whole 40 s test (avg 59.5 fpsat 3840x2160).Not checked on Windows or on a console.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T04:23:43Z.
Progress report (
3e83446→dde480e)➖ System libraries: 89.65% (+0.0%, +1 implemented functions)
✅ 1 implemented
defaultStatsFastImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:16:50Z.
Some 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.
docs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/ApplicationHeapStats.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T02:40:44Z.
A title that reaches this: Ship of Harkinian, Vulkan (PPSA99320) from the homebrew catalog, on Linux (Intel Arc, Mesa ANV).
main5d9dcc42d: stops withmalloc_stats_fast: implemented only for an application allocator that provides it.main5d9dcc42d+ this PR: that line is gone. It renders for the whole 40 s test ([info] perf: 3840x2160 avg 59.5 fps, 1% low 30.0 fps, max 33.5 ms, >20ms 7, >40ms 0, 596 frames,mem heap 0 MB, sys 3 MB). It was stopped by the test after 40 s; theMutex has been destroyedline in the log comes after that stop.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T02:42:17Z.
Thank you, @nicolasfalesy. A catalog title with a before-and-after run on Intel Arc is exactly the evidence this needed. I've added it to the description.
AI-assisted: yes