--------------------- PatchSet 1974 Date: 2001/04/18 22:08:55 Author: akroonmaa Branch: akroonmaa-head Tag: (none) Log: performance optimisation: instead of updating all the memPool Meters every single call, update them only every few thousand calls and when needed. Members: include/MemPool.h:1.1.8.3->1.1.8.4 include/util.h:1.7.24.1->1.7.24.2 lib/MemPool.c:1.1.8.3->1.1.8.4 src/MemPoolStats.c:1.1.8.5->1.1.8.6 Index: squid/include/MemPool.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/Attic/MemPool.h,v retrieving revision 1.1.8.3 retrieving revision 1.1.8.4 diff -u -r1.1.8.3 -r1.1.8.4 --- squid/include/MemPool.h 18 Apr 2001 19:06:10 -0000 1.1.8.3 +++ squid/include/MemPool.h 18 Apr 2001 22:08:55 -0000 1.1.8.4 @@ -53,6 +53,10 @@ int capacity; int memPID; int chunkCount; + size_t alloc_calls; + size_t free_calls; + size_t inuse; + size_t idle; MemChunk *Chunks; MemChunk *nextbest; MemChunk *lastchunk; @@ -105,6 +109,7 @@ extern void memPoolClean(MemPool * pool, time_t maxage); extern void memPoolCleanIdlePools(void *unused); extern void memPoolShrink(MemPool * pool, ssize_t new_limit); +extern void memPoolFlushMeters(MemPool * pool); /* MemMeter */ Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.7.24.1 retrieving revision 1.7.24.2 diff -u -r1.7.24.1 -r1.7.24.2 --- squid/include/util.h 9 Apr 2001 15:17:29 -0000 1.7.24.1 +++ squid/include/util.h 18 Apr 2001 22:08:55 -0000 1.7.24.2 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.7.24.1 2001/04/09 15:17:29 akroonmaa Exp $ + * $Id: util.h,v 1.7.24.2 2001/04/18 22:08:55 akroonmaa Exp $ * * AUTHOR: Harvest Derived * @@ -136,6 +136,7 @@ /* gb_type operations */ #define gb_flush_limit (0x3FFFFFFF) #define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; } +#define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; } extern double gb_to_double(const gb_t *); extern const char *gb_to_str(const gb_t *); extern void gb_flush(gb_t *); /* internal, do not use this */ Index: squid/lib/MemPool.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/Attic/MemPool.c,v retrieving revision 1.1.8.3 retrieving revision 1.1.8.4 diff -u -r1.1.8.3 -r1.1.8.4 --- squid/lib/MemPool.c 18 Apr 2001 19:06:10 -0000 1.1.8.3 +++ squid/lib/MemPool.c 18 Apr 2001 22:08:55 -0000 1.1.8.4 @@ -174,6 +174,7 @@ memMeterAdd(TheMeter.alloc, pool->capacity * pool->obj_size); memMeterAdd(pool->meter.idle, pool->capacity); memMeterAdd(TheMeter.idle, pool->capacity * pool->obj_size); + pool->idle += pool->capacity; pool->chunkCount++; chunk->lastref = squid_curtime; lastPool = pool; @@ -189,6 +190,7 @@ memMeterDel(TheMeter.alloc, pool->capacity * pool->obj_size); memMeterDel(pool->meter.idle, pool->capacity); memMeterDel(TheMeter.idle, pool->capacity * pool->obj_size); + pool->idle -= pool->capacity; pool->chunkCount--; if (pool->lastchunk == chunk) pool->lastchunk = chunk->prev; @@ -364,6 +366,45 @@ assert(pool); } +#define FLUSH_LIMIT 10000 /* Flush memPool counters to memMeters after flush limit calls */ + +void +memPoolFlushMeters(MemPool * pool) +{ + size_t calls; + size_t bytes; + + calls = pool->alloc_calls; + if (calls) { + bytes = pool->obj_size * pool->alloc_calls; + + memMeterAdd(pool->meter.inuse, calls); + gb_incc(&pool->meter.saved, calls); + gb_incc(&pool->meter.total, calls); + mem_pool_alloc_calls += calls; + + memMeterAdd(TheMeter.inuse, bytes); + gb_inc(&TheMeter.saved, bytes); + gb_inc(&TheMeter.total, bytes); + gb_inc(&mem_traffic_volume, bytes); + + memMeterDel(TheMeter.idle, bytes); + memMeterDel(pool->meter.idle, calls); + pool->alloc_calls = 0; + } + calls = pool->free_calls; + if (calls) { + bytes = pool->obj_size * pool->free_calls; + memMeterDel(pool->meter.inuse, calls); + memMeterAdd(pool->meter.idle, calls); + mem_pool_free_calls += calls; + + memMeterDel(TheMeter.inuse, bytes); + memMeterAdd(TheMeter.idle, bytes); + pool->free_calls = 0; + } +} + void * memPoolAlloc(MemPool * pool) { @@ -371,22 +412,15 @@ PROF(PR_start, "memPoolAlloc"); assert(pool); #if !DISABLE_POOLS - memMeterInc(pool->meter.inuse); - gb_inc(&pool->meter.total, 1); - gb_inc(&TheMeter.total, pool->obj_size); - memMeterAdd(TheMeter.inuse, pool->obj_size); - gb_inc(&mem_traffic_volume, pool->obj_size); - mem_pool_alloc_calls++; p = memPoolGet(pool); - assert(pool->meter.idle.level); -#if XMALLOC_DEBUG2 - check_malloc(p, pool->obj_size); -#endif - memMeterDec(pool->meter.idle); - memMeterDel(TheMeter.idle, pool->obj_size); - gb_inc(&pool->meter.saved, 1); - gb_inc(&TheMeter.saved, pool->obj_size); - assert(pool->meter.inuse.level <= pool->meter.alloc.level); + assert(pool->idle); + pool->idle--; + pool->inuse++; + + if (++pool->alloc_calls == FLUSH_LIMIT) + memPoolFlushMeters(pool); + + assert(pool->inuse <= pool->meter.alloc.level); #else p = xcalloc(1, pool->obj_size); #endif @@ -400,17 +434,15 @@ PROF(PR_start, "memPoolFree"); assert(pool && obj); #if !DISABLE_POOLS - memMeterDec(pool->meter.inuse); - memMeterDel(TheMeter.inuse, pool->obj_size); - memMeterInc(pool->meter.idle); - memMeterAdd(TheMeter.idle, pool->obj_size); - mem_pool_free_calls++; -#if XMALLOC_DEBUG2 - if (obj != NULL) - check_free(obj); -#endif + memPoolPush(pool, obj); - assert(pool->meter.idle.level <= pool->meter.alloc.level); + pool->idle++; + pool->inuse--; + + if (++pool->free_calls == FLUSH_LIMIT) + memPoolFlushMeters(pool); + + assert(pool->idle <= pool->meter.alloc.level); #else xfree(obj); #endif Index: squid/src/MemPoolStats.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/MemPoolStats.c,v retrieving revision 1.1.8.5 retrieving revision 1.1.8.6 diff -u -r1.1.8.5 -r1.1.8.6 --- squid/src/MemPoolStats.c 18 Apr 2001 19:06:11 -0000 1.1.8.5 +++ squid/src/MemPoolStats.c 18 Apr 2001 22:08:55 -0000 1.1.8.6 @@ -287,6 +287,7 @@ xm_time = current_dtime; for (i = 0; i < Pools.count ; i++) { const MemPool *pool = Pools.items[i]; + memPoolFlushMeters(pool); if (memPoolWasUsed(pool)) { memPoolReport(pool, e); free_count += freecount;