diff --git a/daemon/remote.c b/daemon/remote.c index ac5ffbc86..01663fad6 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -866,7 +866,6 @@ print_longnum(SSL* ssl, const char* desc, size_t x) static int print_mem(SSL* ssl, struct worker* worker, struct daemon* daemon) { - int m; size_t msg, rrset, val, iter, respip; #ifdef CLIENT_SUBNET size_t subnet = 0; @@ -876,47 +875,14 @@ print_mem(SSL* ssl, struct worker* worker, struct daemon* daemon) #endif /* USE_IPSECMOD */ msg = slabhash_get_mem(daemon->env->msg_cache); rrset = slabhash_get_mem(&daemon->env->rrset_cache->table); - val=0; - iter=0; - respip=0; - m = modstack_find(&worker->env.mesh->mods, "validator"); - if(m != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh-> - mods.mod[m]->get_mem)); - val = (*worker->env.mesh->mods.mod[m]->get_mem) - (&worker->env, m); - } - m = modstack_find(&worker->env.mesh->mods, "iterator"); - if(m != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh-> - mods.mod[m]->get_mem)); - iter = (*worker->env.mesh->mods.mod[m]->get_mem) - (&worker->env, m); - } - m = modstack_find(&worker->env.mesh->mods, "respip"); - if(m != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh-> - mods.mod[m]->get_mem)); - respip = (*worker->env.mesh->mods.mod[m]->get_mem) - (&worker->env, m); - } + val = mod_get_mem(&worker->env, "validator"); + iter = mod_get_mem(&worker->env, "iterator"); + respip = mod_get_mem(&worker->env, "respip"); #ifdef CLIENT_SUBNET - m = modstack_find(&worker->env.mesh->mods, "subnet"); - if(m != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh-> - mods.mod[m]->get_mem)); - subnet = (*worker->env.mesh->mods.mod[m]->get_mem) - (&worker->env, m); - } + subnet = mod_get_mem(&worker->env, "subnet"); #endif /* CLIENT_SUBNET */ #ifdef USE_IPSECMOD - m = modstack_find(&worker->env.mesh->mods, "ipsecmod"); - if(m != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh-> - mods.mod[m]->get_mem)); - ipsecmod = (*worker->env.mesh->mods.mod[m]->get_mem) - (&worker->env, m); - } + ipsecmod = mod_get_mem(&worker->env, "ipsecmod"); #endif /* USE_IPSECMOD */ if(!print_longnum(ssl, "mem.cache.rrset"SQ, rrset)) diff --git a/doc/Changelog b/doc/Changelog index 10d52f559..ceac7885d 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -6,6 +6,8 @@ - updated dependencies in the makefile. - document trust-anchor-signaling in example config file. - updated configure, dependencies and flex output. + - better module memory lookup, fix of unbound-control shm names for + module memory printout of statistics. 12 May 2017: Wouter - Adjust servfail by iterator to not store in cache when serve-expired diff --git a/libunbound/unbound.h b/libunbound/unbound.h index bc47b5e46..d7667d104 100644 --- a/libunbound/unbound.h +++ b/libunbound/unbound.h @@ -621,6 +621,7 @@ struct ub_shm_stat_info { long long iter; long long subnet; long long ipsecmod; + long long respip; } mem; }; diff --git a/services/modstack.c b/services/modstack.c index 8a8aa4e8f..136245a96 100644 --- a/services/modstack.c +++ b/services/modstack.c @@ -243,3 +243,15 @@ modstack_find(struct module_stack* stack, const char* name) } return -1; } + +size_t +mod_get_mem(struct module_env* env, const char* name) +{ + int m = modstack_find(&env->mesh->mods, name); + if(m != -1) { + fptr_ok(fptr_whitelist_mod_get_mem(env->mesh-> + mods.mod[m]->get_mem)); + return (*env->mesh->mods.mod[m]->get_mem)(env, m); + } + return 0; +} diff --git a/services/modstack.h b/services/modstack.h index cb8613299..3ff01b54d 100644 --- a/services/modstack.h +++ b/services/modstack.h @@ -110,4 +110,7 @@ void modstack_desetup(struct module_stack* stack, struct module_env* env); */ int modstack_find(struct module_stack* stack, const char* name); +/** fetch memory for a module by name, returns 0 if module not there */ +size_t mod_get_mem(struct module_env* env, const char* name); + #endif /* SERVICES_MODSTACK_H */ diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index 3e4f5dce2..aa2db4a61 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -242,10 +242,14 @@ static void print_mem(struct ub_shm_stat_info* shm_stat) { PR_LL("mem.cache.rrset", shm_stat->mem.rrset); PR_LL("mem.cache.message", shm_stat->mem.msg); - PR_LL("mem.cache.iterator", shm_stat->mem.iter); - PR_LL("mem.cache.validator", shm_stat->mem.val); + PR_LL("mem.mod.iterator", shm_stat->mem.iter); + PR_LL("mem.mod.validator", shm_stat->mem.val); + PR_LL("mem.mod.respip", shm_stat->mem.respip); #ifdef CLIENT_SUBNET - PR_LL("mem.cache.subnet", shm_stat->mem.subnet); + PR_LL("mem.mod.subnet", shm_stat->mem.subnet); +#endif +#ifdef USE_IPSECMOD + PR_LL("mem.mod.ipsecmod", shm_stat->mem.ipsecmod); #endif } diff --git a/util/shm_side/shm_main.c b/util/shm_side/shm_main.c index 55b96e5c0..bba2a8396 100644 --- a/util/shm_side/shm_main.c +++ b/util/shm_side/shm_main.c @@ -221,7 +221,6 @@ void shm_main_run(struct worker *worker) struct ub_shm_stat_info *shm_stat; struct ub_stats_info *stat_total; struct ub_stats_info *stat_info; - int modstack; int offset; verbose(VERB_DETAIL, "SHM run - worker [%d] - daemon [%p] - timenow(%u) - timeboot(%u)", @@ -250,40 +249,28 @@ void shm_main_run(struct worker *worker) shm_stat->mem.msg = (long long)slabhash_get_mem(worker->env.msg_cache); shm_stat->mem.rrset = (long long)slabhash_get_mem(&worker->env.rrset_cache->table); - shm_stat->mem.val = 0; - shm_stat->mem.iter = 0; + shm_stat->mem.val = (long long)mod_get_mem(&worker->env, + "validator"); + shm_stat->mem.iter = (long long)mod_get_mem(&worker->env, + "iterator"); + shm_stat->mem.respip = (long long)mod_get_mem(&worker->env, + "respip"); - modstack = modstack_find(&worker->env.mesh->mods, "validator"); - if(modstack != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh->mods.mod[modstack]->get_mem)); - shm_stat->mem.val = (long long)(*worker->env.mesh->mods.mod[modstack]->get_mem)(&worker->env, modstack); - } - modstack = modstack_find(&worker->env.mesh->mods, "iterator"); - if(modstack != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh->mods.mod[modstack]->get_mem)); - shm_stat->mem.iter = (long long)(*worker->env.mesh->mods.mod[modstack]->get_mem)(&worker->env, modstack); - } /* subnet mem value is available in shm, also when not enabled, * to make the struct easier to memmap by other applications, * independent of the configuration of unbound */ shm_stat->mem.subnet = 0; #ifdef CLIENT_SUBNET - modstack = modstack_find(&worker->env.mesh->mods, "subnet"); - if(modstack != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh->mods.mod[modstack]->get_mem)); - shm_stat->mem.subnet = (long long)(*worker->env.mesh->mods.mod[modstack]->get_mem)(&worker->env, modstack); - } + shm_stat->mem.subnet = (long long)mod_get_mem(&worker->env, + "subnet"); #endif /* ipsecmod mem value is available in shm, also when not enabled, * to make the struct easier to memmap by other applications, * independent of the configuration of unbound */ shm_stat->mem.ipsecmod = 0; #ifdef USE_IPSECMOD - modstack = modstack_find(&worker->env.mesh->mods, "ipsecmod"); - if(modstack != -1) { - fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh->mods.mod[modstack]->get_mem)); - shm_stat->mem.ipsecmod = (*worker->env.mesh->mods.mod[modstack]->get_mem)(&worker->env, modstack); - } + shm_stat->mem.ipsecmod = (long long)mod_get_mem(&worker->env, + "ipsecmod"); #endif }