]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug #2114: cache memory accounting not working well
authorhno <>
Thu, 27 Dec 2007 08:58:19 +0000 (08:58 +0000)
committerhno <>
Thu, 27 Dec 2007 08:58:19 +0000 (08:58 +0000)
Use the page allocator statistics to report cache_mem usage

This patch removes the weak attempt in keeping an byte-exact cache_mem usage
counter, instead using the actual allocated size (but excluding overhead).

This is the same accounting method as used in Squid-2 btw..

src/mem_node.cc
src/mem_node.h
src/snmp_agent.cc
src/stat.cc
src/stmem.cc

index dc44b48978343528b2ba8c996219790fd1476216..ce75d99457959ac3eb32ec9563ef805eb9de6e78 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mem_node.cc,v 1.10 2007/08/13 17:20:51 hno Exp $
+ * $Id: mem_node.cc,v 1.11 2007/12/27 01:58:19 hno Exp $
  *
  * DEBUG: section 19    Store Memory Primitives
  * AUTHOR: Robert Collins
@@ -38,7 +38,6 @@
 
 static int makeMemNodeDataOffset();
 
-unsigned long mem_node::store_mem_size;
 static int _mem_node_data_offset = makeMemNodeDataOffset();
 
 /*
@@ -70,9 +69,7 @@ mem_node::mem_node(int64_t offset):nodeBuffer(0,offset,data)
 {}
 
 mem_node::~mem_node()
-{
-    store_mem_size -= nodeBuffer.length;
-}
+{}
 
 size_t
 mem_node::InUseCount()
@@ -80,6 +77,12 @@ mem_node::InUseCount()
     return Pool().inUseCount();
 }
 
+size_t
+mem_node::StoreMemSize()
+{
+    return InUseCount() * SM_PAGE_SIZE;
+}
+
 int64_t
 mem_node::start() const
 {
index 15a20c98e90461a288199473c2936154840646a9..3f3faf2fb4c6e3670db989a23d06408e589be7fe 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mem_node.h,v 1.10 2007/08/13 17:20:51 hno Exp $
+ * $Id: mem_node.h,v 1.11 2007/12/27 01:58:19 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -42,7 +42,7 @@ class mem_node
 
 public:
     static size_t InUseCount();
-    static unsigned long store_mem_size;       /* 0 */
+    static size_t StoreMemSize();
 
     MEMPROXY_CLASS(mem_node);
     mem_node(int64_t);
index 90ba56d010bdd0920c20d2579fb39a93ac49aa90..f0789b022039151ebf784e0f885d079c12843e0e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: snmp_agent.cc,v 1.97 2007/12/14 23:11:48 amosjeffries Exp $
+ * $Id: snmp_agent.cc,v 1.98 2007/12/27 01:58:19 hno Exp $
  *
  * DEBUG: section 49    SNMP Interface
  * AUTHOR: Kostas Anagnostakis
@@ -60,7 +60,7 @@ snmp_sysFn(variable_list * Var, snint * ErrP)
 
     case SYSVMSIZ:
         Answer = snmp_var_new_integer(Var->name, Var->name_length,
-                                      mem_node::store_mem_size >> 10,
+                                      mem_node::StoreMemSize() >> 10,
                                       ASN_INTEGER);
         break;
 
index 6eb81ec5cf431a84aaf188fac14cb07f22a671a0..a7eb6afed761c65c84a27ec87803764b79f4e442 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: stat.cc,v 1.411 2007/12/14 23:11:48 amosjeffries Exp $
+ * $Id: stat.cc,v 1.412 2007/12/27 01:58:19 hno Exp $
  *
  * DEBUG: section 18    Cache Manager Statistics
  * AUTHOR: Harvest Derived
@@ -547,7 +547,7 @@ info_get(StoreEntry * sentry)
 
 
     storeAppendPrintf(sentry, "\tStorage Mem size:\t%d KB\n",
-                      (int) (mem_node::store_mem_size >> 10));
+                      mem_node::StoreMemSize() >> 10);
 
     storeAppendPrintf(sentry, "\tStorage Mem capacity:\t%4.1f%% used, %4.1f%% free\n",
                       dpercent(mem_node::InUseCount(), store_pages_max),
index e1837d97e1ca926d6f511cd269b7aac7f4fd3b6e..d94a16cddc94fdab44d4b8d495f1effcde760844 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: stmem.cc,v 1.92 2007/08/13 18:25:14 hno Exp $
+ * $Id: stmem.cc,v 1.93 2007/12/27 01:58:19 hno Exp $
  *
  * DEBUG: section 19    Store Memory Primitives
  * AUTHOR: Harvest Derived
@@ -150,8 +150,6 @@ mem_hdr::writeAvailable(mem_node *aNode, int64_t location, size_t amount, char c
     /* Adjust the ptr and len according to what was deposited in the page */
     aNode->nodeBuffer.length += copyLen;
 
-    mem_node::store_mem_size += copyLen;
-
     return copyLen;
 }