mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-09 00:39:32 +03:00
re-add deferred free and heap retired collect
This commit is contained in:
parent
c138fba149
commit
da17a59bdb
3 changed files with 11 additions and 5 deletions
|
@ -400,6 +400,7 @@ struct mi_heap_s {
|
||||||
size_t page_count; // total number of pages in the `pages` queues.
|
size_t page_count; // total number of pages in the `pages` queues.
|
||||||
size_t page_retired_min; // smallest retired index (retired pages are fully free, but still in the page queues)
|
size_t page_retired_min; // smallest retired index (retired pages are fully free, but still in the page queues)
|
||||||
size_t page_retired_max; // largest retired index into the `pages` array.
|
size_t page_retired_max; // largest retired index into the `pages` array.
|
||||||
|
size_t generic_count; // how often is mimalloc_generic invoked?
|
||||||
mi_heap_t* next; // list of heaps per thread
|
mi_heap_t* next; // list of heaps per thread
|
||||||
long full_page_retain; // how many full pages can be retained per queue (before abondoning them)
|
long full_page_retain; // how many full pages can be retained per queue (before abondoning them)
|
||||||
bool allow_page_reclaim; // `true` if this heap should not reclaim abandoned pages
|
bool allow_page_reclaim; // `true` if this heap should not reclaim abandoned pages
|
||||||
|
|
|
@ -119,6 +119,7 @@ mi_decl_cache_align const mi_heap_t _mi_heap_empty = {
|
||||||
{ {0}, {0}, 0, true }, // random
|
{ {0}, {0}, 0, true }, // random
|
||||||
0, // page count
|
0, // page count
|
||||||
MI_BIN_FULL, 0, // page retired min/max
|
MI_BIN_FULL, 0, // page retired min/max
|
||||||
|
0, // generic count
|
||||||
NULL, // next
|
NULL, // next
|
||||||
0, // full page retain
|
0, // full page retain
|
||||||
false, // can reclaim
|
false, // can reclaim
|
||||||
|
@ -155,6 +156,7 @@ mi_decl_cache_align mi_heap_t heap_main = {
|
||||||
{ {0x846ca68b}, {0}, 0, true }, // random
|
{ {0x846ca68b}, {0}, 0, true }, // random
|
||||||
0, // page count
|
0, // page count
|
||||||
MI_BIN_FULL, 0, // page retired min/max
|
MI_BIN_FULL, 0, // page retired min/max
|
||||||
|
0, // generic count
|
||||||
NULL, // next heap
|
NULL, // next heap
|
||||||
2, // full page retain
|
2, // full page retain
|
||||||
true, // allow page reclaim
|
true, // allow page reclaim
|
||||||
|
|
11
src/page.c
11
src/page.c
|
@ -872,11 +872,14 @@ void* _mi_malloc_generic(mi_heap_t* heap, size_t size, bool zero, size_t huge_al
|
||||||
}
|
}
|
||||||
mi_assert_internal(mi_heap_is_initialized(heap));
|
mi_assert_internal(mi_heap_is_initialized(heap));
|
||||||
|
|
||||||
|
// collect every N generic mallocs
|
||||||
|
if (heap->generic_count++ > 10000) {
|
||||||
|
heap->generic_count = 0;
|
||||||
// call potential deferred free routines
|
// call potential deferred free routines
|
||||||
// _mi_deferred_free(heap, false);
|
_mi_deferred_free(heap, false);
|
||||||
|
// collect retired pages
|
||||||
// free delayed frees from other threads (but skip contended ones)
|
_mi_heap_collect_retired(heap, false);
|
||||||
// _mi_heap_delayed_free_partial(heap);
|
}
|
||||||
|
|
||||||
// find (or allocate) a page of the right size
|
// find (or allocate) a page of the right size
|
||||||
mi_page_t* page = mi_find_page(heap, size, huge_alignment);
|
mi_page_t* page = mi_find_page(heap, size, huge_alignment);
|
||||||
|
|
Loading…
Add table
Reference in a new issue