-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Upgrade mimalloc to v3.2.7 #26214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade mimalloc to v3.2.7 #26214
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,17 +60,28 @@ pub const Heap = opaque { | |
| return mi_heap_realloc(self, p, newsize); | ||
| } | ||
|
|
||
| pub fn isOwned(self: *Heap, p: ?*anyopaque) bool { | ||
| return mi_heap_check_owned(self, p); | ||
| pub fn isOwned(self: *Heap, p: ?*const anyopaque) bool { | ||
| return mi_heap_contains(self, p); | ||
| } | ||
| }; | ||
| pub extern fn mi_heap_new() ?*Heap; | ||
| pub extern fn mi_heap_delete(heap: *Heap) void; | ||
| pub extern fn mi_heap_destroy(heap: *Heap) void; | ||
| pub extern fn mi_heap_set_default(heap: *Heap) *Heap; | ||
| pub extern fn mi_heap_get_default() *Heap; | ||
| pub extern fn mi_heap_get_backing() *Heap; | ||
| pub extern fn mi_heap_collect(heap: *Heap, force: bool) void; | ||
| pub extern fn mi_heap_main() *Heap; | ||
|
|
||
| // Thread-local heap (theap) API - new in mimalloc v3 | ||
| pub const THeap = opaque {}; | ||
| pub extern fn mi_theap_get_default() *THeap; | ||
| pub extern fn mi_theap_set_default(theap: *THeap) *THeap; | ||
| pub extern fn mi_theap_collect(theap: *THeap, force: bool) void; | ||
| pub extern fn mi_theap_malloc(theap: *THeap, size: usize) ?*anyopaque; | ||
| pub extern fn mi_theap_zalloc(theap: *THeap, size: usize) ?*anyopaque; | ||
| pub extern fn mi_theap_calloc(theap: *THeap, count: usize, size: usize) ?*anyopaque; | ||
| pub extern fn mi_theap_malloc_small(theap: *THeap, size: usize) ?*anyopaque; | ||
| pub extern fn mi_theap_malloc_aligned(theap: *THeap, size: usize, alignment: usize) ?*anyopaque; | ||
| pub extern fn mi_theap_realloc(theap: *THeap, p: ?*anyopaque, newsize: usize) ?*anyopaque; | ||
| pub extern fn mi_heap_theap(heap: *Heap) *THeap; | ||
|
Comment on lines
+71
to
+84
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: git ls-files | head -30Repository: oven-sh/bun Length of output: 911 🏁 Script executed: fd -a 'mimalloc\.(zig|h)' .Repository: oven-sh/bun Length of output: 101 🏁 Script executed: cat -n src/allocators/mimalloc.zig | head -100Repository: oven-sh/bun Length of output: 6735 🏁 Script executed: fd -a '\.h$' | xargs grep -l 'mi_theap_malloc' 2>/dev/null | head -5Repository: oven-sh/bun Length of output: 37 🏁 Script executed: find . -type f -name "*.h" | grep -i mimalloc | head -10Repository: oven-sh/bun Length of output: 96 🏁 Script executed: find . -type d -name "mimalloc*" 2>/dev/null | head -10Repository: oven-sh/bun Length of output: 37 🏁 Script executed: git config --file=.gitmodules --name-only --get-regexp path | head -10Repository: oven-sh/bun Length of output: 37 🏁 Script executed: cat -n ./src/bun.js/bindings/MimallocWTFMalloc.h | head -100Repository: oven-sh/bun Length of output: 3139 🏁 Script executed: rg -n 'mimalloc|v3\.|version|3\.2\.7' src/allocators/mimalloc.zigRepository: oven-sh/bun Length of output: 148 🌐 Web query:
💡 Result: Did you mean mi_heap_* (not "mi_theap")? The C signatures in mimalloc v3.2.7 are:
(These appear in the mimalloc heap API which also documents aligned/zero/calloc/realloc variants.) [1] Sources: 🌐 Web query:
💡 Result: Short answer: There is no mi_theap_malloc / mi_theap_realloc in the official mimalloc v3.2.7 API — the correct heap-specific function names use "mi_heap_*", e.g. mi_heap_malloc and mi_heap_realloc (and related variants mi_heap_reallocf, mi_heap_realloc_aligned, mi_heap_mallocn, etc.). See the official heap and basic-allocation docs and the v3.2.7 doxygen listing. [1][2][3] Sources:
🏁 Script executed: fd 'mimalloc\.h' . -type fRepository: oven-sh/bun Length of output: 225 🏁 Script executed: rg -n 'mi_theap' . --type zigRepository: oven-sh/bun Length of output: 1266 🏁 Script executed: rg -n 'theap' . -A 2 -B 2Repository: oven-sh/bun Length of output: 2139 🏁 Script executed: find . -path ./\.git -prune -o -type f -name "*.c" -o -name "*.h" | xargs grep -l 'mi_theap' 2>/dev/null | head -5Repository: oven-sh/bun Length of output: 37 🏁 Script executed: rg 'mi_theap_' --type zig -A 2 -B 2Repository: oven-sh/bun Length of output: 1834 🏁 Script executed: rg '\.mi_theap_|mi_theap_get_default|mi_theap_malloc|mi_theap_set_default|mi_theap_collect|mi_theap_zalloc|mi_theap_calloc|mi_theap_malloc_small|mi_theap_malloc_aligned|mi_theap_realloc|mi_heap_theap' src/allocators/ --type zigRepository: oven-sh/bun Length of output: 1162 🏁 Script executed: rg -i 'fork|custom|patch|version.*mimalloc|mimalloc.*version' src/allocators/ --type zig -A 1Repository: oven-sh/bun Length of output: 284 Remove incorrect The nine 🤖 Prompt for AI Agents |
||
| pub extern fn mi_heap_malloc(heap: *Heap, size: usize) ?*anyopaque; | ||
| pub extern fn mi_heap_zalloc(heap: *Heap, size: usize) ?*anyopaque; | ||
| pub extern fn mi_heap_calloc(heap: *Heap, count: usize, size: usize) ?*anyopaque; | ||
|
|
@@ -102,8 +113,7 @@ pub extern fn mi_heap_rezalloc_aligned(heap: *Heap, p: ?*anyopaque, newsize: usi | |
| pub extern fn mi_heap_rezalloc_aligned_at(heap: *Heap, p: ?*anyopaque, newsize: usize, alignment: usize, offset: usize) ?*anyopaque; | ||
| pub extern fn mi_heap_recalloc_aligned(heap: *Heap, p: ?*anyopaque, newcount: usize, size: usize, alignment: usize) ?*anyopaque; | ||
| pub extern fn mi_heap_recalloc_aligned_at(heap: *Heap, p: ?*anyopaque, newcount: usize, size: usize, alignment: usize, offset: usize) ?*anyopaque; | ||
| pub extern fn mi_heap_contains_block(heap: *Heap, p: *const anyopaque) bool; | ||
| pub extern fn mi_heap_check_owned(heap: *Heap, p: *const anyopaque) bool; | ||
| pub extern fn mi_heap_contains(heap: *const Heap, p: ?*const anyopaque) bool; | ||
| pub extern fn mi_check_owned(p: ?*const anyopaque) bool; | ||
| pub const struct_mi_heap_area_s = extern struct { | ||
| blocks: ?*anyopaque, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 71
🏁 Script executed:
head -120 src/allocators/mimalloc.zig | tail -60Repository: oven-sh/bun
Length of output: 4537
🏁 Script executed:
Repository: oven-sh/bun
Length of output: 5014
🌐 Web query:
mimalloc v3 mi_heap_contains API documentation💡 Result:
There is no mi_heap_contains function in mimalloc v3. Use these heap-introspection APIs instead:
bool mi_heap_contains_block(mi_heap_t *heap, const void *p) — returns true if p (a pointer to a previously allocated block) is in heap. [1]
bool mi_heap_check_owned(mi_heap_t *heap, const void *p) — more general/expensive check: returns true if p points anywhere into the given heap (p need not be a previously allocated block). Note: linear in the pages in the heap. [1]
(See the v3 API docs for the Heap Introspection and Heap Allocation groups.) [1][2]
Sources:
[1] mimalloc — Heap Introspection (mi_heap_contains_block, mi_heap_check_owned).
[2] mimalloc — Heap Allocation (mi_heap_* APIs).
mi_heap_containsis not a valid mimalloc v3 API function. Usemi_heap_contains_block()to check if a pointer is a previously allocated block, ormi_heap_check_owned()for a more general check. The extern declaration at line 116 and theisOwnedimplementation at lines 63-65 both reference a non-existent function that will cause link or runtime failures.🤖 Prompt for AI Agents