From 45f7fb559ace2ba1c463d0ca48dbeff62e46d117 Mon Sep 17 00:00:00 2001 From: daanx Date: Wed, 4 Dec 2024 00:14:56 -0800 Subject: [PATCH] small fixes --- include/mimalloc/internal.h | 11 +++++++++-- src/bitmap.h | 3 ++- test/test-stress.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index c92375c5..cb689877 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -487,7 +487,7 @@ static inline mi_page_t* _mi_checked_ptr_page(const void* p) { } static inline mi_page_t* _mi_ptr_page(const void* p) { - #if 1 // MI_DEBUG + #if MI_DEBUG return _mi_checked_ptr_page(p); #else return _mi_ptr_page_ex(p,NULL); @@ -638,6 +638,13 @@ static inline bool mi_page_is_mostly_used(const mi_page_t* page) { return (page->reserved - page->used <= frac); } +// is less than 1/n'th of a page free? +static inline bool mi_page_is_used_at_frac(const mi_page_t* page, uint16_t n) { + if (page==NULL) return true; + uint16_t frac = page->reserved / n; + return (page->reserved - page->used <= frac); +} + static inline bool mi_page_is_abandoned(const mi_page_t* page) { // note: the xheap field of an abandoned heap is set to the subproc (for fast reclaim-on-free) return (mi_atomic_load_acquire(&page->xthread_id) <= 1); @@ -692,7 +699,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_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.h b/src/bitmap.h index 9b931c95..d73ee98a 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -51,8 +51,9 @@ typedef uint32_t mi_cmap_t; typedef mi_decl_align(MI_BITMAP_CHUNK_SIZE) struct mi_bitmap_s { _Atomic(size_t) chunk_map_count; _Atomic(size_t) chunk_count; + size_t padding[MI_BITMAP_CHUNK_SIZE/MI_SIZE_SIZE - 2]; // suppress warning on msvc _Atomic(mi_chunkmap_t) chunk_maps[MI_BITMAP_MAX_CHUNKMAPS]; - // padding + mi_bitmap_chunk_t chunks[MI_BITMAP_MIN_BIT_COUNT]; // or more, up to MI_BITMAP_MAX_CHUNK_COUNT } mi_bitmap_t; diff --git a/test/test-stress.c b/test/test-stress.c index 904b1acc..0b1b6c8d 100644 --- a/test/test-stress.c +++ b/test/test-stress.c @@ -45,7 +45,7 @@ static int THREADS = 1; static int SCALE = 100; static int ITER = 10; #define ALLOW_LARGE false -#elif 0 +#elif 1 static int THREADS = 32; static int SCALE = 50; static int ITER = 50;