]> git.ipfire.org Git - thirdparty/bind9.git/commit
Change the .inuse member of isc_mem to be per-thread/per-loop
authorOndřej Surý <ondrej@isc.org>
Wed, 4 Jun 2025 16:14:23 +0000 (18:14 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 30 Jun 2025 11:23:17 +0000 (13:23 +0200)
commit5eec9a2ebb47ca0be513d415bba882744c1d2ed1
tree66bfc04c9e59f3fb445177cb806cc8627a7c6042
parentf9528b88aea6f84c3c7f5c61d9e0cadb61d99c59
Change the .inuse member of isc_mem to be per-thread/per-loop

The .inuse member was causing a lot of contention between threads using
the same memory context.  Scather the .inuse and .overmem members of
isc_mem_t structure to be an per-tid array of variables to reduce the
contention as the writes are now independent of each other.

The array uses one tad bit nasty trick, as ISC_TID_UNKNOWN is now -1,
the array has been sized to fit the unknown tid with [-1] index into the
array accomplished with `ctx->stat = &ctx->stat_s[1];`.  It will not win
a beauty contest, but it works seamlessly by just passing `isc_tid()` as
an index into the array.

The caveat here is that gathering the real inuse value requires walking
the whole array for all registered tid values (isc_tid_count()).  The
gather part happens only when statistics are being gathered or when
isc_mem_isovermem() is called.  As the isc_mem_isovermem() call happens
only when new data is being added to cache or ADB, it doesn't happen on
the hottest (read-only) path and according to the measurements, it
doesn't slow down neither the cold cache nor the hot cache latency.
lib/isc/mem.c