diff --git a/ChangeLog b/ChangeLog index f68ece213031fe59db8ee809bf43309ec16e5572..668473a543d78459c14ee79630fb4f4de75ffa97 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 1a77d6c16f73ebbe790197e8a8ec73d1225c46af..3cc14fcbec987443af6b0ed47f7f69895c7b54db 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 991cda1a97d69c1f7bfe946649b801793087a24e..580f078afeccce9f356fbbbf2d32fa807107ab1a 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 3cd19c06c0a7e59533d3fa76b81cfc047e9000a8..b0db03f149ec5e7b8433f682f5910acf7798d263 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -23,6 +23,9 @@ #ifdef HAVE_TIME_H #include <time.h> #endif +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#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 <b>member</b> within the type <b>tp</b>, 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 25a0f3261688dfeca8ccd102f70b97620efc35d0..0086168a4d50b3beb0ec42c30f6703a3bcabb789 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