Repository navigation
feat(libc): answer malloc_stats_fast for the default heap - #6217
Merged
adriadam10 merged 1 commit intoOct 18, 2026
Merged
Conversation
Closed
10 tasks done
Merged
10 tasks done
This was referenced Oct 15, 2026
|
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.
|
This was referenced Oct 15, 2026
Closed
milescoviello
force-pushed
the
fix/libc-malloc-stats-default-heap
branch
2 times, most recently
from
October 15, 2026 15:14
1eb72d6 to
f33e70e
Compare
Contributor
|
A title that reaches this: Ship of Harkinian, Vulkan (PPSA99320) from the homebrew catalog, on Linux (Intel Arc, Mesa ANV).
AI-assisted: yes |
Contributor
Author
|
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 |
milescoviello
force-pushed
the
fix/libc-malloc-stats-default-heap
branch
from
October 17, 2026 18:34
f33e70e to
5691669
Compare
Ship of Harkinian (PPSA99320) logs its heap use with malloc_stats_fast every 10 s and stopped on the first call, since only an application allocator could answer it. The default heap now keeps its system and in-use byte counts with their peaks and fills the same managed-size block as sceLibcMspaceMallocStatsFast, whose layout moves to a shared header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
milescoviello
force-pushed
the
fix/libc-malloc-stats-default-heap
branch
from
October 17, 2026 20:54
5691669 to
dde480e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
maina077a88: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
main5d9dcc4 it 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