diff --git a/include/mimalloc/internal.h b/include/mimalloc/internal.h index 9c5eb362..50bd5d79 100644 --- a/include/mimalloc/internal.h +++ b/include/mimalloc/internal.h @@ -219,6 +219,7 @@ void _mi_page_free_collect_partly(mi_page_t* page, mi_block_t* head); void _mi_page_init(mi_heap_t* heap, mi_page_t* page); bool _mi_page_queue_is_valid(mi_heap_t* heap, const mi_page_queue_t* pq); +size_t _mi_page_bin(const mi_page_t* page); // for stats size_t _mi_bin_size(size_t bin); // for stats size_t _mi_bin(size_t size); // for stats @@ -237,6 +238,7 @@ void _mi_heap_page_reclaim(mi_heap_t* heap, mi_page_t* page); // "stats.c" void _mi_stats_done(mi_stats_t* stats); +void _mi_stats_merge_thread(mi_tld_t* tld); void _mi_stats_merge_from(mi_stats_t* to, mi_stats_t* from); mi_msecs_t _mi_clock_now(void); mi_msecs_t _mi_clock_end(mi_msecs_t start); diff --git a/src/heap.c b/src/heap.c index 971aad68..17dd1fdb 100644 --- a/src/heap.c +++ b/src/heap.c @@ -130,9 +130,7 @@ static void mi_heap_collect_ex(mi_heap_t* heap, mi_collect_t collect) _mi_arenas_collect(collect == MI_FORCE /* force purge? */, collect >= MI_FORCE /* visit all? */, heap->tld); // merge statistics - if (collect <= MI_FORCE) { - mi_stats_merge(); - } + if (collect <= MI_FORCE) { _mi_stats_merge_thread(heap->tld); } } void _mi_heap_collect_abandon(mi_heap_t* heap) { diff --git a/src/page-queue.c b/src/page-queue.c index 3e2315cc..91bb0ef9 100644 --- a/src/page-queue.c +++ b/src/page-queue.c @@ -168,8 +168,7 @@ bool _mi_page_queue_is_valid(mi_heap_t* heap, const mi_page_queue_t* pq) { return true; } - -static size_t mi_page_bin(const mi_page_t* page) { +size_t _mi_page_bin(const mi_page_t* page) { const size_t bin = (mi_page_is_in_full(page) ? MI_BIN_FULL : (mi_page_is_huge(page) ? MI_BIN_HUGE : mi_bin(mi_page_block_size(page)))); mi_assert_internal(bin <= MI_BIN_FULL); return bin; @@ -177,7 +176,7 @@ static size_t mi_page_bin(const mi_page_t* page) { static mi_page_queue_t* mi_heap_page_queue_of(mi_heap_t* heap, const mi_page_t* page) { mi_assert_internal(heap!=NULL); - const size_t bin = mi_page_bin(page); + const size_t bin = _mi_page_bin(page); mi_page_queue_t* pq = &heap->pages[bin]; mi_assert_internal((mi_page_block_size(page) == pq->block_size) || (mi_page_is_huge(page) && mi_page_queue_is_huge(pq)) || diff --git a/src/page.c b/src/page.c index 0d8e4e12..103d11b4 100644 --- a/src/page.c +++ b/src/page.c @@ -324,7 +324,7 @@ static mi_page_t* mi_page_fresh_alloc(mi_heap_t* heap, mi_page_queue_t* pq, size } mi_heap_stat_increase(heap, pages, 1); mi_assert_internal(pq!=NULL || mi_page_block_size(page) >= block_size); - mi_heap_stat_increase(heap, page_bins[mi_page_bin(page)], 1); + mi_heap_stat_increase(heap, page_bins[_mi_page_bin(page)], 1); mi_assert_expensive(_mi_page_is_valid(page)); return page; } @@ -395,7 +395,7 @@ void _mi_page_free(mi_page_t* page, mi_page_queue_t* pq) { // and free it mi_heap_t* heap = page->heap; - mi_heap_stat_decrease(heap, page_bins[mi_page_bin(page)], 1); + mi_heap_stat_decrease(heap, page_bins[_mi_page_bin(page)], 1); mi_heap_stat_decrease(heap, pages, 1); mi_page_set_heap(page,NULL); _mi_arenas_page_free(page); diff --git a/src/stats.c b/src/stats.c index 3b53d5a9..93b68054 100644 --- a/src/stats.c +++ b/src/stats.c @@ -406,6 +406,10 @@ void _mi_stats_merge_from(mi_stats_t* to, mi_stats_t* from) { } } +void _mi_stats_merge_thread(mi_tld_t* tld) { + _mi_stats_merge_from( &tld->subproc->stats, &tld->stats ); +} + void _mi_stats_done(mi_stats_t* stats) { // called from `mi_thread_done` _mi_stats_merge_from(&_mi_subproc()->stats, stats); } @@ -519,7 +523,7 @@ static bool mi_heap_buf_expand(mi_heap_buf_t* hbuf) { hbuf->buf[hbuf->size-1] = 0; } if (hbuf->size > SIZE_MAX/2 || !hbuf->can_realloc) return false; - const size_t newsize = (hbuf->size == 0 ? 2*MI_KiB : 2*hbuf->size); + const size_t newsize = (hbuf->size == 0 ? mi_good_size(12*MI_KiB) : 2*hbuf->size); char* const newbuf = (char*)mi_rezalloc(hbuf->buf, newsize); if (newbuf == NULL) return false; hbuf->buf = newbuf; diff --git a/test/test-stress.c b/test/test-stress.c index cd63b05e..ba6270ba 100644 --- a/test/test-stress.c +++ b/test/test-stress.c @@ -374,6 +374,7 @@ int main(int argc, char** argv) { mi_free(json); } #endif + mi_collect(true); mi_stats_print(NULL); #endif //bench_end_program();