From 45c82b1d8555901b6992bf9a30120fbb35a005ab Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 30 Jul 2007 18:14:14 +0000 Subject: [PATCH] r14024@catbus: nickm | 2007-07-30 14:13:58 -0400 Glibc (and maybe others) define a mallinfo() that can be used to see how the platform malloc is acting inside. When we have it, dump its output on dumpmemusage(). svn:r10996 --- ChangeLog | 4 +++- configure.in | 7 ++++--- src/common/util.c | 18 ++++++++++++++++++ src/common/util.h | 5 +++++ src/or/main.c | 1 + 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f68ece2130..668473a543 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,11 +3,13 @@ Changes in version 0.2.0.4-alpha - 2007-??-?? - Be even more aggressive about releasing RAM from small empty buffers. Thanks to our free-list code, this shouldn't be too performance-intensive. - - Disable sentiel-based debugging for buffer code: we squashed all + - Disable sentinel-based debugging for buffer code: we squashed all the bugs that this was supposed to detect a long time ago, and now its only effect is to change our buffer sizes from nice powers of two (which platform mallocs tend to like) to values siightly over powers of two (which make some platform mallocs sad). + - Log malloc statistics from mallinfo() on platforms where it + exists. Changes in version 0.2.0.3-alpha - 2007-07-29 diff --git a/configure.in b/configure.in index 1a77d6c16f..3cc14fcbec 100644 --- a/configure.in +++ b/configure.in @@ -152,7 +152,7 @@ dnl ------------------------------------------------------------------- dnl Check for functions before libevent, since libevent-1.2 apparently dnl exports strlcpy without defining it in a header. -AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop) +AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop mallinfo) if test $enable_threads = "yes"; then AC_CHECK_HEADERS(pthread.h) @@ -244,7 +244,7 @@ AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h dnl These headers are not essential -AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netintet/in.h netinet/in6.h) +AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netintet/in.h netinet/in6.h malloc.h) AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0, [#ifdef HAVE_SYS_TYPES_H @@ -623,7 +623,8 @@ if test x$enable_gcc_warnings = xyes; then #error #endif]), have_gcc42=yes, have_gcc42=no) - CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings -Waggregate-return -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum -Werror" + CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2 -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wnested-externs -Wbad-function-cast -Wswitch-enum -Werror" + # Disabled, so we can use mallinfo(): -Waggregate-return if test x$have_gcc4 = xyes ; then # These warnings break gcc 3.3.5 and work on gcc 4.0.2 diff --git a/src/common/util.c b/src/common/util.c index 991cda1a97..580f078afe 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -213,6 +213,24 @@ _tor_free(void *mem) tor_free(mem); } +/** DOCDOC */ +void +tor_log_mallinfo(int severity) +{ +#ifdef HAVE_MALLINFO + struct mallinfo mi; + memset(&mi, 0, sizeof(mi)); + mi = mallinfo(); + log(severity, LD_MM, + "mallinfo() said: arena=%d, ordblks=%d, smblks=%d, hblks=%d, " + "hblkhd=%d, usmblks=%d, fsmblks=%d, uordblks=%d, fordblks=%d, " + "keepcost=%d", + mi.arena, mi.ordblks, mi.smblks, mi.hblks, + mi.hblkhd, mi.usmblks, mi.fsmblks, mi.uordblks, mi.fordblks, + mi.keepcost); +#endif +} + /* ===== * Math * ===== */ diff --git a/src/common/util.h b/src/common/util.h index 3cd19c06c0..b0db03f149 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -23,6 +23,9 @@ #ifdef HAVE_TIME_H #include #endif +#ifdef HAVE_MALLOC_H +#include +#endif /* Replace assert() with a variant that sends failures to the log before * calling assert() normally. @@ -105,6 +108,8 @@ extern int dmalloc_free(const char *file, const int line, void *pnt, #define tor_strndup(s, n) _tor_strndup(s, n DMALLOC_ARGS) #define tor_memdup(s, n) _tor_memdup(s, n DMALLOC_ARGS) +void tor_log_mallinfo(int severity); + /** Return the offset of member within the type tp, in bytes */ #if defined(__GNUC__) && __GNUC__ > 3 #define STRUCT_OFFSET(tp, member) __builtin_offsetof(tp, member) diff --git a/src/or/main.c b/src/or/main.c index 25a0f32616..0086168a4d 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1550,6 +1550,7 @@ dumpmemusage(int severity) dump_routerlist_mem_usage(severity); dump_cell_pool_usage(severity); buf_dump_freelist_sizes(severity); + tor_log_mallinfo(severity); } /** Write all statistics to the log, with log level 'severity'. Called