Unbound pretends to report memory statistics based on the value returned
by sbrk(). Not only is this non-portable (as demonstrated by r3528 and
r3911), but it is completely meaningless even on systems that provide
the sbrk() function. First, modern allocators (and by "modern" I mean
"anything written in the last 10-15 years") use mmap(), not sbrk(), to
manage address space. Second, even with allocators that do rely on
sbrk(), it only tells you how much address space is available to the
program, not how much of it is currently or has ever been used. The
attached patch removes all traces of sbrk() from the code.
DES
--
Dag-Erling Smørgrav - [email protected]
Index: config.h.in
===================================================================
--- config.h.in (revision 3926)
+++ config.h.in (working copy)
@@ -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
Index: configure
===================================================================
--- configure (revision 3926)
+++ configure (working copy)
@@ -18967,45 +18967,6 @@
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
Index: configure.ac
===================================================================
--- configure.ac (revision 3926)
+++ configure.ac (working copy)
@@ -1147,21 +1147,6 @@
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])
Index: contrib/unbound_munin_
===================================================================
--- contrib/unbound_munin_ (revision 3926)
+++ contrib/unbound_munin_ (working copy)
@@ -266,7 +266,6 @@
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 @@
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
Index: daemon/remote.c
===================================================================
--- daemon/remote.c (revision 3926)
+++ daemon/remote.c (working copy)
@@ -823,12 +823,6 @@
{
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;
Index: daemon/unbound.c
===================================================================
--- daemon/unbound.c (revision 3926)
+++ daemon/unbound.c (working copy)
@@ -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 @@
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);
Index: daemon/worker.c
===================================================================
--- daemon/worker.c (revision 3926)
+++ daemon/worker.c (working copy)
@@ -101,51 +101,6 @@
*/
#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),
Index: doc/unbound-control.8.in
===================================================================
--- doc/unbound-control.8.in (revision 3926)
+++ doc/unbound-control.8.in (working copy)
@@ -405,9 +405,6 @@
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