]> git.ipfire.org Git - thirdparty/glibc.git/commit
Use relaxed atomics for malloc have_fastchunks
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 16 Nov 2017 06:51:27 +0000 (12:21 +0530)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 16 Nov 2017 06:51:27 +0000 (12:21 +0530)
commitaa5be982ea1f59ee1e479fe9a561aeafd91a2261
treed41857510aec530364bd46c763409f92b1f255c5
parentade53e0df7a1257c54ce96e01fa659b374db2117
Use relaxed atomics for malloc have_fastchunks

Currently free typically uses 2 atomic operations per call.  The have_fastchunks
flag indicates whether there are recently freed blocks in the fastbins.  This
is purely an optimization to avoid calling malloc_consolidate too often and
avoiding the overhead of walking all fast bins even if all are empty during a
sequence of allocations.  However using catomic_or to update the flag is
completely unnecessary since it can be changed into a simple boolean and
accessed using relaxed atomics.  There is no change in multi-threaded behaviour
given the flag is already approximate (it may be set when there are no blocks in
any fast bins, or it may be clear when there are free blocks that could be
consolidated).

Performance of malloc/free improves by 27% on a simple benchmark on AArch64
(both single and multithreaded). The number of load/store exclusive instructions
is reduced by 33%. Bench-malloc-thread speeds up by ~3% in all cases.

* malloc/malloc.c (FASTCHUNKS_BIT): Remove.
(have_fastchunks): Remove.
(clear_fastchunks): Remove.
(set_fastchunks): Remove.
(malloc_state): Add have_fastchunks.
(malloc_init_state): Use have_fastchunks.
(do_check_malloc_state): Remove incorrect invariant checks.
(_int_malloc): Use have_fastchunks.
(_int_free): Likewise.
(malloc_consolidate): Likewise.

(cherry-picked from e956075a5a2044d05ce48b905b10270ed4a63e87)
ChangeLog
malloc/malloc.c