[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r10996: Glibc (and maybe others) define a mallinfo() that can be use (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2007-07-30 14:14:14 -0400 (Mon, 30 Jul 2007)
New Revision: 10996

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/configure.in
   tor/trunk/src/common/util.c
   tor/trunk/src/common/util.h
   tor/trunk/src/or/main.c
Log:
 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().



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14024] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-07-30 17:51:51 UTC (rev 10995)
+++ tor/trunk/ChangeLog	2007-07-30 18:14:14 UTC (rev 10996)
@@ -3,11 +3,13 @@
     - 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

Modified: tor/trunk/configure.in
===================================================================
--- tor/trunk/configure.in	2007-07-30 17:51:51 UTC (rev 10995)
+++ tor/trunk/configure.in	2007-07-30 18:14:14 UTC (rev 10996)
@@ -152,7 +152,7 @@
 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 @@
 
 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 @@
 #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

Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c	2007-07-30 17:51:51 UTC (rev 10995)
+++ tor/trunk/src/common/util.c	2007-07-30 18:14:14 UTC (rev 10996)
@@ -213,6 +213,24 @@
   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
  * ===== */

Modified: tor/trunk/src/common/util.h
===================================================================
--- tor/trunk/src/common/util.h	2007-07-30 17:51:51 UTC (rev 10995)
+++ tor/trunk/src/common/util.h	2007-07-30 18:14:14 UTC (rev 10996)
@@ -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 @@
 #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)

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2007-07-30 17:51:51 UTC (rev 10995)
+++ tor/trunk/src/or/main.c	2007-07-30 18:14:14 UTC (rev 10996)
@@ -1550,6 +1550,7 @@
   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