--------------------- PatchSet 11380 Date: 2008/02/07 02:51:06 Author: Adrian Chadd Branch: HEAD Tag: (none) Log: Author: Adrian Chadd Extend the Memory Allocator infrastructure to not need to zero buffers. Members: include/MemPool.h:1.18->1.19 lib/MemPool.cc:1.11->1.12 src/mem.cc:1.107->1.108 src/protos.h:1.554->1.555 Index: squid3/include/MemPool.h =================================================================== RCS file: /cvsroot/squid/squid3/include/MemPool.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- squid3/include/MemPool.h 13 Nov 2007 23:25:33 -0000 1.18 +++ squid3/include/MemPool.h 7 Feb 2008 02:51:06 -0000 1.19 @@ -110,11 +110,14 @@ 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: squid3/lib/MemPool.cc =================================================================== RCS file: /cvsroot/squid/squid3/lib/MemPool.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- squid3/lib/MemPool.cc 7 Jan 2008 15:47:08 -0000 1.11 +++ squid3/lib/MemPool.cc 7 Feb 2008 02:51:13 -0000 1.12 @@ -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 @@ * 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 @@ return pools_inuse; } -MemAllocator::MemAllocator(char const *aLabel) : label(aLabel) +MemAllocator::MemAllocator(char const *aLabel) : doZeroOnPush(true), label(aLabel) { } @@ -938,6 +939,12 @@ { } +void +MemAllocator::zeroOnPush(bool doIt) +{ + doZeroOnPush = doIt; +} + MemPoolMeter const & MemImplementingAllocator::getMeter() const { Index: squid3/src/mem.cc =================================================================== RCS file: /cvsroot/squid/squid3/src/mem.cc,v retrieving revision 1.107 retrieving revision 1.108 diff -u -r1.107 -r1.108 --- squid3/src/mem.cc 22 Jan 2008 17:13:36 -0000 1.107 +++ squid3/src/mem.cc 7 Feb 2008 02:51:17 -0000 1.108 @@ -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 @@ * 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 @@ * 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 @@ 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: squid3/src/protos.h =================================================================== RCS file: /cvsroot/squid/squid3/src/protos.h,v retrieving revision 1.554 retrieving revision 1.555 diff -u -r1.554 -r1.555 --- squid3/src/protos.h 24 Jan 2008 19:20:43 -0000 1.554 +++ squid3/src/protos.h 7 Feb 2008 02:51:18 -0000 1.555 @@ -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 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);