------------------------------------------------------------ revno: 13111 revision-id: squid3@treenet.co.nz-20140323050054-q7pxoz6kuacz8pe3 parent: squid3@treenet.co.nz-20140323045740-seryw2e2ubpk33bw fixes bug(s): http://bugs.squid-cache.org/show_bug.cgi?id=4043 author: Francesco Chemolli committer: Amos Jeffries branch nick: 3.4 timestamp: Sat 2014-03-22 23:00:54 -0600 message: Bug 4043: Remove XMALLOC_TRACE and references to sbrk(2) ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140323050054-q7pxoz6kuacz8pe3 # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.4 # testament_sha1: 343b12fa9b98c9e2ba413afaf5f49e86ae5e0bc6 # timestamp: 2014-03-23 05:01:56 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.4 # base_revision_id: squid3@treenet.co.nz-20140323045740-\ # seryw2e2ubpk33bw # # Begin patch === modified file 'compat/xalloc.cc' --- compat/xalloc.cc 2012-07-02 12:14:07 +0000 +++ compat/xalloc.cc 2014-03-23 05:00:54 +0000 @@ -92,9 +92,6 @@ #if XMALLOC_STATISTICS malloc_stat(sz * n); #endif -#if XMALLOC_TRACE - xmalloc_show_trace(p, 1); -#endif #if MEM_GEN_TRACE if (tracefp) fprintf(tracefp, "c:%u:%u:%p\n", (unsigned int) n, (unsigned int) sz, p); @@ -133,9 +130,6 @@ #if XMALLOC_STATISTICS malloc_stat(sz); #endif -#if XMALLOC_TRACE - xmalloc_show_trace(p, 1); -#endif #if MEM_GEN_TRACE if (tracefp) fprintf(tracefp, "m:%d:%p\n", sz, p); @@ -149,9 +143,6 @@ xrealloc(void *s, size_t sz) { PROF_start(xrealloc); -#if XMALLOC_TRACE - xmalloc_show_trace(s, -1); -#endif if (sz < 1) sz = 1; @@ -182,9 +173,6 @@ #if XMALLOC_STATISTICS malloc_stat(sz); #endif -#if XMALLOC_TRACE - xmalloc_show_trace(p, 1); -#endif #if MEM_GEN_TRACE if (tracefp) /* new ptr, old ptr, new size */ fprintf(tracefp, "r:%p:%p:%d\n", p, s, sz); @@ -199,9 +187,6 @@ void *s = const_cast(s_const); PROF_start(free_const); -#if XMALLOC_TRACE - xmalloc_show_trace(s, -1); -#endif #if XMALLOC_DEBUG check_free(s); === modified file 'configure.ac' --- configure.ac 2014-03-23 04:57:40 +0000 +++ configure.ac 2014-03-23 05:00:54 +0000 @@ -459,18 +459,6 @@ dnl fi dnl ]) -dnl This is a developer only option.. developers know how to set defines -dnl -dnl AC_ARG_ENABLE(xmalloc-debug-trace, -dnl [ --enable-xmalloc-debug-trace -dnl Detailed trace of memory allocations], -dnl [ if test "$enableval" = "yes" ; then -dnl AC_MSG_NOTICE([malloc debug trace enabled]) -dnl AC_DEFINE(XMALLOC_TRACE,1,[Define to have a detailed trace of memory allocations]) -dnl AC_DEFINE(XMALLOC_DEBUG,1) -dnl fi -dnl ]) - AH_TEMPLATE(XMALLOC_STATISTICS,[Define to have malloc statistics]) AC_ARG_ENABLE(xmalloc-statistics, AS_HELP_STRING([--enable-xmalloc-statistics], @@ -3095,7 +3083,6 @@ res_init \ __res_init \ rint \ - sbrk \ sched_getaffinity \ sched_setaffinity \ select \ === modified file 'include/squid.h' --- include/squid.h 2012-10-11 07:19:02 +0000 +++ include/squid.h 2014-03-23 05:00:54 +0000 @@ -103,11 +103,7 @@ /* * Determine if this is a leak check build or standard */ -#if PURIFY -#define LEAK_CHECK_MODE 1 -#elif WITH_VALGRIND -#define LEAK_CHECK_MODE 1 -#elif XMALLOC_TRACE +#if PURIFY || WITH_VALGRIND #define LEAK_CHECK_MODE 1 #endif === modified file 'include/util.h' --- include/util.h 2012-10-09 09:23:00 +0000 +++ include/util.h 2014-03-23 05:00:54 +0000 @@ -63,20 +63,6 @@ #include "SquidNew.h" #endif -#if XMALLOC_TRACE -#define xmalloc(size) (xmalloc_func="xmalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xmalloc(size)) -#define xfree(ptr) (xmalloc_func="xfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xfree(ptr)) -#define xrealloc(ptr,size) (xmalloc_func="xrealloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xrealloc(ptr,size)) -#define xcalloc(n,size) (xmalloc_func="xcalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xcalloc(n,size)) -#define xstrdup(ptr) (xmalloc_func="xstrdup",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xstrdup(ptr)) -extern int xmalloc_line; -extern char *xmalloc_file; -extern char *xmalloc_func; -extern int xmalloc_trace; -extern size_t xmalloc_total; -extern void xmalloc_find_leaks(void); -#endif - SQUIDCEXTERN time_t parse_iso3307_time(const char *buf); SQUIDCEXTERN double xpercent(double part, double whole); === modified file 'lib/malloc_trace.cc' --- lib/malloc_trace.cc 2012-09-01 14:38:36 +0000 +++ lib/malloc_trace.cc 2014-03-23 05:00:54 +0000 @@ -87,30 +87,11 @@ #endif -#if XMALLOC_TRACE -char *xmalloc_file = ""; -int xmalloc_line = 0; -char *xmalloc_func = ""; -static int xmalloc_count = 0; -int xmalloc_trace = 0; /* Enable with -m option */ -size_t xmalloc_total = 0; -#undef xmalloc -#undef xfree -#undef xrealloc -#undef xcalloc -#undef xstrdup -#endif - #if XMALLOC_DEBUG #define DBG_ARRY_SZ (1<<11) #define DBG_ARRY_BKTS (1<<8) static void *(*malloc_ptrs)[DBG_ARRY_SZ]; static int malloc_size[DBG_ARRY_BKTS][DBG_ARRY_SZ]; -#if XMALLOC_TRACE -static char *malloc_file[DBG_ARRY_BKTS][DBG_ARRY_SZ]; -static short malloc_line[DBG_ARRY_BKTS][DBG_ARRY_SZ]; -static int malloc_count[DBG_ARRY_BKTS][DBG_ARRY_SZ]; -#endif static int dbg_initd = 0; #define DBG_HASH_BUCKET(ptr) (((((int)ptr)>>4)+(((int)ptr)>>12)+(((int)ptr)>>20))&0xFF) @@ -126,13 +107,6 @@ for (I = 0; I < DBG_ARRY_SZ; ++I) { malloc_ptrs[B][I] = NULL; malloc_size[B][I] = 0; -#if XMALLOC_TRACE - - malloc_file[B][I] = NULL; - malloc_line[B][I] = 0; - malloc_count[B][I] = 0; -#endif - } } @@ -150,19 +124,7 @@ continue; malloc_ptrs[B][I] = NULL; - malloc_size[B][I] = 0; - -#if XMALLOC_TRACE - - malloc_file[B][I] = NULL; - - malloc_line[B][I] = 0; - - malloc_count[B][I] = 0; - -#endif - break; } @@ -209,19 +171,7 @@ continue; malloc_ptrs[B][I] = p; - malloc_size[B][I] = (int) sz; - -#if XMALLOC_TRACE - - malloc_file[B][I] = xmalloc_file; - - malloc_line[B][I] = xmalloc_line; - - malloc_count[B][I] = xmalloc_count; - -#endif - break; } @@ -235,189 +185,3 @@ #endif -#if XMALLOC_TRACE && !HAVE_MALLOCBLKSIZE -size_t -xmallocblksize(void *p) -{ - int B, I; - B = DBG_HASH_BUCKET(p); - - for (I = 0; I < DBG_ARRY_SZ; ++I) { - if (malloc_ptrs[B][I] == p) - return malloc_size[B][I]; - } - - return 0; -} - -#endif - -#ifdef XMALLOC_TRACE -static char * -malloc_file_name(void *p) -{ - int B, I; - B = DBG_HASH_BUCKET(p); - - for (I = 0; I < DBG_ARRY_SZ; ++I) { - if (malloc_ptrs[B][I] == p) - return malloc_file[B][I]; - } - - return 0; -} - -int -malloc_line_number(void *p) -{ - int B, I; - B = DBG_HASH_BUCKET(p); - - for (I = 0; I < DBG_ARRY_SZ; ++I) { - if (malloc_ptrs[B][I] == p) - return malloc_line[B][I]; - } - - return 0; -} - -int -malloc_number(void *p) -{ - int B, I; - B = DBG_HASH_BUCKET(p); - - for (I = 0; I < DBG_ARRY_SZ; ++I) { - if (malloc_ptrs[B][I] == p) - return malloc_count[B][I]; - } - - return 0; -} - -static void -xmalloc_show_trace(void *p, int sign) -{ - int statMemoryAccounted(); - static size_t last_total = 0, last_accounted = 0, last_mallinfo = 0; - size_t accounted = statMemoryAccounted(); - size_t mi = 0; - size_t sz; -#if HAVE_MALLINFO - - struct mallinfo mp = mallinfo(); - mi = mp.uordblks + mp.usmblks + mp.hblkhd; -#endif - - sz = xmallocblksize(p) * sign; - xmalloc_total += sz; - xmalloc_count += sign > 0; - - if (xmalloc_trace) { - fprintf(stderr, "%c%8p size=%5d/%d acc=%5d/%d mallinfo=%5d/%d %s:%d %s", - sign > 0 ? '+' : '-', p, - (int) xmalloc_total - last_total, (int) xmalloc_total, - (int) accounted - last_accounted, (int) accounted, - (int) mi - last_mallinfo, (int) mi, - xmalloc_file, xmalloc_line, xmalloc_func); - - if (sign < 0) - fprintf(stderr, " (%d %s:%d)\n", malloc_number(p), malloc_file_name(p), malloc_line_number(p)); - else - fprintf(stderr, " %d\n", xmalloc_count); - } - - last_total = xmalloc_total; - last_accounted = accounted; - last_mallinfo = mi; -} - -short malloc_refs[DBG_ARRY_BKTS][DBG_ARRY_SZ]; -#define XMALLOC_LEAK_ALIGN (4) -static void -xmalloc_scan_region(void *start, int size, int depth) -{ - int B, I; - char *ptr = start; - char *end = ptr + size - XMALLOC_LEAK_ALIGN; - static int sum = 0; - - while (ptr <= end) { - void *p = *(void **) ptr; - - if (p && p != start) { - B = DBG_HASH_BUCKET(p); - - for (I = 0; I < DBG_ARRY_SZ; ++I) { - if (malloc_ptrs[B][I] == p) { - if (!malloc_refs[B][I]++) { - /* A new reference */ - fprintf(stderr, "%*s%p %s:%d size %d allocation %d\n", - depth, "", - malloc_ptrs[B][I], malloc_file[B][I], - malloc_line[B][I], malloc_size[B][I], - malloc_count[B][I]); - sum += malloc_size[B][I]; - xmalloc_scan_region(malloc_ptrs[B][I], malloc_size[B][I], depth + 1); - - if (depth == 0) { - if (sum != malloc_size[B][I]) - fprintf(stderr, "=== %d bytes\n", sum); - - sum = 0; - } - -#if XMALLOC_SHOW_ALL_REFERENCES - - } else { - /* We have already scanned this pointer... */ - fprintf(stderr, "%*s%p %s:%d size %d allocation %d ... (%d)\n", - depth * 2, "", - malloc_ptrs[B][I], malloc_file[B][I], - malloc_line[B][I], malloc_size[B][I], - malloc_count[B][I], malloc_refs[B][I]); -#endif - - } - } - } - } - - ptr += XMALLOC_LEAK_ALIGN; - } -} - -void -xmalloc_find_leaks(void) -{ - int B, I; - int leak_sum = 0; - - extern void _etext; - fprintf(stderr, "----- Memory map ----\n"); - xmalloc_scan_region(&_etext, (void *) sbrk(0) - (void *) &_etext, 0); - - for (B = 0; B < DBG_ARRY_BKTS; ++B) { - for (I = 0; I < DBG_ARRY_SZ; ++I) { - if (malloc_ptrs[B][I] && malloc_refs[B][I] == 0) { - /* Found a leak... */ - fprintf(stderr, "Leak found: %p", malloc_ptrs[B][I]); - fprintf(stderr, " %s", malloc_file[B][I]); - fprintf(stderr, ":%d", malloc_line[B][I]); - fprintf(stderr, " size %d", malloc_size[B][I]); - fprintf(stderr, " allocation %d\n", malloc_count[B][I]); - leak_sum += malloc_size[B][I]; - } - } - } - - if (leak_sum) { - fprintf(stderr, "Total leaked memory: %d\n", leak_sum); - } else { - fprintf(stderr, "No memory leaks detected\n"); - } - - fprintf(stderr, "----------------------\n"); -} - -#endif /* XMALLOC_TRACE */ === modified file 'src/globals.h' --- src/globals.h 2013-08-08 06:00:28 +0000 +++ src/globals.h 2014-03-23 05:00:54 +0000 @@ -126,9 +126,6 @@ extern char *WIN32_Service_Command_Line; /* NULL */ extern unsigned int WIN32_run_mode; /* _WIN_SQUID_RUN_MODE_INTERACTIVE */ #endif -#if HAVE_SBRK -extern void *sbrk_start; /* 0 */ -#endif extern int ssl_ex_index_server; /* -1 */ extern int ssl_ctx_ex_index_dont_verify_domain; /* -1 */ === modified file 'src/main.cc' --- src/main.cc 2014-02-02 02:41:49 +0000 +++ src/main.cc 2014-03-23 05:00:54 +0000 @@ -501,13 +501,7 @@ fatal("Need to add -DMALLOC_DBG when compiling to use -mX option"); #endif - } else { -#if XMALLOC_TRACE - xmalloc_trace = !xmalloc_trace; -#else - fatal("Need to configure --enable-xmalloc-debug-trace to use -m option"); -#endif - } + } break; #if USE_WIN32_SERVICE @@ -1302,10 +1296,6 @@ { ConfigureCurrentKid(argv[0]); -#if HAVE_SBRK - sbrk_start = sbrk(0); -#endif - Debug::parseOptions(NULL); debug_log = stderr; @@ -1927,15 +1917,6 @@ mimeFreeMemory(); errorClean(); #endif -#if !XMALLOC_TRACE - - if (opt_no_daemon) { - file_close(0); - file_close(1); - file_close(2); - } - -#endif // clear StoreController Store::Root(NULL); @@ -1945,13 +1926,6 @@ memClean(); -#if XMALLOC_TRACE - - xmalloc_find_leaks(); - - debugs(1, DBG_CRITICAL, "Memory used after shutdown: " << xmalloc_total); - -#endif #if MEM_GEN_TRACE log_trace_done(); === modified file 'src/mgr/InfoAction.cc' --- src/mgr/InfoAction.cc 2013-07-26 03:12:33 +0000 +++ src/mgr/InfoAction.cc 2014-03-23 05:00:54 +0000 @@ -81,9 +81,6 @@ cpu_usage += stats.cpu_usage; cpu_usage5 += stats.cpu_usage5; cpu_usage60 += stats.cpu_usage60; -#if HAVE_SBRK - proc_data_seg += stats.proc_data_seg; -#endif maxrss += stats.maxrss; page_faults += stats.page_faults; #if HAVE_MSTATS && HAVE_GNUMALLOC_H @@ -106,8 +103,8 @@ mp_uordbytes += stats.mp_uordbytes; mp_allocated += stats.mp_allocated; mp_treeoverhead += stats.mp_treeoverhead; -#endif -#endif +#endif /* HAVE_STRUCT_MALLINFO_MXFAST */ +#endif /* HAVE_MALLINFO && HAVE_STRUCT_MALLINFO */ total_accounted += stats.total_accounted; #if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO mem_pool_allocated += stats.mem_pool_allocated; === modified file 'src/mgr/InfoAction.h' --- src/mgr/InfoAction.h 2013-10-03 11:02:34 +0000 +++ src/mgr/InfoAction.h 2014-03-23 05:00:54 +0000 @@ -68,9 +68,6 @@ double cpu_usage; double cpu_usage5; double cpu_usage60; -#if HAVE_SBRK - double proc_data_seg; -#endif double maxrss; double page_faults; #if HAVE_MSTATS && HAVE_GNUMALLOC_H @@ -93,8 +90,8 @@ double mp_uordbytes; double mp_allocated; double mp_treeoverhead; -#endif -#endif +#endif /* HAVE_STRUCT_MALLINFO_MXFAST */ +#endif /* HAVE_MALLINFO && HAVE_STRUCT_MALLINFO */ double total_accounted; #if !(HAVE_MSTATS && HAVE_GNUMALLOC_H) && HAVE_MALLINFO && HAVE_STRUCT_MALLINFO double mem_pool_allocated; === modified file 'src/stat.cc' --- src/stat.cc 2013-09-08 03:22:37 +0000 +++ src/stat.cc 2014-03-23 05:00:54 +0000 @@ -591,12 +591,6 @@ stats.cpu_usage5 = statCPUUsage(5); stats.cpu_usage60 = statCPUUsage(60); -#if HAVE_SBRK - - stats.proc_data_seg = ((char *) sbrk(0) - (char *) sbrk_start); - -#endif - stats.maxrss = rusage_maxrss(&rusage); stats.page_faults = rusage_pagefaults(&rusage); @@ -815,13 +809,6 @@ storeAppendPrintf(sentry, "\tCPU Usage, 60 minute avg:\t%.2f%%\n", stats.cpu_usage60); -#if HAVE_SBRK - - storeAppendPrintf(sentry, "\tProcess Data Segment Size via sbrk(): %.0f KB\n", - stats.proc_data_seg / 1024); - -#endif - storeAppendPrintf(sentry, "\tMaximum Resident Size: %.0f KB\n", stats.maxrss); @@ -1462,18 +1449,12 @@ if (Config.warnings.high_memory) { size_t i = 0; #if HAVE_MSTATS && HAVE_GNUMALLOC_H - struct mstats ms = mstats(); i = ms.bytes_total; #elif HAVE_MALLINFO && HAVE_STRUCT_MALLINFO - struct mallinfo mp = mallinfo(); i = mp.arena; -#elif HAVE_SBRK - - i = (size_t) ((char *) sbrk(0) - (char *) sbrk_start); #endif - if (Config.warnings.high_memory < i) debugs(18, DBG_CRITICAL, "WARNING: Memory usage at " << ((unsigned long int)(i >> 20)) << " MB"); }