--------------------- PatchSet 4650 Date: 2007/05/25 19:05:38 Author: adri Branch: squid3_adri Tag: (none) Log: * Implement non-zero'ing hooks into the allocator. * mark the various socket buffers and string data as non-zero'ed memory. (A runtime hook should be added to run squid with always-zero-memory for debugging/comparison.) Its too dangerous to turn this on for everything as plenty of places assume 0'ed memory for state structs; but buffers are pretty safe. Members: include/MemPool.h:1.12->1.12.2.1 lib/MemPool.cc:1.6->1.6.2.1 src/mem.cc:1.38->1.38.2.1 Index: squid3/include/MemPool.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/include/MemPool.h,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- squid3/include/MemPool.h 22 May 2007 16:52:03 -0000 1.12 +++ squid3/include/MemPool.h 25 May 2007 19:05:38 -0000 1.12.2.1 @@ -111,12 +111,15 @@ virtual size_t objectSize() const = 0; virtual int getInUseCount() = 0; int inUseCount(); + void DontZero() { dozero = false; } virtual void setChunkSize(size_t chunksize) {} + bool ShouldZero() const { return dozero; } // smallest size divisible by sizeof(void*) and at least minSize static size_t RoundedSize(size_t minSize); private: const char *label; + bool dozero; }; /* Support late binding of pool type for allocator agnostic classes */ Index: squid3/lib/MemPool.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/MemPool.cc,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- squid3/lib/MemPool.cc 22 May 2007 16:52:04 -0000 1.6 +++ squid3/lib/MemPool.cc 25 May 2007 19:05:38 -0000 1.6.2.1 @@ -1,6 +1,6 @@ /* - * $Id: MemPool.cc,v 1.6 2007/05/22 16:52:04 squidadm Exp $ + * $Id: MemPool.cc,v 1.6.2.1 2007/05/25 19:05:38 adri Exp $ * * DEBUG: section 63 Low Level Memory Pool Management * AUTHOR: Alex Rousskov, Andres Kroonmaa, Robert Collins @@ -271,7 +271,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 (ShouldZero()) + bzero(obj, obj_size); Free = (void **)obj; *Free = freeCache; freeCache = obj; @@ -832,7 +833,7 @@ return pools_inuse; } -MemAllocator::MemAllocator(char const *aLabel) : label(aLabel) +MemAllocator::MemAllocator(char const *aLabel) : label(aLabel), dozero(true) { } Index: squid3/src/mem.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/mem.cc,v retrieving revision 1.38 retrieving revision 1.38.2.1 diff -u -r1.38 -r1.38.2.1 --- squid3/src/mem.cc 22 May 2007 16:52:04 -0000 1.38 +++ squid3/src/mem.cc 25 May 2007 19:05:38 -0000 1.38.2.1 @@ -1,6 +1,6 @@ /* - * $Id: mem.cc,v 1.38 2007/05/22 16:52:04 squidadm Exp $ + * $Id: mem.cc,v 1.38.2.1 2007/05/25 19:05:38 adri Exp $ * * DEBUG: section 13 High Level Memory Pool Management * AUTHOR: Harvest Derived @@ -172,6 +172,13 @@ MemPools[type] = memPoolCreate(name, size); } +void +memDataNonZero(mem_type type) +{ + assert(MemPools[type] != NULL); + MemPools[type]->DontZero(); +} + /* find appropriate pool and use it (pools always init buffer with 0s) */ void * @@ -394,11 +401,17 @@ * malloc() for those? @?@ */ memDataInit(MEM_2K_BUF, "2K Buffer", 2048, 10); + memDataNonZero(MEM_2K_BUF); memDataInit(MEM_4K_BUF, "4K Buffer", 4096, 10); + memDataNonZero(MEM_4K_BUF); memDataInit(MEM_8K_BUF, "8K Buffer", 8192, 10); + memDataNonZero(MEM_8K_BUF); memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10); + memDataNonZero(MEM_16K_BUF); memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10); + memDataNonZero(MEM_32K_BUF); memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10); + memDataNonZero(MEM_64K_BUF); 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); @@ -424,6 +437,7 @@ for (i = 0; i < mem_str_pool_count; i++) { StrPools[i].pool = memPoolCreate(StrPoolsAttrs[i].name, StrPoolsAttrs[i].obj_size); + StrPools[i].pool->DontZero(); 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");