2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Refactor the handling of isc_mem overmem condition

Previously, there were two methods of working with the overmem
condition:

1. hi/lo water callback - when the overmem condition was reached
   for the first time, the water callback was called with HIWATER
   mark and .is_overmem boolean was set internally.  Similarly,
   when the used memory went below the lo water mark, the water
   callback would be called with LOWATER mark and .is_overmem
   was reset.  This check would be called **every** time memory
   was allocated or freed.

2. isc_mem_isovermem() - a simple getter for the internal
   .is_overmem flag

This commit refactors removes the first method and move the hi/lo water
checks to the isc_mem_isovermem() function, thus we now have only a
single method of checking overmem condition and the check for hi/lo
water is removed from the hot path for memory contexts that doesn't use
overmem checks.
This commit is contained in:
Ondřej Surý
2023-11-29 09:01:56 +01:00
parent 669800342d
commit 14bdd21e0a
5 changed files with 63 additions and 207 deletions

View File

@@ -239,13 +239,6 @@ dns_cache_getname(dns_cache_t *cache) {
return (cache->name);
}
/* This is a no-op, but has to exist for isc_mem_setwater(). */
static void
water(void *arg, int mark) {
UNUSED(arg);
UNUSED(mark);
}
void
dns_cache_setcachesize(dns_cache_t *cache, size_t size) {
REQUIRE(VALID_CACHE(cache));
@@ -267,7 +260,7 @@ dns_cache_setcachesize(dns_cache_t *cache, size_t size) {
if (size == 0U || hi == 0U || lo == 0U) {
isc_mem_clearwater(cache->mctx);
} else {
isc_mem_setwater(cache->mctx, water, cache, hi, lo);
isc_mem_setwater(cache->mctx, hi, lo);
}
}