summaryrefslogtreecommitdiffstats
path: root/src/stats.c
diff options
context:
space:
mode:
authorQi Wang <interwq@gwu.edu>2017-01-30 23:54:16 (GMT)
committerQi Wang <interwq@gmail.com>2017-02-01 23:17:39 (GMT)
commitbbff6ca6740c27737378f6c2dec3a13053a5a150 (patch)
tree681586ef3f2d17ed3450f52d84284eb5279566ee /src/stats.c
parent190f81c6d5676efd321701dd9b8918a24da2f783 (diff)
downloadjemalloc-bbff6ca6740c27737378f6c2dec3a13053a5a150.zip
jemalloc-bbff6ca6740c27737378f6c2dec3a13053a5a150.tar.gz
jemalloc-bbff6ca6740c27737378f6c2dec3a13053a5a150.tar.bz2
Handle race in stats_arena_bins_print
When multiple threads calling stats_print, race could happen as we read the counters in separate mallctl calls; and the removed assertion could fail when other operations happened in between the mallctl calls. For simplicity, output "race" in the utilization field in this case.
Diffstat (limited to 'src/stats.c')
-rw-r--r--src/stats.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/stats.c b/src/stats.c
index 2a424a7..ae360e1 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -133,8 +133,16 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
availregs = nregs * curslabs;
milli = (availregs != 0) ? (1000 * curregs) / availregs
: 1000;
- assert(milli <= 1000);
- if (milli < 10) {
+
+ if (milli > 1000) {
+ /*
+ * Race detected: the counters were read in
+ * separate mallctl calls and concurrent
+ * operations happened in between. In this case
+ * no meaningful utilization can be computed.
+ */
+ malloc_snprintf(util, sizeof(util), " race");
+ } else if (milli < 10) {
malloc_snprintf(util, sizeof(util),
"0.00%zu", milli);
} else if (milli < 100) {
@@ -144,6 +152,7 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
malloc_snprintf(util, sizeof(util), "0.%zu",
milli);
} else {
+ assert(milli == 1000);
malloc_snprintf(util, sizeof(util), "1");
}