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.
This commit is contained in:
parent
190f81c6d5
commit
bbff6ca674
13
src/stats.c
13
src/stats.c
@ -133,8 +133,16 @@ stats_arena_bins_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
availregs = nregs * curslabs;
|
availregs = nregs * curslabs;
|
||||||
milli = (availregs != 0) ? (1000 * curregs) / availregs
|
milli = (availregs != 0) ? (1000 * curregs) / availregs
|
||||||
: 1000;
|
: 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),
|
malloc_snprintf(util, sizeof(util),
|
||||||
"0.00%zu", milli);
|
"0.00%zu", milli);
|
||||||
} else if (milli < 100) {
|
} 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",
|
malloc_snprintf(util, sizeof(util), "0.%zu",
|
||||||
milli);
|
milli);
|
||||||
} else {
|
} else {
|
||||||
|
assert(milli == 1000);
|
||||||
malloc_snprintf(util, sizeof(util), "1");
|
malloc_snprintf(util, sizeof(util), "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user