From: adrian <> Date: Wed, 20 Sep 2006 06:59:26 +0000 (+0000) Subject: Bypass the expensive check to the allocator getStats() when obtaining inuse data X-Git-Tag: SQUID_3_0_PRE5~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f9e06f3e0e028258a446df3b4f1f7ef2422c302;p=thirdparty%2Fsquid.git Bypass the expensive check to the allocator getStats() when obtaining inuse data A lot of busy code calls getStats() to get the inuse values when calculating queue length (diskthreads) and store memory use for object memory expiry. This was destroying performance. The changes implement a "shortcut" to obtain the inuse values for both the malloc and mempool allocator. getStats() is still expensive for mempools (as it does GC before updating all the statistics to get accurate information) but code has been modified to not use getStats() where all it wanted was inuse info. --- diff --git a/include/MemPool.h b/include/MemPool.h index 74dfd595be..c2e97d372f 100644 --- a/include/MemPool.h +++ b/include/MemPool.h @@ -109,6 +109,7 @@ public: virtual void free(void *) = 0; virtual char const *objectType() const; virtual size_t objectSize() const = 0; + virtual int getInUseCount() = 0; int inUseCount(); virtual void setChunkSize(size_t chunksize) {} private: @@ -179,6 +180,7 @@ class MemImplementingAllocator : public MemAllocator /* Hint to the allocator - may be ignored */ virtual void setChunkSize(size_t chunksize) {} virtual size_t objectSize() const; + virtual int getInUseCount() = 0; protected: virtual void *allocate() = 0; virtual void deallocate(void *) = 0; @@ -204,6 +206,7 @@ class MemPool : public MemImplementingAllocator void createChunk(); void *get(); void push(void *obj); + virtual int getInUseCount(); protected: virtual void *allocate(); virtual void deallocate(void *); @@ -230,9 +233,12 @@ class MemMalloc : public MemImplementingAllocator virtual bool idleTrigger(int shift) const; virtual void clean(time_t maxage); virtual int getStats(MemPoolStats * stats); + virtual int getInUseCount(); protected: virtual void *allocate(); virtual void deallocate(void *); + private: + int inuse; }; class MemChunk diff --git a/lib/MemPool.cc b/lib/MemPool.cc index 5de67f74f5..26f40ae17c 100644 --- a/lib/MemPool.cc +++ b/lib/MemPool.cc @@ -1,6 +1,6 @@ /* - * $Id: MemPool.cc,v 1.5 2006/09/03 04:11:59 hno Exp $ + * $Id: MemPool.cc,v 1.6 2006/09/20 00:59:26 adrian Exp $ * * DEBUG: section 63 Low Level Memory Pool Management * AUTHOR: Alex Rousskov, Andres Kroonmaa, Robert Collins @@ -456,9 +456,7 @@ MemAllocator::objectType() const int MemAllocator::inUseCount() { - MemPoolStats stats; - getStats(&stats); - return stats.items_inuse; + return getInUseCount(); } void @@ -529,12 +527,14 @@ MemPools::flushMeters() void * MemMalloc::allocate() { + inuse++; return xcalloc(1, obj_size); } void MemMalloc::deallocate(void *obj) { + inuse--; xfree(obj); } @@ -556,6 +556,12 @@ MemImplementingAllocator::free(void *obj) ++free_calls; } +int +MemPool::getInUseCount() +{ + return inuse; +} + void * MemPool::allocate() { @@ -777,6 +783,12 @@ MemMalloc::getStats(MemPoolStats * stats) return getMeter().inuse.level; } +int +MemMalloc::getInUseCount() +{ + return inuse; +} + /* * Totals statistics is returned */ @@ -824,7 +836,7 @@ MemAllocator::MemAllocator(char const *aLabel) : label(aLabel) { } -MemMalloc::MemMalloc(char const *label, size_t aSize) : MemImplementingAllocator(label, aSize) {} +MemMalloc::MemMalloc(char const *label, size_t aSize) : MemImplementingAllocator(label, aSize) { inuse = 0; } bool MemMalloc::idleTrigger(int shift) const diff --git a/src/MemObject.cc b/src/MemObject.cc index 1dadcc3108..04fe0418f4 100644 --- a/src/MemObject.cc +++ b/src/MemObject.cc @@ -1,6 +1,6 @@ /* - * $Id: MemObject.cc,v 1.23 2006/08/21 00:50:41 robertc Exp $ + * $Id: MemObject.cc,v 1.24 2006/09/20 00:59:26 adrian Exp $ * * DEBUG: section 19 Store Memory Primitives * AUTHOR: Robert Collins @@ -68,11 +68,7 @@ RemovalPolicy * mem_policy = NULL; size_t MemObject::inUseCount() { - MemPoolStats stats; - - Pool().getStats (&stats); - - return stats.items_inuse; + return Pool().inUseCount(); } MemObject::MemObject(char const *aUrl, char const *aLog_url) diff --git a/src/mem_node.cc b/src/mem_node.cc index d0dc18d02d..834aa5b5c1 100644 --- a/src/mem_node.cc +++ b/src/mem_node.cc @@ -1,6 +1,6 @@ /* - * $Id: mem_node.cc,v 1.8 2005/11/02 22:19:22 serassio Exp $ + * $Id: mem_node.cc,v 1.9 2006/09/20 00:59:27 adrian Exp $ * * DEBUG: section 19 Store Memory Primitives * AUTHOR: Robert Collins @@ -77,11 +77,7 @@ mem_node::~mem_node() size_t mem_node::InUseCount() { - MemPoolStats stats; - - Pool().getStats (&stats); - - return stats.items_inuse; + return Pool().inUseCount(); } size_t diff --git a/src/store.cc b/src/store.cc index 473b543556..e6e036c110 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.600 2006/09/03 21:05:20 hno Exp $ + * $Id: store.cc,v 1.601 2006/09/20 00:59:27 adrian Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -210,12 +210,7 @@ StoreEntry::inUseCount() { if (!pool) return 0; - - MemPoolStats stats; - - pool->getStats (&stats); - - return stats.items_inuse; + return pool->getInUseCount(); } const char *