]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: pools: always pre-initialize allocated memory outside of the lock
authorWilly Tarreau <w@1wt.eu>
Thu, 4 Jul 2019 09:48:16 +0000 (11:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 9 Jul 2019 08:40:33 +0000 (10:40 +0200)
commit828675421e32d136c35d27d26e4ee5d24d5b440c
tree7765ef5334d1786857c62ef74833c3e49db59de3
parent3e853ea74dcf9040fc684332d41b306212252057
MINOR: pools: always pre-initialize allocated memory outside of the lock

When calling mmap(), in general the system gives us a page but does not
really allocate it until we first dereference it. And it turns out that
this time is much longer than the time to perform the mmap() syscall.
Unfortunately, when running with memory debugging enabled, we mmap/munmap()
each object resulting in lots of such calls and a high contention on the
allocator. And the first accesses to the page being done under the pool
lock is extremely damaging to other threads.

The simple fact of writing a 0 at the beginning of the page after
allocating it and placing the POOL_LINK pointer outside of the lock is
enough to boost the performance by 8x in debug mode and to save the
watchdog from triggering on lock contention. This is what this patch
does.
include/common/memory.h
src/memory.c