]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4043: Remove XMALLOC_TRACE and references to sbrk(2)
authorFrancesco Chemolli <kinkie@squid-cache.org>
Sun, 23 Mar 2014 05:00:54 +0000 (23:00 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 23 Mar 2014 05:00:54 +0000 (23:00 -0600)
compat/xalloc.cc
configure.ac
include/squid.h
include/util.h
lib/malloc_trace.cc
src/globals.h
src/main.cc
src/mgr/InfoAction.cc
src/mgr/InfoAction.h
src/stat.cc

index 3f3a9ae13dd7fdba5e3b1fb0ee1c50e0e7998857..144af386e281ea84eadbe154ebd79c2adc7ad6ca 100644 (file)
@@ -92,9 +92,6 @@ xcalloc(size_t n, size_t sz)
 #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 @@ xmalloc(size_t sz)
 #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 @@ void *
 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 @@ xrealloc(void *s, size_t sz)
 #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 @@ free_const(const void *s_const)
     void *s = const_cast<void *>(s_const);
 
     PROF_start(free_const);
-#if XMALLOC_TRACE
-    xmalloc_show_trace(s, -1);
-#endif
 
 #if XMALLOC_DEBUG
     check_free(s);
index 6ab6ce2cd669a6115d3972124991513395dfcf45..a327965d0e809732002baf4cbdf13e128c2c342d 100644 (file)
@@ -459,18 +459,6 @@ dnl     AC_DEFINE(XMALLOC_DEBUG,1,[Define to do simple malloc debugging])
 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 @@ AC_CHECK_FUNCS(\
        res_init \
        __res_init \
        rint \
-       sbrk \
        sched_getaffinity \
        sched_setaffinity \
        select \
index 2e9c7d52f6128a7d005cc6cecfde471d54825914..306abd1948c2a68e15e54eb81c857bc4e9eac518 100644 (file)
 /*
  * 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
 
index 08174754f4812f77287055096a9af8b4ee097e30..45504e02805e1e9ab678794b92dd810bc00dbb7f 100644 (file)
@@ -63,20 +63,6 @@ SQUIDCEXTERN void Tolower(char *);
 #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);
index 358e01b6c38a5afa4ff1f595088336df38fa9187..a55f10dc512689d672bea3649ee344915ce79c63 100644 (file)
@@ -87,30 +87,11 @@ log_trace_done()
 
 #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 @@ check_init(void)
         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 @@ check_free(void *s)
             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 @@ check_malloc(void *p, size_t sz)
             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 @@ check_malloc(void *p, size_t sz)
 
 #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 */
index c713470ee679a86507621fde882a6699990ae3f5..3179ef299b322cc613efadf64d31052e78b607cd 100644 (file)
@@ -126,9 +126,6 @@ extern char *WIN32_Command_Line;        /* NULL */
 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 */
index a6a8b27a74afcf0ddd929724fe468d7e99449a6b..462eb73b72e6d700c437fe7255c98cf5358b3ded 100644 (file)
@@ -501,13 +501,7 @@ mainParseOptions(int argc, char *argv[])
                 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 @@ SquidMain(int argc, char **argv)
 {
     ConfigureCurrentKid(argv[0]);
 
-#if HAVE_SBRK
-    sbrk_start = sbrk(0);
-#endif
-
     Debug::parseOptions(NULL);
     debug_log = stderr;
 
@@ -1926,15 +1916,6 @@ SquidShutdown()
     eventFreeMemory();
     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 @@ SquidShutdown()
 
     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();
index dc9e6c1df184d4fea6d1e7008f596ba9feb26bca..eeb8fe42165dbe502af9eb0b899d04e354469092 100644 (file)
@@ -81,9 +81,6 @@ Mgr::InfoActionData::operator += (const InfoActionData& stats)
     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 @@ Mgr::InfoActionData::operator += (const InfoActionData& stats)
     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;
index f5cdc6097be0e4d5ae3ac90c3b46f00720922f4f..bc598430a5d669b3c96b8fd5db847c5492a83fda 100644 (file)
@@ -68,9 +68,6 @@ public:
     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 @@ public:
     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;
index 59db7e56a2b78a66b331cc8639db6d79b231e75d..0436621914aa6ff6f03f99061c76fbf4f068f8a6 100644 (file)
@@ -591,12 +591,6 @@ GetInfo(Mgr::InfoActionData& stats)
     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 @@ DumpInfo(Mgr::InfoActionData& stats, StoreEntry* sentry)
     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 @@ statAvgTick(void *notused)
     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");
     }