From 819e809be59d646de5f7fdb110dc2e54e067807e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Wed, 15 Jan 2025 10:36:33 +0100 Subject: [PATCH] Remove memory limit on ADB finds and fetches Address Database (ADB) shares the memory for the short lived ADB objects (finds, fetches, addrinfo) and the long lived ADB objects (names, entries, namehooks). This could lead to a situation where the resolver-heavy load would force evict ADB objects from the database to point where ADB is completely empty, leading to even more resolver-heavy load. Make the short lived ADB objects use the other memory context that we already created for the hashmaps. This makes the ADB overmem condition to not be triggered by the ongoing resolver fetches. (cherry picked from commit 05faff6d5306de1e57b56f9ea44469bfb111e2e3) --- lib/dns/adb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/dns/adb.c b/lib/dns/adb.c index e112c14cfe..281377e376 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -1114,7 +1114,7 @@ static dns_adbfind_t * new_adbfind(dns_adb_t *adb, in_port_t port) { dns_adbfind_t *find = NULL; - find = isc_mem_get(adb->mctx, sizeof(*find)); + find = isc_mem_get(adb->hmctx, sizeof(*find)); *find = (dns_adbfind_t){ .port = port, .result_v4 = ISC_R_UNEXPECTED, @@ -1153,7 +1153,7 @@ free_adbfind(dns_adbfind_t **findp) { isc_mutex_destroy(&find->lock); - isc_mem_put(adb->mctx, find, sizeof(*find)); + isc_mem_put(adb->hmctx, find, sizeof(*find)); dns_adb_detach(&adb); } @@ -1161,7 +1161,7 @@ static dns_adbfetch_t * new_adbfetch(dns_adb_t *adb) { dns_adbfetch_t *fetch = NULL; - fetch = isc_mem_get(adb->mctx, sizeof(*fetch)); + fetch = isc_mem_get(adb->hmctx, sizeof(*fetch)); *fetch = (dns_adbfetch_t){ 0 }; dns_rdataset_init(&fetch->rdataset); @@ -1185,7 +1185,7 @@ free_adbfetch(dns_adb_t *adb, dns_adbfetch_t **fetchp) { dns_rdataset_disassociate(&fetch->rdataset); } - isc_mem_put(adb->mctx, fetch, sizeof(*fetch)); + isc_mem_put(adb->hmctx, fetch, sizeof(*fetch)); } /* @@ -1196,7 +1196,7 @@ static dns_adbaddrinfo_t * new_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) { dns_adbaddrinfo_t *ai = NULL; - ai = isc_mem_get(adb->mctx, sizeof(*ai)); + ai = isc_mem_get(adb->hmctx, sizeof(*ai)); *ai = (dns_adbaddrinfo_t){ .srtt = atomic_load(&entry->srtt), .flags = atomic_load(&entry->flags), @@ -1229,7 +1229,7 @@ free_adbaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **ainfo) { } dns_adbentry_detach(&ai->entry); - isc_mem_put(adb->mctx, ai, sizeof(*ai)); + isc_mem_put(adb->hmctx, ai, sizeof(*ai)); } static bool @@ -1866,7 +1866,7 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, dns_adb_t **newadb) { isc_mem_attach(mem, &adb->mctx); isc_mem_create(&adb->hmctx); - isc_mem_setname(adb->hmctx, "ADB_hashmaps"); + isc_mem_setname(adb->hmctx, "ADB_dynamic"); isc_hashmap_create(adb->hmctx, ADB_HASH_BITS, &adb->names); isc_rwlock_init(&adb->names_lock);