Fall back to the block bitmap when mimalloc rejects a small Structure heap reservation - #483
Fall back to the block bitmap when mimalloc rejects a small Structure heap reservation#483robobun wants to merge 1 commit into
Conversation
… heap reservation
|
Warning Review limit reachedYour included review limit has been reached. You’re in a promotional period — use the checkbox below to run this review for free:
On-demand reviews are free for the next 30 days. After that, they cost $0.25 per reviewed file. How can I continue?Run this review now using the option above, or comment You can also wait for the limit to reset (next review available in 10 minutes), then comment An organization admin can change what happens after included review limits in Billing. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Comment |
Preview Builds
|
Problem
StructureMemoryManager::StructureMemoryManager()halves its 4 GB reservation request up to 8 times, down to 32 MB. UnderUSE(MIMALLOC)the 32 MB rung can never be used:RELEASE_ASSERT(mi_manage_os_memory_ex(...))atStructureAlignedMemoryAllocator.cpp:147fails and the process aborts before any JS runs. This is Sentry BUN-4NF7 on bun 1.4.0 (Linux x64).32 MiB - 16 KiB(oneMarkedBlockis kept for StructureID 0). mimalloc aligns the start up to its 64 KiB slice size and then needs one whole chunk of slices,MI_ARENA_MIN_SIZE= 32 MiB. It sees 32704 KiB, needs 32768 KiB, and returns false. Every rung from 64 MB up passes.Fix
mi_manage_os_memory_exreturns false, setm_useSystemHeapand hand out blocks from the reservation with the existingm_usedBlocksbitmap. That is the path JSC already uses when bmalloc is disabled, so a 32 MB reservation now gives a working 32 MB Structure heap instead of an abort.MADV_DOFORK/vm_inheritundo stays inside the mimalloc branch, because only the mimalloc arena puts process-wide data inside the reservation.tryMallocStructureBlockandfreeStructureBlockbranch onm_useSystemHeapin bothUSE(LIBPAS)andUSE(MIMALLOC)builds. The file compiles with-fsyntax-onlyin bun'sUSE_MIMALLOC=1configuration. I did not build JSC here.BUN_JSC_structureHeapSizeInKB=32768 bun -e 1aborts on bun 1.4.0 with the same trace string as BUN-4NF7 (65536works). With this change it prints nothing and exits 0.bash -c 'ulimit -v 300000; exec bun -e 1'reaches the same assert through the halving loop.Background
StructureIDcan be 32 bits.sizeOfStructureHeapis whatever rung the reservation loop ended on.USE(MIMALLOC)the reservation (minus the first block) is registered as an exclusive mimalloc arena, andstructureHeapallocates 16 KiB blocks from it. Underm_useSystemHeapthe manager commits and decommits blocks of the reservation itself and tracks them in aBitVector.ulimit -v, a container limit, orvm.overcommit_memory=2. On bun 1.4.0 x64 Linux,ulimit -vbetween about 100 and 340 MB, 1.15 and 1.27 GB, and 2.20 and 2.33 GB ends on the 32 MB rung (bun's own 1 GiB mimalloc arena and the 1 GiB JIT pool are what eat the space in the upper two windows). The companion bun change (oven-sh/bun, crash_handler) turns the remaining case, no reservation at all, into an error message instead of a crash report.