From 3fc2c8e279bc7d0ba18378ec1f525adff8672a87 Mon Sep 17 00:00:00 2001 From: daanx Date: Tue, 3 Dec 2024 11:06:07 -0800 Subject: [PATCH] fix assertions --- include/mimalloc/internal.h | 3 +-- src/bitmap.c | 4 +--- src/free.c | 2 +- src/init.c | 3 ++- src/page.c | 2 +- test/test-stress.c | 4 ++-- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index 56172bcd..9fa27f31 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -676,8 +676,7 @@ static inline bool mi_page_try_claim_ownership(mi_page_t* page) { static inline void _mi_page_unown(mi_page_t* page) { mi_assert_internal(mi_page_is_owned(page)); - mi_assert_internal(mi_page_is_abandoned(page)); - mi_assert_internal(mi_page_thread_id(page)==0); + mi_assert_internal(mi_page_is_abandoned(page)); mi_thread_free_t tf_new; mi_thread_free_t tf_old = mi_atomic_load_relaxed(&page->xthread_free); do { diff --git a/src/bitmap.c b/src/bitmap.c index df25e028..4eadce80 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -1120,9 +1120,7 @@ static inline bool mi_bfield_atomic_clear_while_not_busy(_Atomic(mi_bfield_t)*b, do { if mi_unlikely((old&mask)==mask_busy) { old = mi_atomic_load_acquire(b); - if ((old&mask)==mask_busy) { - _mi_stat_counter_increase(&_mi_stats_main.pages_unabandon_busy_wait, 1); - } + if ((old&mask)==mask_busy) { _mi_stat_counter_increase(&_mi_stats_main.pages_unabandon_busy_wait, 1); } while ((old&mask)==mask_busy) { // busy wait mi_atomic_yield(); old = mi_atomic_load_acquire(b); diff --git a/src/free.c b/src/free.c index 6e8514c6..70ef5d8a 100644 --- a/src/free.c +++ b/src/free.c @@ -155,7 +155,7 @@ void mi_free(void* p) mi_attr_noexcept static void mi_decl_noinline mi_free_try_reclaim_mt(mi_page_t* page) { mi_assert_internal(mi_page_is_owned(page)); - mi_assert_internal(mi_page_thread_id(page)==0); + mi_assert_internal(mi_page_is_abandoned(page)); #if 1 // we own the page now.. // safe to collect the thread atomic free list diff --git a/src/init.c b/src/init.c index 01beb222..99a5ea39 100644 --- a/src/init.c +++ b/src/init.c @@ -83,7 +83,8 @@ const mi_page_t _mi_page_empty = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ - { 0, 0 }, { 0, 0 }, { 0, 0 } \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 } \ MI_STAT_COUNT_END_NULL() // -------------------------------------------------------- diff --git a/src/page.c b/src/page.c index 9ea7a979..e5e3f972 100644 --- a/src/page.c +++ b/src/page.c @@ -811,7 +811,7 @@ static mi_page_t* mi_page_queue_find_free_ex(mi_heap_t* heap, mi_page_queue_t* p _mi_page_free(page_candidate, pq); page_candidate = page; } - else if (page->used >= page_candidate->used && !mi_page_is_mostly_used(page)) { + else if (page->used >= page_candidate->used) { // && !mi_page_is_mostly_used(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 4c2719aa..9e53e920 100644 --- a/test/test-stress.c +++ b/test/test-stress.c @@ -45,14 +45,14 @@ static int THREADS = 4; static int SCALE = 100; static int ITER = 10; #define ALLOW_LARGE false -#elif 1 +#elif 0 static int THREADS = 32; static int SCALE = 50; static int ITER = 50; #define ALLOW_LARGE false #else static int THREADS = 32; // more repeatable if THREADS <= #processors -static int SCALE = 50; // scaling factor +static int SCALE = 25; // scaling factor static int ITER = 50; // N full iterations destructing and re-creating all threads #endif