Skip to content

Commit 9e70ca4

Browse files
committed
address PR #1188 by @bazineta; fixes #1147 and #1151
1 parent 236ae0b commit 9e70ca4

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

include/mimalloc-stats.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ terms of the MIT license. A copy of the license can be found in the file
1111
#include <mimalloc.h>
1212
#include <stdint.h>
1313

14-
#define MI_STAT_VERSION 1 // increased on every backward incompatible change
14+
#define MI_STAT_VERSION 3 // increased on every backward incompatible change
1515

1616
// count allocation over time
1717
typedef struct mi_stat_count_s {
@@ -29,8 +29,8 @@ typedef struct mi_stat_counter_s {
2929
MI_STAT_COUNT(pages) /* count of mimalloc pages */ \
3030
MI_STAT_COUNT(reserved) /* reserved memory bytes */ \
3131
MI_STAT_COUNT(committed) /* committed bytes */ \
32-
MI_STAT_COUNT(reset) /* reset bytes */ \
33-
MI_STAT_COUNT(purged) /* purged bytes */ \
32+
MI_STAT_COUNTER(reset) /* reset bytes */ \
33+
MI_STAT_COUNTER(purged) /* purged bytes */ \
3434
MI_STAT_COUNT(page_committed) /* committed memory inside pages */ \
3535
MI_STAT_COUNT(pages_abandoned) /* abandonded pages count */ \
3636
MI_STAT_COUNT(threads) /* number of threads */ \
@@ -52,7 +52,8 @@ typedef struct mi_stat_counter_s {
5252
MI_STAT_COUNTER(arena_purges) \
5353
MI_STAT_COUNTER(pages_extended) /* number of page extensions */ \
5454
MI_STAT_COUNTER(pages_retire) /* number of pages that are retired */ \
55-
MI_STAT_COUNTER(page_searches) /* searches for a fresh page */ \
55+
MI_STAT_COUNTER(page_searches) /* total pages searched for a fresh page */ \
56+
MI_STAT_COUNTER(page_searches_count) /* searched count for a fresh page */ \
5657
/* only on v1 and v2 */ \
5758
MI_STAT_COUNT(segments) \
5859
MI_STAT_COUNT(segments_abandoned) \

src/init.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ const mi_page_t _mi_page_empty = {
7070

7171
// Empty statistics
7272
#define MI_STATS_NULL \
73-
MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), \
74-
MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), \
73+
MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), \
74+
{ 0 }, { 0 }, \
75+
MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), \
7576
MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), MI_STAT_COUNT_NULL(), \
7677
{ 0 }, { 0 }, { 0 }, { 0 }, \
7778
{ 0 }, { 0 }, { 0 }, { 0 }, \
7879
\
79-
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, \
80+
{ 0 }, { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, \
8081
MI_INIT4(MI_STAT_COUNT_NULL), \
8182
{ 0 }, { 0 }, { 0 }, { 0 }, \
8283
\

src/os.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ bool _mi_os_reset(void* addr, size_t size) {
528528
size_t csize;
529529
void* start = mi_os_page_align_area_conservative(addr, size, &csize);
530530
if (csize == 0) return true; // || _mi_os_is_huge_reserved(addr)
531-
mi_os_stat_increase(reset, csize);
531+
mi_os_stat_counter_increase(reset, csize);
532532
mi_os_stat_counter_increase(reset_calls, 1);
533533

534534
#if (MI_DEBUG>1) && !MI_SECURE && !MI_TRACK_ENABLED // && !MI_TSAN
@@ -560,7 +560,7 @@ bool _mi_os_purge_ex(void* p, size_t size, bool allow_reset, size_t stat_size)
560560
{
561561
if (mi_option_get(mi_option_purge_delay) < 0) return false; // is purging allowed?
562562
mi_os_stat_counter_increase(purge_calls, 1);
563-
mi_os_stat_increase(purged, size);
563+
mi_os_stat_counter_increase(purged, size);
564564

565565
if (mi_option_is_enabled(mi_option_purge_decommits) && // should decommit?
566566
!_mi_preloading()) // don't decommit during preloading (unsafe)

src/page.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ static mi_page_t* mi_page_queue_find_free_ex(mi_heap_t* heap, mi_page_queue_t* p
815815
} // for each page
816816

817817
mi_heap_stat_counter_increase(heap, page_searches, count);
818+
mi_heap_stat_counter_increase(heap, page_searches_count, 1);
818819

819820
// set the page to the best candidate
820821
if (page_candidate != NULL) {

src/stats.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,6 @@ static void mi_stat_print(const mi_stat_count_t* stat, const char* msg, int64_t
216216
mi_stat_print_ex(stat, msg, unit, out, arg, NULL);
217217
}
218218

219-
static void mi_stat_peak_print(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg) {
220-
_mi_fprintf(out, arg, "%10s:", msg);
221-
mi_print_amount(stat->peak, unit, out, arg);
222-
_mi_fprintf(out, arg, "\n");
223-
}
224-
225219
#if MI_STAT>1
226220
static void mi_stat_total_print(const mi_stat_count_t* stat, const char* msg, int64_t unit, mi_output_fun* out, void* arg) {
227221
_mi_fprintf(out, arg, "%10s:", msg);
@@ -238,8 +232,8 @@ static void mi_stat_counter_print(const mi_stat_counter_t* stat, const char* msg
238232
}
239233

240234

241-
static void mi_stat_counter_print_avg(const mi_stat_counter_t* stat, const char* msg, mi_output_fun* out, void* arg) {
242-
const int64_t avg_tens = (stat->total == 0 ? 0 : (stat->total*10 / stat->total));
235+
static void mi_stat_average_print(size_t count, size_t total, const char* msg, mi_output_fun* out, void* arg) {
236+
const int64_t avg_tens = (count == 0 ? 0 : (total*10 / count));
243237
const long avg_whole = (long)(avg_tens/10);
244238
const long avg_frac1 = (long)(avg_tens%10);
245239
_mi_fprintf(out, arg, "%10s: %5ld.%ld avg\n", msg, avg_whole, avg_frac1);
@@ -332,8 +326,8 @@ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0)
332326
#endif
333327
mi_stat_print_ex(&stats->reserved, "reserved", 1, out, arg, "");
334328
mi_stat_print_ex(&stats->committed, "committed", 1, out, arg, "");
335-
mi_stat_peak_print(&stats->reset, "reset", 1, out, arg );
336-
mi_stat_peak_print(&stats->purged, "purged", 1, out, arg );
329+
mi_stat_counter_print(&stats->reset, "reset", out, arg );
330+
mi_stat_counter_print(&stats->purged, "purged", out, arg );
337331
mi_stat_print_ex(&stats->page_committed, "touched", 1, out, arg, "");
338332
mi_stat_print(&stats->segments, "segments", -1, out, arg);
339333
mi_stat_print(&stats->segments_abandoned, "-abandoned", -1, out, arg);
@@ -351,7 +345,7 @@ static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0)
351345
mi_stat_counter_print(&stats->purge_calls, "purges", out, arg);
352346
mi_stat_counter_print(&stats->malloc_guarded_count, "guarded", out, arg);
353347
mi_stat_print(&stats->threads, "threads", -1, out, arg);
354-
mi_stat_counter_print_avg(&stats->page_searches, "searches", out, arg);
348+
mi_stat_average_print(stats->page_searches_count.total, stats->page_searches.total, "searches", out, arg);
355349
_mi_fprintf(out, arg, "%10s: %5i\n", "numa nodes", _mi_os_numa_node_count());
356350

357351
size_t elapsed;

0 commit comments

Comments
 (0)