d63ae51ba337165172a9b50fd5d84805ffe50044Tinderbox User * Copyright (C) 1999-2009, 2011-2017 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
e1cf6fd20a9f56c6c31581480445dea96fc7ac60Mark Andrews/* $Id: cache.c,v 1.91 2011/08/26 05:12:56 marka Exp $ */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉#define CACHE_MAGIC ISC_MAGIC('$', '$', '$', '$')
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉#define VALID_CACHE(cache) ISC_MAGIC_VALID(cache, CACHE_MAGIC)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Control incremental cleaning.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * DNS_CACHE_MINSIZE is how many bytes is the floor for dns_cache_setcachesize().
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * See also DNS_CACHE_CLEANERINCREMENT
f3350b671881f175d03e16fa5d0f685a1691bcabMark Andrews#define DNS_CACHE_MINSIZE 2097152U /*%< Bytes. 2097152 = 2 MB */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Control incremental cleaning.
f991461dc144794d80ff8d85e430fd8a6e6113f3David Lawrence * CLEANERINCREMENT is how many nodes are examined in one pass.
b239c8294a5653d21876d084e0c5b029f6b9fc5dMichael Graff * See also DNS_CACHE_MINSIZE
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉#define DNS_CACHE_CLEANERINCREMENT 1000U /*%< Number of nodes. */
584848087f7463c1f659ce4712dc047d8e7f2b07Francis Dupont * A cache_cleaner_t encapsulates the state of the periodic
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * cache cleaning.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssontypedef struct cache_cleaner cache_cleaner_t;
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 cleaner_s_idle, /*%< Waiting for cleaning-interval to expire. */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 cleaner_s_busy, /*%< Currently cleaning. */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 cleaner_s_done /*%< Freed enough memory after being overmem. */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Convenience macros for comprehensive assertion checking.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉#define CLEANER_IDLE(c) ((c)->state == cleaner_s_idle && \
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉#define CLEANER_BUSY(c) ((c)->state == cleaner_s_busy && \
f991461dc144794d80ff8d85e430fd8a6e6113f3David Lawrence * Accesses to a cache cleaner object are synchronized through
f991461dc144794d80ff8d85e430fd8a6e6113f3David Lawrence * task/event serialization, or locked from the cache object.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * Locks overmem_event, overmem. Note: never allocate memory
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * while holding this lock - that could lead to deadlock since
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * the lock is take by water() which is called from the memory
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 unsigned int cleaning_interval; /*% The cleaning-interval from
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater named.conf, in seconds. */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_event_t *resched_event; /*% Sent by cleaner task to
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 itself to reschedule */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 unsigned int increment; /*% Number of names to
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater clean in one increment */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_boolean_t overmem; /*% The cache is in an overmem state. */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * The actual cache object.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* Unlocked. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* Locked by 'lock'. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* Locked by 'filelock'. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* Access to the on-disk cache file is also locked by 'filelock'. */
f991461dc144794d80ff8d85e430fd8a6e6113f3David Lawrencecache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_timermgr_t *timermgr, cache_cleaner_t *cleaner);
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssoncleaning_timer_action(isc_task_t *task, isc_event_t *event);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉incremental_cleaning_action(isc_task_t *task, isc_event_t *event);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉cleaner_shutdown_action(isc_task_t *task, isc_event_t *event);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉overmem_cleaning_action(isc_task_t *task, isc_event_t *event);
c20ffa38dee7efa0dc01822d4bac5e41729b9b61Brian Wellingtoncache_create_db(dns_cache_t *cache, dns_db_t **db) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater return (dns_db_create(cache->mctx, cache->db_type, dns_rootname,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater const char *db_type, unsigned int db_argc, char **db_argv,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt return (dns_cache_create3(cmctx, cmctx, taskmgr, timermgr, rdclass, "",
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create2(isc_mem_t *cmctx, isc_taskmgr_t *taskmgr,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt unsigned int db_argc, char **db_argv, dns_cache_t **cachep)
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt return (dns_cache_create3(cmctx, cmctx, taskmgr, timermgr, rdclass,
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Huntdns_cache_create3(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 isc_timermgr_t *timermgr, dns_rdataclass_t rdclass,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 const char *cachename, const char *db_type,
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 unsigned int db_argc, char **db_argv, dns_cache_t **cachep)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_mutex_init(&cache->filelock);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * For databases of type "rbt" we pass hmctx to dns_db_create()
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * via cache->db_argv, followed by the rest of the arguments in
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * db_argv (of which there really shouldn't be any).
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * Create the database
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = cache_create_db(cache, &cache->db);
5d7849ad7ffc6d08870dbfbc8d6bfffd90007488Tatuya JINMEI 神明達哉 result = isc_task_create(taskmgr, 1, &dbtask);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * RBT-type cache DB has its own mechanism of cache cleaning and doesn't
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * need the control of the generic cleaner.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = cache_cleaner_init(cache, NULL, NULL, &cache->cleaner);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = cache_cleaner_init(cache, taskmgr, timermgr,
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt result = dns_db_setcachestats(cache->db, cache->stats);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt isc_mem_putanddetach(&cache->mctx, cache, sizeof(*cache));
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_setwater(cache->mctx, NULL, NULL, 0, 0);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 if (cache->cleaner.overmem_event != NULL)
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_event_free(&cache->cleaner.overmem_event);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 if (cache->cleaner.resched_event != NULL)
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_event_free(&cache->cleaner.resched_event);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_dbiterator_destroy(&cache->cleaner.iterator);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_free(cache->mctx, cache->filename);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * We don't free db_argv[0] in "rbt" cache databases
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt * as it's a pointer to hmctx
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_free(cache->mctx, cache->db_argv[i]);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_free(cache->mctx, cache->db_type);
70c7f4fb4fc589b04a68d67479d34eecd99c1991Evan Hunt isc_mem_putanddetach(&cache->mctx, cache, sizeof(*cache));
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_attach(dns_cache_t *cache, dns_cache_t **targetp) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater REQUIRE(targetp != NULL && *targetp == NULL);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * When the cache is shut down, dump it to a file if one is
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_result_t result = dns_cache_dump(cache);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "error dumping cache: %s ",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If the cleaner task exists, let it free the cache.
b120e39deac3e9c323cdc7801ed2313f8ebbb744Andreas Gustafssondns_cache_attachdb(dns_cache_t *cache, dns_db_t **dbp) {
4e1d3e67cdc76609bad5f0310ac48de10b442b9fMark Andrewsdns_cache_setfilename(dns_cache_t *cache, const char *filename) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater newname = isc_mem_strdup(cache->mctx, filename);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_free(cache->mctx, cache->filename);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_db_load(cache->db, cache->filename);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_master_dump(cache->mctx, cache->db, NULL,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater &dns_master_style_cache, cache->filename);
8f79820c6930ee5ef6b4a54f36d2559400bdf47dAndreas Gustafssondns_cache_setcleaninginterval(dns_cache_t *cache, unsigned int t) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * It may be the case that the cache has already shut down.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If so, it has no timer.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (cache->cleaner.cleaning_timer == NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_timer_reset(cache->cleaner.cleaning_timer,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_interval_set(&interval, cache->cleaner.cleaning_interval,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_timer_reset(cache->cleaner.cleaning_timer,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "could not set cache cleaning interval: %s",
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉dns_cache_getcleaninginterval(dns_cache_t *cache) {
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 unsigned int t;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Initialize the cache cleaner object at *cleaner.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * Space for the object must be allocated by the caller.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencecache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_timermgr_t *timermgr, cache_cleaner_t *cleaner)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater cleaner->increment = DNS_CACHE_CLEANERINCREMENT;
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉 cleaner->cleaning_interval = 0; /* Initially turned off. */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_db_createiterator(cleaner->cache->db, ISC_FALSE,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (taskmgr != NULL && timermgr != NULL) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_task_create(taskmgr, 1, &cleaner->task);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "isc_task_create() failed: %s",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_task_setname(cleaner->task, "cachecleaner", cleaner);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_task_onshutdown(cleaner->task,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "cache cleaner: "
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "isc_task_onshutdown() failed: %s",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = isc_timer_create(timermgr, isc_timertype_inactive,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "isc_timer_create() failed: %s",
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_timer_detach(&cleaner->cleaning_timer);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_dbiterator_destroy(&cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉begin_cleaning(cache_cleaner_t *cleaner) {
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * Create an iterator, if it does not already exist, and
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * position it at the beginning of the cache.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_db_createiterator(cleaner->cache->db, ISC_FALSE,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "cache cleaner could not create "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "iterator: %s", isc_result_totext(result));
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_dbiterator_setcleanmode(cleaner->iterator, ISC_TRUE);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_dbiterator_first(cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * If the result is ISC_R_NOMORE, the database is empty,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * so there is nothing to be cleaned.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 if (result != ISC_R_NOMORE && cleaner->iterator != NULL) {
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "cache cleaner: "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "dns_dbiterator_first() failed: %s",
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_dbiterator_destroy(&cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_dbiterator_pause(cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * Pause the iterator to free its lock.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_dbiterator_pause(cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "begin cache cleaning, mem inuse %lu",
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 (unsigned long)isc_mem_inuse(cleaner->cache->mctx));
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_task_send(cleaner->task, &cleaner->resched_event);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉end_cleaning(cache_cleaner_t *cleaner, isc_event_t *event) {
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_dbiterator_pause(cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_dbiterator_destroy(&cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_cache_setcleaninginterval(cleaner->cache,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 ISC_LOG_DEBUG(1), "end cache cleaning, mem inuse %lu",
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 (unsigned long)isc_mem_inuse(cleaner->cache->mctx));
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafsson * This is run once for every cache-cleaning-interval as defined in named.conf.
a928d619170d61da40c3bff29800ff73709140daAndreas Gustafssoncleaning_timer_action(isc_task_t *task, isc_event_t *event) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(event->ev_type == ISC_TIMEREVENT_TICK);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater ISC_LOG_DEBUG(1), "cache cleaning timer fired, "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * This is called when the cache either surpasses its upper limit
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * or shrinks beyond its lower limit.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉overmem_cleaning_action(isc_task_t *task, isc_event_t *event) {
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 cache_cleaner_t *cleaner = event->ev_arg;
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 INSIST(event->ev_type == DNS_EVENT_CACHEOVERMEM);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 ISC_LOG_DEBUG(1), "overmem_cleaning_action called, "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "overmem = %d, state = %d", cleaner->overmem,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * end_cleaning() can't be called here because
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * then both cleaner->overmem_event and
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * cleaner->resched_event will point to this
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * event. Set the state to done, and then
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * when the incremental_cleaning_action() event
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * is posted, it will handle the end_cleaning.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * Do incremental cleaning.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉incremental_cleaning_action(isc_task_t *task, isc_event_t *event) {
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 cache_cleaner_t *cleaner = event->ev_arg;
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 INSIST(event->ev_type == DNS_EVENT_CACHECLEAN);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_dbiterator_destroy(&cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 (void) dns_db_createiterator(cleaner->cache->db,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 REQUIRE(DNS_DBITERATOR_VALID(cleaner->iterator));
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 while (n_names-- > 0) {
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_dbiterator_current(cleaner->iterator, &node,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "cache cleaner: dns_dbiterator_current() "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "failed: %s", dns_result_totext(result));
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * The node was not needed, but was required by
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * dns_dbiterator_current(). Give up its reference.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 dns_db_detachnode(cleaner->cache->db, &node);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * Step to the next node.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_dbiterator_next(cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * Either the end was reached (ISC_R_NOMORE) or
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * some error was signaled. If the cache is still
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * overmem and no error was encountered,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * keep trying to clean it, otherwise stop cleaning.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "cache cleaner: "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "dns_dbiterator_next() "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "cache cleaner: "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "still overmem, "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "reset and try again");
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * We have successfully performed a cleaning increment but have
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * not gone through the entire cache. Free the iterator locks
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 * and reschedule another batch. If it fails, just try to continue
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 result = dns_dbiterator_pause(cleaner->iterator);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 ISC_LOG_DEBUG(1), "cache cleaner: checked %u nodes, "
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 "mem inuse %lu, sleeping", cleaner->increment,
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 (unsigned long)isc_mem_inuse(cleaner->cache->mctx));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Do immediate cleaning.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssondns_cache_clean(dns_cache_t *cache, isc_stdtime_t now) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result = dns_db_createiterator(cache->db, 0, &iterator);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_dbiterator_current(iterator, &node,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Check TTLs, mark expired rdatasets stale.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater result = dns_db_expirenode(cache->db, node, now);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater "cache cleaner: dns_db_expirenode() "
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Continue anyway.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * This is where the actual freeing takes place.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_boolean_t overmem = ISC_TF(mark == ISC_MEM_HIWATER);
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 if (cache->cleaner.overmem_event != NULL)
2a184ff86544cc67c36e2ce6bb3ddb5ac44684b8Evan Huntdns_cache_setcachesize(dns_cache_t *cache, size_t size) {
584848087f7463c1f659ce4712dc047d8e7f2b07Francis Dupont * Impose a minimum cache size; pathological things happen if there
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * is too little room.
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 hiwater = size - (size >> 3); /* Approximately 7/8ths. */
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 lowater = size - (size >> 2); /* Approximately 3/4ths. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * If the cache was overmem and cleaning, but now with the new limits
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * it is no longer in an overmem condition, then the next
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * isc_mem_put for cache memory will do the right thing and trigger
f3350b671881f175d03e16fa5d0f685a1691bcabMark Andrews if (size == 0U || hiwater == 0U || lowater == 0U)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Disable cache memory limiting.
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_setwater(cache->mctx, water, cache, 0, 0);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * Establish new cache memory limits (either for the first
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * time, or replacing other limits).
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_mem_setwater(cache->mctx, water, cache, hiwater, lowater);
7781f25078c491a9650dec555bdc86cb0ed49861Tatuya JINMEI 神明達哉dns_cache_getcachesize(dns_cache_t *cache) {
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafsson * The cleaner task is shutting down; do the necessary cleanup.
f951f076f3d321c52b824a866caff28ce4f8e06cAndreas Gustafssoncleaner_shutdown_action(isc_task_t *task, isc_event_t *event) {
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater INSIST(event->ev_type == ISC_TASKEVENT_SHUTDOWN);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * By detaching the timer in the context of its task,
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater * we are guaranteed that there will be no further timer
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (cache->cleaner.cleaning_timer != NULL)
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater isc_timer_detach(&cache->cleaner.cleaning_timer);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater /* Make sure we don't reschedule anymore. */
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater (void)isc_task_purge(task, NULL, DNS_EVENT_CACHECLEAN, NULL);
307adf67922dd222bacf84ef0f074a0eb84d3a0aMark Andrews dns_dbiterator_t *dbiterator = NULL, *olddbiterator = NULL;
307adf67922dd222bacf84ef0f074a0eb84d3a0aMark Andrews result = dns_db_createiterator(db, ISC_FALSE, &dbiterator);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (cache->cleaner.state == cleaner_s_idle) {
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 if (cache->cleaner.state == cleaner_s_busy)
5c024f787777143031c2c49f9811c39c84bfa259Tatuya JINMEI 神明達哉 cache->cleaner.replaceiterator = ISC_TRUE;
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt result = dns_db_allrdatasets(db, node, NULL, (isc_stdtime_t)0, &iter);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater for (result = dns_rdatasetiter_first(iter);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater dns_rdatasetiter_current(iter, &rdataset);
f172f06ff2e7609dd7d91914a44b4e24cff8bb7aAutomatic Updater if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED)
dd185fb371632b9cf1b7be3097960185c9645a09Mark Andrews * Create the node if it doesn't exist so dns_dbiterator_seek()
dd185fb371632b9cf1b7be3097960185c9645a09Mark Andrews * can find it. We will continue even if this fails.
dd185fb371632b9cf1b7be3097960185c9645a09Mark Andrews (void)dns_db_findnode(db, name, ISC_TRUE, &top);
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt result = dns_dbiterator_current(iter, &node, nodename);
e1cf6fd20a9f56c6c31581480445dea96fc7ac60Mark Andrews * Are we done?
e1cf6fd20a9f56c6c31581480445dea96fc7ac60Mark Andrews * If clearnode fails record and move onto the next node.
e1cf6fd20a9f56c6c31581480445dea96fc7ac60Mark Andrews if (result != ISC_R_SUCCESS && answer == ISC_R_SUCCESS)
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt if (result == ISC_R_NOMORE || result == ISC_R_NOTFOUND)
e1cf6fd20a9f56c6c31581480445dea96fc7ac60Mark Andrews if (result != ISC_R_SUCCESS && answer == ISC_R_SUCCESS)
01279934803dd45c007a58b61fe20c2852135b52Evan Huntdns_cache_flushname(dns_cache_t *cache, dns_name_t *name) {
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt return (dns_cache_flushnode(cache, name, ISC_FALSE));
01279934803dd45c007a58b61fe20c2852135b52Evan Huntdns_cache_flushnode(dns_cache_t *cache, dns_name_t *name,
6214c3c93a43dc86f080dc0219e4560b69721f53Mark Andrews if (tree && dns_name_equal(name, dns_rootname))
01279934803dd45c007a58b61fe20c2852135b52Evan Hunt result = dns_db_findnode(cache->db, name, ISC_FALSE, &node);
d640b4a0ab9dec252749793f78a1ed1e8551ea19Evan Huntdns_cache_updatestats(dns_cache_t *cache, isc_result_t result) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * XXX: Much of the following code has been copied in from statschannel.c.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * We should refactor this into a generic function in stats.c that can be
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * called from both places.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunttypedef struct
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt isc_uint64_t *countervalues; /* for general statistics */
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntgetcounter(isc_statscounter_t counter, isc_uint64_t val, void *arg) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntgetcounters(isc_stats_t *stats, isc_statsformat_t type, int ncounters,
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt isc_stats_dump(stats, getcounter, &dumparg, ISC_STATSDUMP_VERBOSE);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntdns_cache_dumpstats(dns_cache_t *cache, FILE *fp) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache hits");
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache misses");
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache hits (from query)");
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache misses (from query)");
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache records deleted due to memory exhaustion");
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache records deleted due to TTL expiration");
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt fprintf(fp, "%20u %s\n", dns_db_nodecount(cache->db),
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache database nodes");
7472cd350fe9245553e9da7f2df8e7e364d136abMukund Sivaraman fprintf(fp, "%20" ISC_PLATFORM_QUADFORMAT "u %s\n",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache database hash buckets");
da4823c08a9a41e7b5ff1f3a83c80007f60fd21cMark Andrews fprintf(fp, "%20" ISC_PLATFORM_QUADFORMAT "u %s\n",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache tree memory total");
da4823c08a9a41e7b5ff1f3a83c80007f60fd21cMark Andrews fprintf(fp, "%20" ISC_PLATFORM_QUADFORMAT "u %s\n",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache tree memory in use");
da4823c08a9a41e7b5ff1f3a83c80007f60fd21cMark Andrews fprintf(fp, "%20" ISC_PLATFORM_QUADFORMAT "u %s\n",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache tree highest memory in use");
da4823c08a9a41e7b5ff1f3a83c80007f60fd21cMark Andrews fprintf(fp, "%20" ISC_PLATFORM_QUADFORMAT "u %s\n",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache heap memory total");
da4823c08a9a41e7b5ff1f3a83c80007f60fd21cMark Andrews fprintf(fp, "%20" ISC_PLATFORM_QUADFORMAT "u %s\n",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache heap memory in use");
da4823c08a9a41e7b5ff1f3a83c80007f60fd21cMark Andrews fprintf(fp, "%20" ISC_PLATFORM_QUADFORMAT "u %s\n",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt "cache heap highest memory in use");
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntrenderstat(const char *name, isc_uint64_t value, xmlTextWriterPtr writer) {
b748b5e2c2fa40f758e3b35ad4f1fde99ab5e11fEvan Hunt TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counter"));
b748b5e2c2fa40f758e3b35ad4f1fde99ab5e11fEvan Hunt TRY0(xmlTextWriterEndElement(writer)); /* counter */
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntdns_cache_renderxml(dns_cache_t *cache, xmlTextWriterPtr writer) {
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews values[dns_cachestatscounter_misses], writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews values[dns_cachestatscounter_queryhits], writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews values[dns_cachestatscounter_querymisses], writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews values[dns_cachestatscounter_deletelru], writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews values[dns_cachestatscounter_deletettl], writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("CacheNodes", dns_db_nodecount(cache->db), writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("CacheBuckets", dns_db_hashsize(cache->db), writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("TreeMemTotal", isc_mem_total(cache->mctx), writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("TreeMemInUse", isc_mem_inuse(cache->mctx), writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("TreeMemMax", isc_mem_maxinuse(cache->mctx), writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("HeapMemTotal", isc_mem_total(cache->hmctx), writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("HeapMemInUse", isc_mem_inuse(cache->hmctx), writer));
bbf31e6b623af575138669bdd7031232867b9166Mark Andrews TRY0(renderstat("HeapMemMax", isc_mem_maxinuse(cache->hmctx), writer));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt if (m == NULL) { \
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Huntdns_cache_renderjson(dns_cache_t *cache, json_object *cstats) {
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(values[dns_cachestatscounter_hits]);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(values[dns_cachestatscounter_misses]);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "CacheMisses", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(values[dns_cachestatscounter_queryhits]);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(values[dns_cachestatscounter_querymisses]);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "QueryMisses", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(values[dns_cachestatscounter_deletelru]);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(values[dns_cachestatscounter_deletettl]);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(dns_db_nodecount(cache->db));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "CacheNodes", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(dns_db_hashsize(cache->db));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "CacheBuckets", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(isc_mem_total(cache->mctx));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "TreeMemTotal", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(isc_mem_inuse(cache->mctx));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "TreeMemInUse", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(isc_mem_maxinuse(cache->mctx));
1feffc6fdb1ba386b22d45ea2d2f1613e717cb9eMark Andrews json_object_object_add(cstats, "TreeMemMax", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(isc_mem_total(cache->hmctx));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "HeapMemTotal", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(isc_mem_inuse(cache->hmctx));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "HeapMemInUse", obj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt obj = json_object_new_int64(isc_mem_maxinuse(cache->hmctx));
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt json_object_object_add(cstats, "HeapMemMax", obj);