bind9/lib/isc
Michał Kępień 7aa7b6474b Prevent memory bloat caused by a jemalloc quirk
Since version 5.0.0, decay-based purging is the only available dirty
page cleanup mechanism in jemalloc.  It relies on so-called tickers,
which are simple data structures used for ensuring that certain actions
are taken "once every N times".  Ticker data (state) is stored in a
thread-specific data structure called tsd in jemalloc parlance.  Ticks
are triggered when extents are allocated and deallocated.  Once every
1000 ticks, jemalloc attempts to release some of the dirty pages hanging
around (if any).  This allows memory use to be kept in check over time.

This dirty page cleanup mechanism has a quirk.  If the first
allocator-related action for a given thread is a free(), a
minimally-initialized tsd is set up which does not include ticker data.
When that thread subsequently calls *alloc(), the tsd transitions to its
nominal state, but due to a certain flag being set during minimal tsd
initialization, ticker data remains unallocated.  This prevents
decay-based dirty page purging from working, effectively enabling memory
exhaustion over time. [1]

The quirk described above has been addressed (by moving ticker state to
a different structure) in jemalloc's development branch [2], but not in
any numbered jemalloc version released to date (the latest one being
5.2.1 as of this writing).

Work around the problem by ensuring that every thread spawned by
isc_thread_create() starts with a malloc() call.  Avoid immediately
calling free() for the dummy allocation to prevent an optimizing
compiler from stripping away the malloc() + free() pair altogether.

An alternative implementation of this workaround was considered that
used a pair of isc_mem_create() + isc_mem_destroy() calls instead of
malloc() + free(), enabling the change to be fully contained within
isc__trampoline_run() (i.e. to not touch struct isc__trampoline), as the
compiler is not allowed to strip away arbitrary function calls.
However, that solution was eventually dismissed as it triggered
ThreadSanitizer reports when tools like dig, nsupdate, or rndc exited
abruptly without waiting for all worker threads to finish their work.

[1] https://github.com/jemalloc/jemalloc/issues/2251
[2] c259323ab3
2022-04-21 14:19:39 +02:00
..
include Add detailed tracing when TASKMGR_TRACE is defined 2022-04-19 14:25:23 +02:00
netmgr Allow listening on less than nworkers threads 2022-04-19 11:08:13 +02:00
tests Allow listening on less than nworkers threads 2022-04-19 11:08:13 +02:00
.gitignore [master] update gitignore files; use rev-parse to get srcid 2014-06-17 13:49:30 -07:00
aes.c Remove EVP_CIPHER_CTX_new() and EVP_CIPHER_CTX_free() shims 2022-03-02 10:48:09 +00:00
app.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
assertions.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
astack.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
backtrace.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
base32.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
base64.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
bind9.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
buffer.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
commandline.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
condition.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
counter.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
crc64.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
dir.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
entropy.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
entropy_private.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
errno.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
errno2result.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
errno2result.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
error.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
event.c Add detailed tracing when TASKMGR_TRACE is defined 2022-04-19 14:25:23 +02:00
file.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fsaccess.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fsaccess_common.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fsaccess_common_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
glob.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
hash.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
heap.c Make isc_heap_create() and isc_heap_insert() return void 2022-03-08 11:19:34 +01:00
hex.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
hmac.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
ht.c Make isc_ht optionally case insensitive 2022-03-28 15:02:18 -07:00
httpd.c Allow listening on less than nworkers threads 2022-04-19 11:08:13 +02:00
interfaceiter.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
iterated_hash.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
jemalloc_shim.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
lex.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
lib.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
log.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
Makefile.am Remove isc_pool API 2022-04-01 23:50:34 +02:00
managers.c Replace netievent lock-free queue with simple locked queue 2022-03-04 13:49:51 +01:00
md.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mem.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
mem_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
meminfo.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mutex.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mutexblock.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
net.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
netaddr.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
netmgr_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
netscope.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
nonce.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
openssl_shim.c Add isc_tlsctx_attach() 2022-04-06 18:45:57 +03:00
openssl_shim.h Add isc_tlsctx_attach() 2022-04-06 18:45:57 +03:00
os.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
os_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
parseint.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
portset.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
quota.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
radix.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
random.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
ratelimiter.c Don't use reference counting in isc_timer unit 2022-04-02 01:23:15 +02:00
regex.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
region.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
resource.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
result.c Add ISC_R_TLSBADPEERCERT error code to the TLS related code 2022-03-28 15:32:30 +03:00
rwlock.c Consistenly use UNREACHABLE() instead of ISC_UNREACHABLE() 2022-03-28 23:26:08 +02:00
safe.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
serial.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
siphash.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
sockaddr.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
stats.c Assert if statistics counter underflows in the developer mode 2022-02-10 17:18:09 +01:00
stdio.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
stdtime.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
string.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
symtab.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
syslog.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
task.c Add detailed tracing when TASKMGR_TRACE is defined 2022-04-19 14:25:23 +02:00
task_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
thread.c Remove unused functions from isc_thread API 2022-02-09 17:22:06 +01:00
time.c Remove use of the inline keyword used as suggestion to compiler 2022-03-25 08:33:43 +01:00
timer.c Unlink the timer event before trying to purge it 2022-04-06 07:33:41 +00:00
timer_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
tls.c Add isc_tlsctx_attach() 2022-04-06 18:45:57 +03:00
tls_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
tm.c Add FALLTHROUGH macro for __attribute__((fallthrough)) 2022-03-25 08:33:43 +01:00
trampoline.c Prevent memory bloat caused by a jemalloc quirk 2022-04-21 14:19:39 +02:00
trampoline_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
url.c Simplify way we tag unreachable code with only ISC_UNREACHABLE() 2022-03-25 08:33:43 +01:00
utf8.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00