]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: adrian
authoradrian <>
Thu, 7 Feb 2008 09:51:06 +0000 (09:51 +0000)
committeradrian <>
Thu, 7 Feb 2008 09:51:06 +0000 (09:51 +0000)
Extend the Memory Allocator infrastructure to not need to zero buffers.

include/MemPool.h
lib/MemPool.cc
src/mem.cc
src/protos.h

index 3c12194515251299fc82f35546a37ed3d34ef924..8d524f2aaafc5d1375bc671dae2c4079a3a08979 100644 (file)
@@ -110,11 +110,14 @@ public:
     virtual char const *objectType() const;
     virtual size_t objectSize() const = 0;
     virtual int getInUseCount() = 0;
+    void zeroOnPush(bool doIt);
     int inUseCount();
     virtual void setChunkSize(size_t chunksize) {}
 
     // smallest size divisible by sizeof(void*) and at least minSize
     static size_t RoundedSize(size_t minSize);
+protected:
+    bool doZeroOnPush;
 private:
     const char *label;
 };
index 5983aafb45e860471df375814bd47dfe353b0777..a833d0230a4e3830131d29c1fa617c5af7b9ff47 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: MemPool.cc,v 1.11 2008/01/07 15:47:08 hno Exp $
+ * $Id: MemPool.cc,v 1.12 2008/02/07 02:51:13 adrian Exp $
  *
  * DEBUG: section 63    Low Level Memory Pool Management
  * AUTHOR: Alex Rousskov, Andres Kroonmaa, Robert Collins
@@ -273,7 +273,8 @@ MemPool::push(void *obj)
      * not really need to be cleared.. There was a condition based on
      * the object size here, but such condition is not safe.
      */
-    memset(obj, 0, obj_size);
+    if (doZeroOnPush)
+        memset(obj, 0, obj_size);
     Free = (void **)obj;
     *Free = freeCache;
     freeCache = obj;
@@ -838,7 +839,7 @@ memPoolGetGlobalStats(MemPoolGlobalStats * stats)
     return pools_inuse;
 }
 
-MemAllocator::MemAllocator(char const *aLabel) : label(aLabel)
+MemAllocator::MemAllocator(char const *aLabel) : doZeroOnPush(true), label(aLabel)
 {
 }
 
@@ -938,6 +939,12 @@ MemImplementingAllocator::MemImplementingAllocator(char const *aLabel, size_t aS
 {
 }
 
+void
+MemAllocator::zeroOnPush(bool doIt)
+{
+       doZeroOnPush = doIt;
+}
+
 MemPoolMeter const &
 MemImplementingAllocator::getMeter() const
 {
index 8d4b005243db8cbe7254ebf2da732048c5738eeb..9f0bce2d3dea6eb3e9c3f7194c1aa806a65dfabb 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mem.cc,v 1.107 2008/01/22 17:13:36 rousskov Exp $
+ * $Id: mem.cc,v 1.108 2008/02/07 02:51:17 adrian Exp $
  *
  * DEBUG: section 13    High Level Memory Pool Management
  * AUTHOR: Harvest Derived
@@ -165,11 +165,12 @@ Mem::Stats(StoreEntry * sentry)
  * max_pages for now
  */
 void
-memDataInit(mem_type type, const char *name, size_t size, int max_pages_notused)
+memDataInit(mem_type type, const char *name, size_t size, int max_pages_notused, bool zeroOnPush)
 {
     assert(name && size);
     assert(MemPools[type] == NULL);
     MemPools[type] = memPoolCreate(name, size);
+    MemPools[type]->zeroOnPush(zeroOnPush);
 }
 
 
@@ -391,12 +392,12 @@ Mem::Init(void)
      * that are never used or used only once; perhaps we should simply use
      * malloc() for those? @?@
      */
-    memDataInit(MEM_2K_BUF, "2K Buffer", 2048, 10);
-    memDataInit(MEM_4K_BUF, "4K Buffer", 4096, 10);
-    memDataInit(MEM_8K_BUF, "8K Buffer", 8192, 10);
-    memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10);
-    memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10);
-    memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10);
+    memDataInit(MEM_2K_BUF, "2K Buffer", 2048, 10, false);
+    memDataInit(MEM_4K_BUF, "4K Buffer", 4096, 10, false);
+    memDataInit(MEM_8K_BUF, "8K Buffer", 8192, 10, false);
+    memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10, false);
+    memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10, false);
+    memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10, false);
     memDataInit(MEM_ACL_DENY_INFO_LIST, "acl_deny_info_list",
                 sizeof(acl_deny_info_list), 0);
     memDataInit(MEM_ACL_NAME_LIST, "acl_name_list", sizeof(acl_name_list), 0);
@@ -422,6 +423,7 @@ Mem::Init(void)
 
     for (i = 0; i < mem_str_pool_count; i++) {
         StrPools[i].pool = memPoolCreate(StrPoolsAttrs[i].name, StrPoolsAttrs[i].obj_size);
+        StrPools[i].pool->zeroOnPush(false);
 
         if (StrPools[i].pool->objectSize() != StrPoolsAttrs[i].obj_size)
             debugs(13, 1, "Notice: " << StrPoolsAttrs[i].name << " is " << StrPools[i].pool->objectSize() << " bytes instead of requested " << StrPoolsAttrs[i].obj_size << " bytes");
index 6b6d742f6bc7da09c1bcfb1be5de6c47ff445bbf..0e1e76ed3d2393984ec05ea7069f304e4f07304e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.554 2008/01/24 19:20:43 serassio Exp $
+ * $Id: protos.h,v 1.555 2008/02/07 02:51:18 adrian Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -496,7 +496,7 @@ SQUIDCEXTERN void memFreeString(size_t size, void *);
 SQUIDCEXTERN void memFreeBuf(size_t size, void *);
 SQUIDCEXTERN FREE *memFreeBufFunc(size_t size);
 SQUIDCEXTERN int memInUse(mem_type);
-SQUIDCEXTERN void memDataInit(mem_type, const char *, size_t, int);
+SQUIDCEXTERN void memDataInit(mem_type, const char *, size_t, int, bool zeroOnPush = true);
 SQUIDCEXTERN void memCheckInit(void);