malloc: stop reading the subzone if MALLOC_DEBUG_MAXZONES == 1 (the default)
authormjg <mjg@FreeBSD.org>
Mon, 23 Apr 2018 22:28:49 +0000 (22:28 +0000)
committermjg <mjg@FreeBSD.org>
Mon, 23 Apr 2018 22:28:49 +0000 (22:28 +0000)
commitef181e1503d660f1aee474030fe99e31abede7a8
tree4932fc7b1a442dbabfed90787c7514ee416e6581
parent9a0f94467e44a8ab1acf4f10d194108c666df682
malloc: stop reading the subzone if MALLOC_DEBUG_MAXZONES == 1 (the default)

malloc was showing at the top of profile during while running microbenchmarks.

#define DTMALLOC_PROBE_MAX              2
struct malloc_type_internal {
        uint32_t        mti_probes[DTMALLOC_PROBE_MAX];
        u_char          mti_zone;
        struct malloc_type_stats        mti_stats[MAXCPU];
};

Reading mti_zone it wastes a cacheline to hold mti_probes + mti_zone
(which we know is 0) + part of malloc stats of the first cpu which on top
induces false-sharing.

In particular will-it-scale lock1_processes -t 128 -s 10:
before: average:45879692
after:  average:51655596

Note the counters can be padded but the right fix is to move them to
counter(9), leaving the struct read-only after creation (modulo dtrace
probes).
sys/kern/kern_malloc.c