diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index a5968651..a6ed7057 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -609,7 +609,7 @@ static inline bool mi_page_immediate_available(const mi_page_t* page) { } // is more than 7/8th of a page in use? -static inline bool mi_page_mostly_used(const mi_page_t* page) { +static inline bool mi_page_is_mostly_used(const mi_page_t* page) { if (page==NULL) return true; uint16_t frac = page->reserved / 8U; return (page->reserved - page->used <= frac); diff --git a/src/page-queue.c b/src/page-queue.c index efff60e5..83b60e93 100644 --- a/src/page-queue.c +++ b/src/page-queue.c @@ -348,7 +348,7 @@ static void mi_page_queue_enqueue_from(mi_page_queue_t* to, mi_page_queue_t* fro static void mi_page_queue_enqueue_from_full(mi_page_queue_t* to, mi_page_queue_t* from, mi_page_t* page) { // note: we could insert at the front to increase reuse, but it slows down certain benchmarks (like `alloc-test`) - mi_page_queue_enqueue_from_ex(to, from, false /* enqueue at the end of the `to` queue? */, page); + mi_page_queue_enqueue_from_ex(to, from, true /* enqueue at the end of the `to` queue? */, page); } // Only called from `mi_heap_absorb`. diff --git a/src/page.c b/src/page.c index 860d972b..42f529e1 100644 --- a/src/page.c +++ b/src/page.c @@ -788,7 +788,8 @@ static mi_page_t* mi_page_queue_find_free_ex(mi_heap_t* heap, mi_page_queue_t* p page_candidate = page; candidate_count = 0; } - else if (!mi_page_mostly_used(page) && page->used >= page_candidate->used) { + // prefer to reuse fuller pages (in the hope the less used page gets freed) + else if (page->used >= page_candidate->used && !mi_page_is_mostly_used(page) && !mi_page_is_expandable(page)) { page_candidate = page; } // if we find a non-expandable candidate, or searched for N pages, return with the best candidate diff --git a/test/test-stress.c b/test/test-stress.c index 1aa34339..63e68549 100644 --- a/test/test-stress.c +++ b/test/test-stress.c @@ -326,7 +326,6 @@ int main(int argc, char** argv) { #endif #endif mi_stats_print(NULL); - //mi_stats_print(NULL); //bench_end_program(); return 0; }