mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-03 22:19:32 +03:00
merge from dev
This commit is contained in:
commit
cd6737a1ee
3 changed files with 26 additions and 23 deletions
|
@ -155,7 +155,7 @@ size_t _mi_commit_mask_next_run(const mi_commit_mask_t* cm, size_t* idx) {
|
|||
Each thread owns its own segments.
|
||||
|
||||
Currently we have:
|
||||
- small pages (64KiB)
|
||||
- small pages (64KiB)
|
||||
- medium pages (512KiB)
|
||||
- large pages (4MiB),
|
||||
- huge segments have 1 page in one segment that can be larger than `MI_SEGMENT_SIZE`.
|
||||
|
@ -975,7 +975,7 @@ static void mi_segment_free(mi_segment_t* segment, bool force, mi_segments_tld_t
|
|||
mi_assert_internal(segment != NULL);
|
||||
mi_assert_internal(segment->next == NULL);
|
||||
mi_assert_internal(segment->used == 0);
|
||||
|
||||
|
||||
// in `mi_segment_force_abandon` we set this to true to ensure the segment's memory stays valid
|
||||
if (segment->dont_free) return;
|
||||
|
||||
|
@ -1000,7 +1000,7 @@ static void mi_segment_free(mi_segment_t* segment, bool force, mi_segments_tld_t
|
|||
mi_assert_internal(page_count == 2); // first page is allocated by the segment itself
|
||||
|
||||
// stats
|
||||
_mi_stat_decrease(&tld->stats->page_committed, mi_segment_info_size(segment));
|
||||
// _mi_stat_decrease(&tld->stats->page_committed, mi_segment_info_size(segment));
|
||||
|
||||
// return it to the OS
|
||||
mi_segment_os_free(segment, tld);
|
||||
|
|
36
src/stats.c
36
src/stats.c
|
@ -38,10 +38,8 @@ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) {
|
|||
else {
|
||||
// add thread local
|
||||
stat->current += amount;
|
||||
if (stat->current > stat->peak) stat->peak = stat->current;
|
||||
if (amount > 0) {
|
||||
stat->total += amount;
|
||||
}
|
||||
if (stat->current > stat->peak) { stat->peak = stat->current; }
|
||||
if (amount > 0) { stat->total += amount; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,16 +65,17 @@ void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount) {
|
|||
// must be thread safe as it is called from stats_merge
|
||||
static void mi_stat_add(mi_stat_count_t* stat, const mi_stat_count_t* src) {
|
||||
if (stat==src) return;
|
||||
if (src->total==0) return;
|
||||
mi_atomic_addi64_relaxed( &stat->total, src->total);
|
||||
mi_atomic_addi64_relaxed( &stat->current, src->current);
|
||||
if (src->total!=0) { mi_atomic_addi64_relaxed(&stat->total, src->total); }
|
||||
if (src->current!=0) { mi_atomic_addi64_relaxed(&stat->current, src->current); }
|
||||
// peak scores do really not work across threads ... we use conservative max
|
||||
mi_atomic_maxi64_relaxed( &stat->peak, src->peak); // or: mi_atomic_addi64_relaxed( &stat->peak, src->peak);
|
||||
if (src->peak > stat->peak) {
|
||||
mi_atomic_maxi64_relaxed(&stat->peak, src->peak); // or: mi_atomic_addi64_relaxed( &stat->peak, src->peak);
|
||||
}
|
||||
}
|
||||
|
||||
static void mi_stat_counter_add(mi_stat_counter_t* stat, const mi_stat_counter_t* src) {
|
||||
if (stat==src) return;
|
||||
mi_atomic_addi64_relaxed( &stat->total, src->total);
|
||||
if (src->total!=0) { mi_atomic_addi64_relaxed(&stat->total, src->total); }
|
||||
}
|
||||
|
||||
// must be thread safe as it is called from stats_merge
|
||||
|
@ -109,15 +108,15 @@ static void mi_stats_add(mi_stats_t* stats, const mi_stats_t* src) {
|
|||
mi_stat_counter_add(&stats->page_no_retire, &src->page_no_retire);
|
||||
mi_stat_counter_add(&stats->searches, &src->searches);
|
||||
mi_stat_counter_add(&stats->normal_count, &src->normal_count);
|
||||
mi_stat_counter_add(&stats->huge_count, &src->huge_count);
|
||||
mi_stat_counter_add(&stats->huge_count, &src->huge_count);
|
||||
mi_stat_counter_add(&stats->large_count, &src->large_count);
|
||||
mi_stat_counter_add(&stats->guarded_alloc_count, &src->guarded_alloc_count);
|
||||
|
||||
#if MI_STAT>1
|
||||
for (size_t i = 0; i <= MI_BIN_HUGE; i++) {
|
||||
if (src->normal_bins[i].total > 0) {
|
||||
mi_stat_add(&stats->normal_bins[i], &src->normal_bins[i]);
|
||||
}
|
||||
// if (src->normal_bins[i].total != 0 && src->normal_bins[i].current != 0) {
|
||||
mi_stat_add(&stats->normal_bins[i], &src->normal_bins[i]);
|
||||
//}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -308,24 +307,23 @@ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0)
|
|||
#endif
|
||||
#if MI_STAT
|
||||
mi_stat_print(&stats->normal, "normal", (stats->normal_count.total == 0 ? 1 : -1), out, arg);
|
||||
mi_stat_print(&stats->huge, "large", (stats->large_count.total == 0 ? 1 : -1), out, arg);
|
||||
mi_stat_print(&stats->huge, "huge", (stats->huge_count.total == 0 ? 1 : -1), out, arg);
|
||||
mi_stat_print(&stats->large, "large", (stats->large_count.total == 0 ? 1 : -1), out, arg);
|
||||
mi_stat_print(&stats->huge, "huge", (stats->huge_count.total == 0 ? 1 : -1), out, arg);
|
||||
mi_stat_count_t total = { 0,0,0 };
|
||||
mi_stat_add(&total, &stats->normal);
|
||||
mi_stat_add(&total, &stats->large);
|
||||
mi_stat_add(&total, &stats->huge);
|
||||
|
||||
mi_stat_print(&total, "total", 1, out, arg);
|
||||
mi_stat_print_ex(&total, "total", 1, out, arg, "");
|
||||
#endif
|
||||
#if MI_STAT>1
|
||||
mi_stat_print(&stats->malloc, "malloc req", 1, out, arg);
|
||||
mi_stat_print_ex(&stats->malloc, "malloc req", 1, out, arg, "");
|
||||
_mi_fprintf(out, arg, "\n");
|
||||
#endif
|
||||
mi_stat_print_ex(&stats->reserved, "reserved", 1, out, arg, "");
|
||||
mi_stat_print_ex(&stats->committed, "committed", 1, out, arg, "");
|
||||
mi_stat_peak_print(&stats->reset, "reset", 1, out, arg );
|
||||
mi_stat_peak_print(&stats->purged, "purged", 1, out, arg );
|
||||
mi_stat_print(&stats->page_committed, "touched", 1, out, arg);
|
||||
mi_stat_print_ex(&stats->page_committed, "touched", 1, out, arg, "");
|
||||
mi_stat_print(&stats->segments, "segments", -1, out, arg);
|
||||
mi_stat_print(&stats->segments_abandoned, "-abandoned", -1, out, arg);
|
||||
mi_stat_print(&stats->segments_cache, "-cached", -1, out, arg);
|
||||
|
|
|
@ -116,7 +116,7 @@ static void* alloc_items(size_t items, random_t r) {
|
|||
else if (chance(10, r) && allow_large_objects) items *= 1000; // 0.1% huge
|
||||
else items *= 100; // 1% large objects;
|
||||
}
|
||||
if (items == 40) items++; // pthreads uses that size for stack increases
|
||||
if (items>=32 && items<=40) items*=2; // pthreads uses 320b allocations (this shows that more clearly in the stats)
|
||||
if (use_one_size > 0) items = (use_one_size / sizeof(uintptr_t));
|
||||
if (items==0) items = 1;
|
||||
uintptr_t* p = (uintptr_t*)custom_calloc(items,sizeof(uintptr_t));
|
||||
|
@ -306,6 +306,11 @@ int main(int argc, char** argv) {
|
|||
allow_large_objects = true;
|
||||
}
|
||||
printf("Using %d threads with a %d%% load-per-thread and %d iterations %s\n", THREADS, SCALE, ITER, (allow_large_objects ? "(allow large objects)" : ""));
|
||||
|
||||
#if !defined(NDEBUG) && !defined(USE_STD_MALLOC)
|
||||
mi_stats_reset();
|
||||
#endif
|
||||
|
||||
//mi_reserve_os_memory(1024*1024*1024ULL, false, true);
|
||||
//int res = mi_reserve_huge_os_pages(4,1);
|
||||
//printf("(reserve huge: %i\n)", res);
|
||||
|
|
Loading…
Add table
Reference in a new issue