Skip to content

prof: grow the dump's location table instead of spinning when it fills - #28

Merged
Jarred-Sumner merged 1 commit into
bun-dev3-v2from
claude/prof-dump-loc-table
Aug 23, 2026
Merged

prof: grow the dump's location table instead of spinning when it fills#28
Jarred-Sumner merged 1 commit into
bun-dev3-v2from
claude/prof-dump-loc-table

Conversation

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

Split out of the startup-snapshot branch (#13 / #16), where it rode along with unrelated changes.

mi_prof_dump_pb dedups frame addresses through an open-addressed table that was a fixed 4096 slots with no occupancy check: a profile with more unique frames than that (easy with MIMALLOC_PROF_SAMPLE_RATE on a real program — 32 frames per sample) made mi_prof_loc_find probe a full table forever, with mi_prof.lock held. The table was also allocated with _mi_os_zalloc and never freed, once per dump.

  • The table doubles when it would pass half full and is freed when the dump finishes; if the grow allocation fails the dump stops and returns -1.
  • pb_flush now discards the staging buffer once err is set. Before, a short write() set err, the next flush returned early with pos still at capacity, and pb_raw looped on take == 0 — the same hang by another route (found in review by forcing the grow allocation to fail).
  • test-prof adds 5000 distinct call sites sampled at rate 1 and dumps them; on the base branch that case times out.

ctest in a Debug MI_DEBUG_FULL build: everything passes except test-stress-subprocs and test-purge-holes, which fail identically on bun-dev3-v2 without this change on this machine (the heap-teardown work in #27 is in that area).

…s, free it afterwards, and let a failed write end the dump

mi_prof_dump_pb collected unique frame addresses into a fixed 4096-slot
open-addressed table with no occupancy check, so a profile with more unique
frames than that made mi_prof_loc_find probe forever while holding the
profiler lock; the table was also never freed. It now doubles (kept at most
half full) and is released when the dump finishes. pb_flush discards the
staging buffer once an error is recorded, so a short write (or the new OOM
path) makes the dump return -1 instead of pb_raw spinning on a full buffer.

test-prof gains a case with 5000 distinct call sites sampled at rate 1.

No-Verification-Needed: allocator-fork profiler; covered by mimalloc's own test-prof / test-prof-adversarial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant