--------------------- PatchSet 11684 Date: 2007/09/21 09:35:41 Author: adrian Branch: HEAD Tag: (none) Log: Some simple modifications to avoid zero'ing some buffers, make it a configuration option. Members: src/MemPool.c:1.39->1.40 src/cf.data.pre:1.425->1.426 src/mem.c:1.73->1.74 src/protos.h:1.535->1.536 src/structs.h:1.524->1.525 Index: squid/src/MemPool.c =================================================================== RCS file: /cvsroot/squid/squid/src/MemPool.c,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- squid/src/MemPool.c 18 Sep 2006 22:54:39 -0000 1.39 +++ squid/src/MemPool.c 21 Sep 2007 09:35:41 -0000 1.40 @@ -1,6 +1,6 @@ /* - * $Id: MemPool.c,v 1.39 2006/09/18 22:54:39 hno Exp $ + * $Id: MemPool.c,v 1.40 2007/09/21 09:35:41 adrian Exp $ * * DEBUG: section 63 Low Level Memory Pool Management * AUTHOR: Alex Rousskov @@ -217,6 +217,7 @@ #if DEBUG_MEMPOOL pool->real_obj_size = (obj_size & 7) ? (obj_size | 7) + 1 : obj_size; #endif + pool->flags.dozero = 1; stackInit(&pool->pstack); /* other members are set to 0 */ stackPush(&Pools, pool); @@ -224,6 +225,12 @@ } void +memPoolNonZero(MemPool * p) +{ + p->flags.dozero = 0; +} + +void memPoolDestroy(MemPool * pool) { int i; @@ -292,7 +299,10 @@ (void) VALGRIND_MAKE_NOACCESS(cookie, sizeof(cookie)); } #else - obj = xcalloc(1, pool->obj_size); + if (Config.onoff.zero_buffers || pool->flags.dozero) + obj = xcalloc(1, pool->obj_size); + else + obj = xmalloc(pool->obj_size); #endif } return obj; @@ -317,7 +327,8 @@ if (TheMeter.idle.level + pool->obj_size <= mem_idle_limit) { memMeterInc(pool->meter.idle); memMeterAdd(TheMeter.idle, pool->obj_size); - memset(obj, 0, pool->obj_size); + if (Config.onoff.zero_buffers || pool->flags.dozero) + memset(obj, 0, pool->obj_size); #if DEBUG_MEMPOOL (void) VALGRIND_MAKE_NOACCESS(obj, pool->real_obj_size + sizeof(struct mempool_cookie)); #else Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid/squid/src/cf.data.pre,v retrieving revision 1.425 retrieving revision 1.426 diff -u -r1.425 -r1.426 --- squid/src/cf.data.pre 19 Sep 2007 20:48:14 -0000 1.425 +++ squid/src/cf.data.pre 21 Sep 2007 09:35:41 -0000 1.426 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.425 2007/09/19 20:48:14 hno Exp $ +# $Id: cf.data.pre,v 1.426 2007/09/21 09:35:41 adrian Exp $ # # SQUID Web Proxy Cache http://www.squid-cache.org/ # ---------------------------------------------------------- @@ -5284,4 +5284,17 @@ rounded to 1000. DOC_END +NAME: zero_buffers +COMMENT: on|off +TYPE: onoff +LOC: Config.onoff.zero_buffers +DEFAULT: on +DOC_START + Squid by default will zero all buffers before using or reusing them. + Setting this to 'off' will result in fixed-sized temporary buffers + not being zero'ed. This may give a performance boost on certain + platforms but it may result in undefined behaviour at the present + time. +DOC_END + EOF Index: squid/src/mem.c =================================================================== RCS file: /cvsroot/squid/squid/src/mem.c,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- squid/src/mem.c 20 May 2006 21:51:49 -0000 1.73 +++ squid/src/mem.c 21 Sep 2007 09:35:42 -0000 1.74 @@ -1,6 +1,6 @@ /* - * $Id: mem.c,v 1.73 2006/05/20 21:51:49 hno Exp $ + * $Id: mem.c,v 1.74 2007/09/21 09:35:42 adrian Exp $ * * DEBUG: section 13 High Level Memory Pool Management * AUTHOR: Harvest Derived @@ -146,6 +146,12 @@ MemPools[type] = memPoolCreate(name, size); } +void +memDataNonZero(mem_type type) +{ + memPoolNonZero(MemPools[type]); +} + /* find appropriate pool and use it (pools always init buffer with 0s) */ void * @@ -294,11 +300,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_CLIENT_SOCK_BUF, "Client Socket Buffer", CLIENT_SOCK_SZ, 0); memDataInit(MEM_ACL, "acl", sizeof(acl), 0); memDataInit(MEM_ACL_DENY_INFO_LIST, "acl_deny_info_list", @@ -337,6 +349,7 @@ memDataInit(MEM_MEMOBJECT, "MemObject", sizeof(MemObject), Squid_MaxFD >> 3); memDataInit(MEM_MEM_NODE, "mem_node", sizeof(mem_node), 0); + memDataNonZero(MEM_MEM_NODE); memDataInit(MEM_NETDBENTRY, "netdbEntry", sizeof(netdbEntry), 0); memDataInit(MEM_NET_DB_NAME, "net_db_name", sizeof(net_db_name), 0); memDataInit(MEM_RELIST, "relist", sizeof(relist), 0); @@ -356,6 +369,7 @@ /* init string pools */ for (i = 0; i < mem_str_pool_count; i++) { StrPools[i].pool = memPoolCreate(StrPoolsAttrs[i].name, StrPoolsAttrs[i].obj_size); + memPoolNonZero(StrPools[i].pool); } cachemgrRegister("mem", "Memory Utilization", Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid/squid/src/protos.h,v retrieving revision 1.535 retrieving revision 1.536 diff -u -r1.535 -r1.536 --- squid/src/protos.h 18 Sep 2007 14:43:32 -0000 1.535 +++ squid/src/protos.h 21 Sep 2007 09:35:42 -0000 1.536 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.535 2007/09/18 14:43:32 adrian Exp $ + * $Id: protos.h,v 1.536 2007/09/21 09:35:42 adrian Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -879,6 +879,7 @@ /* MemPool */ extern MemPool *memPoolCreate(const char *label, size_t obj_size); extern void memPoolDestroy(MemPool * pool); +extern void memPoolNonZero(MemPool * p); extern void *memPoolAlloc(MemPool * pool); extern void memPoolFree(MemPool * pool, void *obj); extern int memPoolWasUsed(const MemPool * pool); Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid/squid/src/structs.h,v retrieving revision 1.524 retrieving revision 1.525 diff -u -r1.524 -r1.525 --- squid/src/structs.h 18 Sep 2007 14:43:32 -0000 1.524 +++ squid/src/structs.h 21 Sep 2007 09:35:42 -0000 1.525 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.524 2007/09/18 14:43:32 adrian Exp $ + * $Id: structs.h,v 1.525 2007/09/21 09:35:42 adrian Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -626,6 +626,7 @@ time_t period; } Netdb; struct { + int zero_buffers; int log_udp; int res_defnames; int anonymizer; @@ -2202,6 +2203,9 @@ #if DEBUG_MEMPOOL size_t real_obj_size; /* with alignment */ #endif + struct { + int dozero:1; + } flags; Stack pstack; /* stack for free pointers */ MemPoolMeter meter; #if DEBUG_MEMPOOL