improve precision of malloc_huge statistic by always using the global os stats

This commit is contained in:
Daan 2025-06-03 13:36:05 -07:00
parent 2157947ecf
commit 86757dfbd6
3 changed files with 8 additions and 14 deletions

View file

@ -817,20 +817,17 @@ void _mi_arenas_page_free(mi_page_t* page, mi_tld_t* stats_tld /* can be NULL */
mi_assert_internal(page->next==NULL && page->prev==NULL);
// statistics
const size_t block_size = mi_page_block_size(page);
if (stats_tld != NULL) {
mi_tld_stat_decrease(stats_tld, page_bins[_mi_page_bin(page)], 1);
mi_tld_stat_decrease(stats_tld, pages, 1);
if (block_size > MI_LARGE_MAX_OBJ_SIZE) {
mi_tld_stat_decrease(stats_tld, malloc_huge, block_size);
}
}
else {
mi_os_stat_decrease(page_bins[_mi_page_bin(page)], 1);
mi_os_stat_decrease(pages, 1);
if (block_size > MI_LARGE_MAX_OBJ_SIZE) {
mi_os_stat_decrease(malloc_huge, block_size);
}
}
const size_t block_size = mi_page_block_size(page);
if (mi_page_is_huge(page)) {
mi_os_stat_decrease(malloc_huge, block_size);
}
// assertions

View file

@ -329,14 +329,11 @@ static bool _mi_heap_page_destroy(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_
//_mi_page_use_delayed_free(page, MI_NEVER_DELAYED_FREE, false);
// stats
const size_t bsize = mi_page_block_size(page);
if (bsize > MI_LARGE_MAX_OBJ_SIZE) {
mi_heap_stat_decrease(heap, malloc_huge, bsize);
}
#if (MI_STAT)
_mi_page_free_collect(page, false); // update used count
const size_t inuse = page->used;
const size_t bsize = mi_page_block_size(page);
if (bsize <= MI_LARGE_MAX_OBJ_SIZE) {
const size_t inuse = page->used;
mi_heap_stat_decrease(heap, malloc_normal, bsize * inuse);
#if (MI_STAT>1)
mi_heap_stat_decrease(heap, malloc_bins[_mi_bin(bsize)], inuse);

View file

@ -905,8 +905,8 @@ static mi_page_t* mi_huge_page_alloc(mi_heap_t* heap, size_t size, size_t page_a
mi_assert_internal(mi_page_is_abandoned(page));
mi_page_set_heap(page, NULL);
#endif
mi_heap_stat_increase(heap, malloc_huge, mi_page_block_size(page));
mi_heap_stat_counter_increase(heap, malloc_huge_count, 1);
mi_os_stat_increase(malloc_huge, mi_page_block_size(page));
mi_os_stat_counter_increase(malloc_huge_count, 1);
}
return page;
}