Skip to content

Commit dbe6d9a

Browse files
committed
Merge branch 'dev' into dev2
2 parents a7b8170 + bff836f commit dbe6d9a

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

include/mimalloc/internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,13 @@ static inline bool mi_page_is_in_full(const mi_page_t* page) {
690690
}
691691

692692
static inline void mi_page_set_in_full(mi_page_t* page, bool in_full) {
693+
if (page->flags.x.in_full != in_full) {
694+
// optimize: maintain pages_full_size to avoid visiting the full queue (issue #1220)
695+
mi_heap_t* const heap = mi_page_heap(page);
696+
const size_t size = page->capacity * mi_page_block_size(page);
697+
if (in_full) { heap->pages_full_size += size; }
698+
else { mi_assert_internal(size <= heap->pages_full_size); heap->pages_full_size -= size; }
699+
}
693700
page->flags.x.in_full = in_full;
694701
}
695702

include/mimalloc/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ struct mi_heap_s {
562562
size_t page_count; // total number of pages in the `pages` queues.
563563
size_t page_retired_min; // smallest retired index (retired pages are fully free, but still in the page queues)
564564
size_t page_retired_max; // largest retired index into the `pages` array.
565+
size_t pages_full_size; // optimization: total size of blocks in the pages of the full queue (issue #1220)
565566
long generic_count; // how often is `_mi_malloc_generic` called?
566567
long generic_collect_count; // how often is `_mi_malloc_generic` called without collecting?
567568
mi_heap_t* next; // list of heaps per thread

src/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ mi_decl_cache_align const mi_heap_t _mi_heap_empty = {
119119
{ {0}, {0}, 0, true }, // random
120120
0, // page count
121121
MI_BIN_FULL, 0, // page retired min/max
122+
0, // pages_full_size
122123
0, 0, // generic count
123124
NULL, // next
124125
false, // can reclaim
@@ -168,6 +169,7 @@ mi_decl_cache_align mi_heap_t _mi_heap_main = {
168169
{ {0x846ca68b}, {0}, 0, true }, // random
169170
0, // page count
170171
MI_BIN_FULL, 0, // page retired min/max
172+
0, // pages_full_size
171173
0, 0, // generic count
172174
NULL, // next heap
173175
false, // can reclaim

0 commit comments

Comments
 (0)