From: Ondřej Surý Date: Wed, 14 Jan 2026 15:35:27 +0000 (+0100) Subject: Remove the heap memory context from QPcache X-Git-Tag: v9.21.21~3^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4891a6b14fe72ba92a2765d98ea936bec34ccaca;p=thirdparty%2Fbind9.git Remove the heap memory context from QPcache The heaps have been removed, so the separate heap memory context (hmctx) is no longer needed. Remove it from both dns_cache and dns_qpcache, along with the HeapMemInUse statistics. --- diff --git a/lib/dns/cache.c b/lib/dns/cache.c index e9c904eda00..e60eadfb44e 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -67,7 +67,6 @@ struct dns_cache { unsigned int magic; isc_mutex_t lock; isc_mem_t *mctx; /* Memory context for the dns_cache object */ - isc_mem_t *hmctx; /* Heap memory */ isc_mem_t *tmctx; /* Tree memory */ char *name; isc_refcount_t references; @@ -88,12 +87,10 @@ struct dns_cache { ***/ static isc_result_t -cache_create_db(dns_cache_t *cache, dns_db_t **dbp, isc_mem_t **tmctxp, - isc_mem_t **hmctxp) { +cache_create_db(dns_cache_t *cache, dns_db_t **dbp, isc_mem_t **tmctxp) { isc_result_t result; - char *argv[1] = { 0 }; dns_db_t *db = NULL; - isc_mem_t *tmctx = NULL, *hmctx = NULL; + isc_mem_t *tmctx = NULL; /* * This will be the cache memory context, which is subject @@ -101,22 +98,8 @@ cache_create_db(dns_cache_t *cache, dns_db_t **dbp, isc_mem_t **tmctxp, */ isc_mem_create("cache", &tmctx); - /* - * This will be passed to RBTDB to use for heaps. This is separate - * from the main cache memory because it can grow quite large under - * heavy load and could otherwise cause the cache to be cleaned too - * aggressively. - */ - isc_mem_create("cache_heap", &hmctx); - - /* - * For databases of type "qpcache" or "rbt" (which are the - * only cache implementations currently in existence) we pass - * hmctx to dns_db_create() via argv[0]. - */ - argv[0] = (char *)hmctx; result = dns_db_create(tmctx, CACHEDB_DEFAULT, dns_rootname, - dns_dbtype_cache, cache->rdclass, 1, argv, &db); + dns_dbtype_cache, cache->rdclass, 0, NULL, &db); if (result != ISC_R_SUCCESS) { goto cleanup_mctx; } @@ -131,7 +114,6 @@ cache_create_db(dns_cache_t *cache, dns_db_t **dbp, isc_mem_t **tmctxp, dns_db_setmaxtypepername(db, cache->maxtypepername); *dbp = db; - *hmctxp = hmctx; *tmctxp = tmctx; return ISC_R_SUCCESS; @@ -139,7 +121,6 @@ cache_create_db(dns_cache_t *cache, dns_db_t **dbp, isc_mem_t **tmctxp, cleanup_db: dns_db_detach(&db); cleanup_mctx: - isc_mem_detach(&hmctx); isc_mem_detach(&tmctx); return result; @@ -150,9 +131,6 @@ cache_destroy(dns_cache_t *cache) { isc_stats_detach(&cache->stats); isc_mutex_destroy(&cache->lock); isc_mem_free(cache->mctx, cache->name); - if (cache->hmctx != NULL) { - isc_mem_detach(&cache->hmctx); - } if (cache->tmctx != NULL) { isc_mem_detach(&cache->tmctx); } @@ -184,7 +162,7 @@ dns_cache_create(dns_rdataclass_t rdclass, const char *cachename, /* * Create the database */ - CHECK(cache_create_db(cache, &cache->db, &cache->tmctx, &cache->hmctx)); + CHECK(cache_create_db(cache, &cache->db, &cache->tmctx)); *cachep = cache; return ISC_R_SUCCESS; @@ -325,14 +303,11 @@ isc_result_t dns_cache_flush(dns_cache_t *cache) { dns_db_t *db = NULL, *olddb = NULL; isc_mem_t *tmctx = NULL, *oldtmctx = NULL; - isc_mem_t *hmctx = NULL, *oldhmctx = NULL; - RETERR(cache_create_db(cache, &db, &tmctx, &hmctx)); + RETERR(cache_create_db(cache, &db, &tmctx)); LOCK(&cache->lock); isc_mem_clearwater(cache->tmctx); - oldhmctx = cache->hmctx; - cache->hmctx = hmctx; oldtmctx = cache->tmctx; cache->tmctx = tmctx; updatewater(cache); @@ -341,7 +316,6 @@ dns_cache_flush(dns_cache_t *cache) { UNLOCK(&cache->lock); dns_db_detach(&olddb); - isc_mem_detach(&oldhmctx); isc_mem_detach(&oldtmctx); return ISC_R_SUCCESS; @@ -609,9 +583,6 @@ dns_cache_dumpstats(dns_cache_t *cache, FILE *fp) { fprintf(fp, "%20" PRIu64 " %s\n", (uint64_t)isc_mem_inuse(cache->tmctx), "cache tree memory in use"); - - fprintf(fp, "%20" PRIu64 " %s\n", (uint64_t)isc_mem_inuse(cache->hmctx), - "cache heap memory in use"); } #ifdef HAVE_LIBXML2 @@ -664,8 +635,6 @@ dns_cache_renderxml(dns_cache_t *cache, void *writer0) { TRY0(renderstat("CacheNodes", dns_db_nodecount(cache->db), writer)); TRY0(renderstat("TreeMemInUse", isc_mem_inuse(cache->tmctx), writer)); - - TRY0(renderstat("HeapMemInUse", isc_mem_inuse(cache->hmctx), writer)); error: return xmlrc; } @@ -729,10 +698,6 @@ dns_cache_renderjson(dns_cache_t *cache, void *cstats0) { CHECKMEM(obj); json_object_object_add(cstats, "TreeMemInUse", obj); - obj = json_object_new_int64(isc_mem_inuse(cache->hmctx)); - CHECKMEM(obj); - json_object_object_add(cstats, "HeapMemInUse", obj); - result = ISC_R_SUCCESS; error: return result; diff --git a/lib/dns/qpcache.c b/lib/dns/qpcache.c index e22857087e2..7c85dc3f647 100644 --- a/lib/dns/qpcache.c +++ b/lib/dns/qpcache.c @@ -216,8 +216,6 @@ struct qpcache { /* Locked by tree_lock. */ dns_qp_t *tree; - isc_mem_t *hmctx; /* Memory context for the heaps */ - size_t buckets_count; qpcache_bucket_t buckets[]; /* attribute((counted_by(buckets_count))) */ }; @@ -2055,7 +2053,6 @@ qpcache__destroy(qpcache_t *qpdb) { isc_rwlock_destroy(&qpdb->lock); qpdb->common.magic = 0; qpdb->common.impmagic = 0; - isc_mem_detach(&qpdb->hmctx); isc_mem_putanddetach(&qpdb->common.mctx, qpdb, sizeof(*qpdb) + qpdb->buckets_count * @@ -2964,7 +2961,6 @@ dns__qpcache_create(isc_mem_t *mctx, const dns_name_t *origin, unsigned int argc, char *argv[], void *driverarg ISC_ATTR_UNUSED, dns_db_t **dbp) { qpcache_t *qpdb = NULL; - isc_mem_t *hmctx = mctx; isc_loop_t *loop = isc_loop(); int i; size_t nloops = isc_loopmgr_nloops(); @@ -2972,6 +2968,8 @@ dns__qpcache_create(isc_mem_t *mctx, const dns_name_t *origin, /* This database implementation only supports cache semantics */ REQUIRE(type == dns_dbtype_cache); REQUIRE(loop != NULL); + REQUIRE(argc == 0); + REQUIRE(argv == NULL); qpdb = isc_mem_get(mctx, sizeof(*qpdb) + nloops * sizeof(qpdb->buckets[0])); @@ -2985,13 +2983,6 @@ dns__qpcache_create(isc_mem_t *mctx, const dns_name_t *origin, .buckets_count = nloops, }; - /* - * If argv[0] exists, it points to a memory context to use for heap - */ - if (argc != 0) { - hmctx = (isc_mem_t *)argv[0]; - } - isc_rwlock_init(&qpdb->lock); TREE_INITLOCK(&qpdb->tree_lock); @@ -3012,7 +3003,6 @@ dns__qpcache_create(isc_mem_t *mctx, const dns_name_t *origin, * mctx won't disappear out from under us. */ isc_mem_attach(mctx, &qpdb->common.mctx); - isc_mem_attach(hmctx, &qpdb->hmctx); /* * Make a copy of the origin name. diff --git a/lib/dns/qpcache_p.h b/lib/dns/qpcache_p.h index 041241cd719..87f500ab5db 100644 --- a/lib/dns/qpcache_p.h +++ b/lib/dns/qpcache_p.h @@ -13,7 +13,6 @@ #pragma once -#include #include #include @@ -37,10 +36,6 @@ dns__qpcache_create(isc_mem_t *mctx, const dns_name_t *base, dns_dbtype_t type, * Create a new database of type "qpcache". Called via dns_db_create(); * see documentation for that function for more details. * - * If argv[0] is set, it points to a valid memory context to be used for - * allocation of heap memory. Generally this is used for cache databases - * only. - * * Requires: * * \li argc == 0 or argv[0] is a valid memory context.