mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-01 17:24:38 +03:00
merge from dev
This commit is contained in:
commit
f2c9967a6e
6 changed files with 13 additions and 9 deletions
|
@ -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);
|
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);
|
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(size_t bin); // for stats
|
||||||
size_t _mi_bin(size_t size); // 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"
|
// "stats.c"
|
||||||
void _mi_stats_done(mi_stats_t* stats);
|
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);
|
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_now(void);
|
||||||
mi_msecs_t _mi_clock_end(mi_msecs_t start);
|
mi_msecs_t _mi_clock_end(mi_msecs_t start);
|
||||||
|
|
|
@ -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);
|
_mi_arenas_collect(collect == MI_FORCE /* force purge? */, collect >= MI_FORCE /* visit all? */, heap->tld);
|
||||||
|
|
||||||
// merge statistics
|
// merge statistics
|
||||||
if (collect <= MI_FORCE) {
|
if (collect <= MI_FORCE) { _mi_stats_merge_thread(heap->tld); }
|
||||||
mi_stats_merge();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _mi_heap_collect_abandon(mi_heap_t* heap) {
|
void _mi_heap_collect_abandon(mi_heap_t* heap) {
|
||||||
|
|
|
@ -168,8 +168,7 @@ bool _mi_page_queue_is_valid(mi_heap_t* heap, const mi_page_queue_t* pq) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t _mi_page_bin(const mi_page_t* page) {
|
||||||
static 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))));
|
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);
|
mi_assert_internal(bin <= MI_BIN_FULL);
|
||||||
return bin;
|
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) {
|
static mi_page_queue_t* mi_heap_page_queue_of(mi_heap_t* heap, const mi_page_t* page) {
|
||||||
mi_assert_internal(heap!=NULL);
|
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_page_queue_t* pq = &heap->pages[bin];
|
||||||
mi_assert_internal((mi_page_block_size(page) == pq->block_size) ||
|
mi_assert_internal((mi_page_block_size(page) == pq->block_size) ||
|
||||||
(mi_page_is_huge(page) && mi_page_queue_is_huge(pq)) ||
|
(mi_page_is_huge(page) && mi_page_queue_is_huge(pq)) ||
|
||||||
|
|
|
@ -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_heap_stat_increase(heap, pages, 1);
|
||||||
mi_assert_internal(pq!=NULL || mi_page_block_size(page) >= block_size);
|
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));
|
mi_assert_expensive(_mi_page_is_valid(page));
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ void _mi_page_free(mi_page_t* page, mi_page_queue_t* pq) {
|
||||||
|
|
||||||
// and free it
|
// and free it
|
||||||
mi_heap_t* heap = page->heap;
|
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_heap_stat_decrease(heap, pages, 1);
|
||||||
mi_page_set_heap(page,NULL);
|
mi_page_set_heap(page,NULL);
|
||||||
_mi_arenas_page_free(page);
|
_mi_arenas_page_free(page);
|
||||||
|
|
|
@ -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`
|
void _mi_stats_done(mi_stats_t* stats) { // called from `mi_thread_done`
|
||||||
_mi_stats_merge_from(&_mi_subproc()->stats, stats);
|
_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;
|
hbuf->buf[hbuf->size-1] = 0;
|
||||||
}
|
}
|
||||||
if (hbuf->size > SIZE_MAX/2 || !hbuf->can_realloc) return false;
|
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);
|
char* const newbuf = (char*)mi_rezalloc(hbuf->buf, newsize);
|
||||||
if (newbuf == NULL) return false;
|
if (newbuf == NULL) return false;
|
||||||
hbuf->buf = newbuf;
|
hbuf->buf = newbuf;
|
||||||
|
|
|
@ -374,6 +374,7 @@ int main(int argc, char** argv) {
|
||||||
mi_free(json);
|
mi_free(json);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
mi_collect(true);
|
||||||
mi_stats_print(NULL);
|
mi_stats_print(NULL);
|
||||||
#endif
|
#endif
|
||||||
//bench_end_program();
|
//bench_end_program();
|
||||||
|
|
Loading…
Add table
Reference in a new issue