mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 01:59:26 +00:00
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.