From ae83e02c68385c9d99b875c83115041cb09f1a1e Mon Sep 17 00:00:00 2001 From: anshika_gupta Date: Mon, 9 Mar 2026 06:15:48 +0530 Subject: [PATCH 1/3] Added mi_visit_blocks to visit all blocks of all heaps in a thread --- include/mimalloc.h | 3 +++ src/heap.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/mimalloc.h b/include/mimalloc.h index 174d9a34c..42f7a3bca 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -287,6 +287,9 @@ typedef bool (mi_cdecl mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_ mi_decl_export bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg); +//Visiting all blocks of all heaps in a thread +mi_decl_export bool mi_visit_blocks(const mi_heap_t* heap ,bool visit_blocks, mi_block_visit_fun* visitor, void* arg); + // Experimental mi_decl_nodiscard mi_decl_export bool mi_is_in_heap_region(const void* p) mi_attr_noexcept; mi_decl_nodiscard mi_decl_export bool mi_is_redirected(void) mi_attr_noexcept; diff --git a/src/heap.c b/src/heap.c index 88969311e..54d9a980d 100644 --- a/src/heap.c +++ b/src/heap.c @@ -735,3 +735,19 @@ bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_vis mi_visit_blocks_args_t args = { visit_blocks, visitor, arg }; return mi_heap_visit_areas(heap, &mi_heap_area_visitor, &args); } + +//Visiting all blocks of all heaps in a thread +bool mi_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg) { + mi_assert_internal(heap != NULL); + if (heap == NULL) return false; + mi_heap_t* curr = heap->tld->heaps; + while (curr != NULL) { + mi_heap_t* next = curr->next; + if(!mi_heap_visit_blocks(curr, visit_blocks, visitor, arg)){ + return false; + } + curr = next; + } + return true; +} + From c0ef1e139b592729418b50c9b042620dfd2cfb25 Mon Sep 17 00:00:00 2001 From: Anshika Gupta Date: Thu, 23 Apr 2026 01:03:06 +0530 Subject: [PATCH 2/3] WIP: initial implementation of visit all blocks API --- include/mimalloc.h | 2 +- src/heap.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mimalloc.h b/include/mimalloc.h index 42f7a3bca..545791732 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -288,7 +288,7 @@ typedef bool (mi_cdecl mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_ mi_decl_export bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg); //Visiting all blocks of all heaps in a thread -mi_decl_export bool mi_visit_blocks(const mi_heap_t* heap ,bool visit_blocks, mi_block_visit_fun* visitor, void* arg); +mi_decl_export bool mi_visit_blocks(bool visit_blocks, mi_block_visit_fun* visitor, void* arg); // Experimental mi_decl_nodiscard mi_decl_export bool mi_is_in_heap_region(const void* p) mi_attr_noexcept; diff --git a/src/heap.c b/src/heap.c index 54d9a980d..5f04a4025 100644 --- a/src/heap.c +++ b/src/heap.c @@ -737,7 +737,7 @@ bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_vis } //Visiting all blocks of all heaps in a thread -bool mi_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg) { +bool mi_visit_blocks(bool visit_blocks, mi_block_visit_fun* visitor, void* arg) { mi_assert_internal(heap != NULL); if (heap == NULL) return false; mi_heap_t* curr = heap->tld->heaps; From 4e0b307ecfa03f64a233d9e7fb1268c5b3123947 Mon Sep 17 00:00:00 2001 From: Anshika Gupta Date: Mon, 4 May 2026 19:27:34 +0530 Subject: [PATCH 3/3] Added mi_thread_visit_blocks API --- include/mimalloc.h | 2 +- src/heap.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/mimalloc.h b/include/mimalloc.h index 545791732..2a2a7e35e 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -288,7 +288,7 @@ typedef bool (mi_cdecl mi_block_visit_fun)(const mi_heap_t* heap, const mi_heap_ mi_decl_export bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_visit_fun* visitor, void* arg); //Visiting all blocks of all heaps in a thread -mi_decl_export bool mi_visit_blocks(bool visit_blocks, mi_block_visit_fun* visitor, void* arg); +mi_decl_export bool mi_thread_visit_blocks(bool visit_blocks, mi_block_visit_fun* visitor, void* arg); // Experimental mi_decl_nodiscard mi_decl_export bool mi_is_in_heap_region(const void* p) mi_attr_noexcept; diff --git a/src/heap.c b/src/heap.c index 5f04a4025..6854312d3 100644 --- a/src/heap.c +++ b/src/heap.c @@ -737,17 +737,18 @@ bool mi_heap_visit_blocks(const mi_heap_t* heap, bool visit_blocks, mi_block_vis } //Visiting all blocks of all heaps in a thread -bool mi_visit_blocks(bool visit_blocks, mi_block_visit_fun* visitor, void* arg) { - mi_assert_internal(heap != NULL); +bool mi_thread_visit_blocks(bool visit_blocks, mi_block_visit_fun* visitor, void* arg) { + mi_heap_t* heap = mi_heap_get_default(); if (heap == NULL) return false; + mi_heap_t* curr = heap->tld->heaps; while (curr != NULL) { mi_heap_t* next = curr->next; - if(!mi_heap_visit_blocks(curr, visit_blocks, visitor, arg)){ + if (!mi_heap_visit_blocks(curr, visit_blocks, visitor, arg)) { return false; } curr = next; } + return true; } -