]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bypass the expensive check to the allocator getStats() when obtaining inuse data
authoradrian <>
Wed, 20 Sep 2006 06:59:26 +0000 (06:59 +0000)
committeradrian <>
Wed, 20 Sep 2006 06:59:26 +0000 (06:59 +0000)
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.

include/MemPool.h
lib/MemPool.cc
src/MemObject.cc
src/mem_node.cc
src/store.cc

index 74dfd595be9409b2f655a521214d69c211496189..c2e97d372f3ff812cd0cb8a22e2fe8909a226a40 100644 (file)
@@ -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
index 5de67f74f5e84ea049adca5f97eb821e40503d98..26f40ae17cac469bf4abecd9deb9629f3c3b7c77 100644 (file)
@@ -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
index 1dadcc31081fed77a065c718af59b039e1c90552..04fe0418f4ce818bed96c06771650050ffac8928 100644 (file)
@@ -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)
index d0dc18d02d07afdaaba077aeb0808b912bf1516f..834aa5b5c1508eb6424b6916c481b29d39bc5c64 100644 (file)
@@ -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
index 473b5435561dab31b08d511e9f71b24c23ec350d..e6e036c11025da0bc95c8b02852d8c9ba0751bbe 100644 (file)
@@ -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 *