merge from dev

This commit is contained in:
Daan 2025-05-21 15:13:54 -07:00
commit f2c9967a6e
6 changed files with 13 additions and 9 deletions

View file

@ -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) {

View file

@ -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)) ||

View file

@ -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);

View file

@ -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;