From a6e3ed1025eaacc5ca37d0372a81245ea8f2b904 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 22 Nov 2016 15:50:07 +0000 Subject: [PATCH] - patch from Dag-Erling Smorgrav that removes code that relies on sbrk(). git-svn-id: file:///svn/unbound/trunk@3934 be551aaa-1e26-0410-a405-d3ace91eadb9 --- config.h.in | 3 --- configure | 39 ------------------------------ configure.ac | 15 ------------ contrib/unbound_munin_ | 15 ------------ daemon/remote.c | 6 ----- daemon/unbound.c | 10 -------- daemon/worker.c | 51 ++++------------------------------------ doc/Changelog | 2 ++ doc/unbound-control.8.in | 3 --- testcode/memstats.c | 1 + 10 files changed, 8 insertions(+), 137 deletions(-) diff --git a/config.h.in b/config.h.in index 64d1c797a..cee0b1252 100644 --- a/config.h.in +++ b/config.h.in @@ -344,9 +344,6 @@ /* Define to 1 if you have the `recvmsg' function. */ #undef HAVE_RECVMSG -/* define if you have the sbrk() call */ -#undef HAVE_SBRK - /* Define to 1 if you have the `sendmsg' function. */ #undef HAVE_SENDMSG diff --git a/configure b/configure index 5716f4995..67cbd538c 100755 --- a/configure +++ b/configure @@ -18967,45 +18967,6 @@ fi done -for ac_func in sbrk -do : - ac_fn_c_check_func "$LINENO" "sbrk" "ac_cv_func_sbrk" -if test "x$ac_cv_func_sbrk" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_SBRK 1 -_ACEOF - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if sbrk is not deprecated" >&5 -$as_echo_n "checking if sbrk is not deprecated... " >&6; } -# catch the warning of deprecated sbrk -old_cflags="$CFLAGS" -CFLAGS="$CFLAGS -Werror" -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -$ac_includes_default - -int main(void) { void* cur = sbrk(0); printf("%u\n", (unsigned)(size_t)((char*)cur - (char*)sbrk(0))); return 0; } - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - -$as_echo "#define HAVE_SBRK 1" >>confdefs.h - - -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -CFLAGS="$old_cflags" - -fi -done - - # check if setreuid en setregid fail, on MacOSX10.4(darwin8). if echo $build_os | grep darwin8 > /dev/null; then diff --git a/configure.ac b/configure.ac index 9ccde4d3d..d96d64a4d 100644 --- a/configure.ac +++ b/configure.ac @@ -1147,21 +1147,6 @@ AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam endpwent getrlimit setrlimit se AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])]) AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])]) -AC_CHECK_FUNCS([sbrk],[ -AC_MSG_CHECKING([if sbrk is not deprecated]) -# catch the warning of deprecated sbrk -old_cflags="$CFLAGS" -CFLAGS="$CFLAGS -Werror" -AC_COMPILE_IFELSE([AC_LANG_SOURCE(AC_INCLUDES_DEFAULT -[[ -int main(void) { void* cur = sbrk(0); printf("%u\n", (unsigned)(size_t)((char*)cur - (char*)sbrk(0))); return 0; } -]])], [ - AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_SBRK, 1, [define if you have the sbrk() call]) - ], [AC_MSG_RESULT(no)]) -CFLAGS="$old_cflags" -]) - # check if setreuid en setregid fail, on MacOSX10.4(darwin8). if echo $build_os | grep darwin8 > /dev/null; then AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work]) diff --git a/contrib/unbound_munin_ b/contrib/unbound_munin_ index df76a9fcf..5d3dff8e8 100755 --- a/contrib/unbound_munin_ +++ b/contrib/unbound_munin_ @@ -266,7 +266,6 @@ if test "$1" = "config" ; then echo "graph_args --base 1024 -l 0" echo "graph_vlabel memory used in bytes" echo "graph_category DNS" - p_config "mem.total.sbrk" "Total memory" "GAUGE" p_config "mem.cache.rrset" "RRset cache memory" "GAUGE" p_config "mem.cache.message" "Message cache memory" "GAUGE" p_config "mem.mod.iterator" "Iterator module memory" "GAUGE" @@ -458,20 +457,6 @@ queue) done ;; memory) - mn=`echo mem.total.sbrk | sed $ABBREV | tr . _` - get_value 'mem.total.sbrk' - if test $value -eq 0; then - chk=`echo $ctrl | sed -e 's/-control$/-checkconf/'` - pidf=`$chk -o pidfile $conf 2>&1` - pid=`cat $pidf 2>&1` - value=`ps -p "$pid" -o rss= 2>&1` - if test "`expr $value + 1 - 1 2>&1`" -eq "$value" 2>&1; then - value=`expr $value \* 1024` - else - value=0 - fi - fi - echo "$mn.value" $value for x in mem.cache.rrset mem.cache.message mem.mod.iterator \ mem.mod.validator msg.cache.count rrset.cache.count \ infra.cache.count key.cache.count; do diff --git a/daemon/remote.c b/daemon/remote.c index faee2f881..417c6a24a 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -823,12 +823,6 @@ print_mem(SSL* ssl, struct worker* worker, struct daemon* daemon) { int m; size_t msg, rrset, val, iter; -#ifdef HAVE_SBRK - extern void* unbound_start_brk; - void* cur = sbrk(0); - if(!print_longnum(ssl, "mem.total.sbrk"SQ, - (size_t)((char*)cur - (char*)unbound_start_brk))) return 0; -#endif /* HAVE_SBRK */ msg = slabhash_get_mem(daemon->env->msg_cache); rrset = slabhash_get_mem(&daemon->env->rrset_cache->table); val=0; diff --git a/daemon/unbound.c b/daemon/unbound.c index d1fc6eb9e..971ccc47d 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -87,11 +87,6 @@ # include "nss.h" #endif -#ifdef HAVE_SBRK -/** global debug value to keep track of heap memory allocation */ -void* unbound_start_brk = 0; -#endif - /** print usage. */ static void usage(void) { @@ -686,11 +681,6 @@ main(int argc, char* argv[]) int cmdline_cfg = 0; #endif -#ifdef HAVE_SBRK - /* take debug snapshot of heap */ - unbound_start_brk = sbrk(0); -#endif - log_init(NULL, 0, NULL); log_ident_default = strrchr(argv[0],'/')?strrchr(argv[0],'/')+1:argv[0]; log_ident_set(log_ident_default); diff --git a/daemon/worker.c b/daemon/worker.c index 5e49011ac..94f636b65 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -101,57 +101,14 @@ */ #define PREFETCH_EXPIRY_ADD 60 -#ifdef UNBOUND_ALLOC_STATS -/** measure memory leakage */ -static void -debug_memleak(size_t accounted, size_t heap, - size_t total_alloc, size_t total_free) -{ - static int init = 0; - static size_t base_heap, base_accounted, base_alloc, base_free; - size_t base_af, cur_af, grow_af, grow_acc; - if(!init) { - init = 1; - base_heap = heap; - base_accounted = accounted; - base_alloc = total_alloc; - base_free = total_free; - } - base_af = base_alloc - base_free; - cur_af = total_alloc - total_free; - grow_af = cur_af - base_af; - grow_acc = accounted - base_accounted; - log_info("Leakage: %d leaked. growth: %u use, %u acc, %u heap", - (int)(grow_af - grow_acc), (unsigned)grow_af, - (unsigned)grow_acc, (unsigned)(heap - base_heap)); -} - -/** give debug heap size indication */ -static void -debug_total_mem(size_t calctotal) -{ -#ifdef HAVE_SBRK - extern void* unbound_start_brk; - extern size_t unbound_mem_alloc, unbound_mem_freed; - void* cur = sbrk(0); - int total = cur-unbound_start_brk; - log_info("Total heap memory estimate: %u total-alloc: %u " - "total-free: %u", (unsigned)total, - (unsigned)unbound_mem_alloc, (unsigned)unbound_mem_freed); - debug_memleak(calctotal, (size_t)total, - unbound_mem_alloc, unbound_mem_freed); -#else - (void)calctotal; -#endif /* HAVE_SBRK */ -} -#endif /* UNBOUND_ALLOC_STATS */ - /** Report on memory usage by this thread and global */ static void worker_mem_report(struct worker* ATTR_UNUSED(worker), struct serviced_query* ATTR_UNUSED(cur_serv)) { #ifdef UNBOUND_ALLOC_STATS + /* measure memory leakage */ + extern size_t unbound_mem_alloc, unbound_mem_freed; /* debug func in validator module */ size_t total, front, back, mesh, msg, rrset, infra, ac, superac; size_t me, iter, val, anch; @@ -199,7 +156,9 @@ worker_mem_report(struct worker* ATTR_UNUSED(worker), (unsigned)mesh, (unsigned)msg, (unsigned)rrset, (unsigned)infra, (unsigned)iter, (unsigned)val, (unsigned)anch, (unsigned)ac, (unsigned)superac, (unsigned)me); - debug_total_mem(total); + log_info("Total heap memory estimate: %u total-alloc: %u " + "total-free: %u", (unsigned)total, + (unsigned)unbound_mem_alloc, (unsigned)unbound_mem_freed); #else /* no UNBOUND_ALLOC_STATS */ size_t val = 0; int i; diff --git a/doc/Changelog b/doc/Changelog index 814b494a8..7c90fb30c 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -11,6 +11,8 @@ 22 November 2016: Wouter - iana portlist update. - Fix unit tests for DS hash processing for fake-dsa test option. + - patch from Dag-Erling Smorgrav that removes code that relies + on sbrk(). 21 November 2016: Wouter - Fix #1158: reference RFC 8020 "NXDOMAIN: There Really Is Nothing diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index 5a0bff682..f5e36df2c 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -405,9 +405,6 @@ uptime since server boot in seconds. time since last statistics printout, in seconds. .SH EXTENDED STATISTICS .TP -.I mem.total.sbrk -If sbrk(2) is available, an estimate of the heap size of the program in number of bytes. Close to the total memory used by the program, as reported by top and ps. Could be wrong if the OS allocates memory non\-contiguously. -.TP .I mem.cache.rrset Memory in bytes in use by the RRset cache. .TP diff --git a/testcode/memstats.c b/testcode/memstats.c index 1cca02e74..e837bbf3b 100644 --- a/testcode/memstats.c +++ b/testcode/memstats.c @@ -236,6 +236,7 @@ printstats(rbtree_t* tree) int main(int argc, const char* argv[]) { rbtree_t* tree = 0; + log_init(NULL, 0, 0); if(argc != 2) { usage(); }