Browse Source

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

Nick Mathewson 17 years ago
parent
commit
45c82b1d85
5 changed files with 31 additions and 4 deletions
  1. 3 1
      ChangeLog
  2. 4 3
      configure.in
  3. 18 0
      src/common/util.c
  4. 5 0
      src/common/util.h
  5. 1 0
      src/or/main.c

+ 3 - 1
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

+ 4 - 3
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

+ 18 - 0
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
  * ===== */

+ 5 - 0
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)

+ 1 - 0
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