From: hno <> Date: Thu, 27 Dec 2007 08:58:19 +0000 (+0000) Subject: Bug #2114: cache memory accounting not working well X-Git-Tag: BASIC_TPROXY4~224 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2415e2023d5b5e99c65cfe4794819489f9f81511;p=thirdparty%2Fsquid.git Bug #2114: cache memory accounting not working well 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.. --- diff --git a/src/mem_node.cc b/src/mem_node.cc index dc44b48978..ce75d99457 100644 --- a/src/mem_node.cc +++ b/src/mem_node.cc @@ -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 { diff --git a/src/mem_node.h b/src/mem_node.h index 15a20c98e9..3f3faf2fb4 100644 --- a/src/mem_node.h +++ b/src/mem_node.h @@ -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); diff --git a/src/snmp_agent.cc b/src/snmp_agent.cc index 90ba56d010..f0789b0220 100644 --- a/src/snmp_agent.cc +++ b/src/snmp_agent.cc @@ -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; diff --git a/src/stat.cc b/src/stat.cc index 6eb81ec5cf..a7eb6afed7 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -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), diff --git a/src/stmem.cc b/src/stmem.cc index e1837d97e1..d94a16cddc 100644 --- a/src/stmem.cc +++ b/src/stmem.cc @@ -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; }