]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alex Rousskov <rousskov@measurement-factory.com>
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Thu, 27 Jan 2011 09:29:04 +0000 (11:29 +0200)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Thu, 27 Jan 2011 09:29:04 +0000 (11:29 +0200)
Fix IP/FQDN cache accounting to avoid idle caches on busy servers.

When maintaining the IP/FQDN cache size, use the number of entries in the cache
rather than the number of allocated and not freed MEM_IPCACHE_ENTRY and
MEM_FQDNCACHE_ENTRY objects. These objects are used outside the cache
for DNS queries. If queries leak (or perhaps when there are just a lot of them),
the memory-pool-based count overestimates the cache size, sometimes to
such a degree that the cache remains nearly empty despite lots of misses.

Use memory-pool-based counter to estimate cache size also violates IP/FQDN cache
encapsulation boundaries because it effectively prevents others from using
the same memory pool.

src/fqdncache.cc
src/ipcache.cc

index d3cc6108c85f0d6c734cd14dcf10f056187b0e21..ef75be1622bd839f8c5e86f0939075b00a8cac28 100644 (file)
@@ -152,6 +152,9 @@ static long fqdncache_low = 180;
 /// \ingroup FQDNCacheInternal
 static long fqdncache_high = 200;
 
+/// \ingroup FQDNCacheInternal
+inline int fqdncacheCount() { return fqdn_table ? fqdn_table->count : 0; }
+
 int
 fqdncache_entry::age() const
 {
@@ -229,7 +232,7 @@ fqdncache_purgelru(void *notused)
     eventAdd("fqdncache_purgelru", fqdncache_purgelru, NULL, 10.0, 1);
 
     for (m = lru_list.tail; m; m = prev) {
-        if (memInUse(MEM_FQDNCACHE_ENTRY) < fqdncache_low)
+        if (fqdncacheCount() < fqdncache_low)
             break;
 
         prev = m->prev;
@@ -698,9 +701,12 @@ fqdnStats(StoreEntry * sentry)
 
     storeAppendPrintf(sentry, "FQDN Cache Statistics:\n");
 
-    storeAppendPrintf(sentry, "FQDNcache Entries: %d\n",
+    storeAppendPrintf(sentry, "FQDNcache Entries In Use: %d\n",
                       memInUse(MEM_FQDNCACHE_ENTRY));
 
+    storeAppendPrintf(sentry, "FQDNcache Entries Cached: %d\n",
+                      fqdncacheCount());
+
     storeAppendPrintf(sentry, "FQDNcache Requests: %d\n",
                       FqdncacheStats.requests);
 
@@ -882,7 +888,7 @@ snmp_netFqdnFn(variable_list * Var, snint * ErrP)
 
     case FQDN_ENT:
         Answer = snmp_var_new_integer(Var->name, Var->name_length,
-                                      memInUse(MEM_FQDNCACHE_ENTRY),
+                                      fqdncacheCount(),
                                       SMI_GAUGE32);
         break;
 
index 926b906e5c20f18011432482ea6f73e1e2d76cec..b4a1f725a65cf7784d8989ad6aff686d21ad9d4c 100644 (file)
@@ -161,6 +161,9 @@ static long ipcache_high = 200;
 extern int _dns_ttl_;
 #endif
 
+/// \ingroup IPCacheInternal
+inline int ipcacheCount() { return ip_table ? ip_table->count : 0; }
+
 int
 ipcache_entry::age() const
 {
@@ -235,7 +238,7 @@ ipcache_purgelru(void *voidnotused)
     eventAdd("ipcache_purgelru", ipcache_purgelru, NULL, 10.0, 1);
 
     for (m = lru_list.tail; m; m = prev) {
-        if (memInUse(MEM_IPCACHE_ENTRY) < ipcache_low)
+        if (ipcacheCount() < ipcache_low)
             break;
 
         prev = m->prev;
@@ -855,8 +858,10 @@ stat_ipcache_get(StoreEntry * sentry)
     dlink_node *m;
     assert(ip_table != NULL);
     storeAppendPrintf(sentry, "IP Cache Statistics:\n");
-    storeAppendPrintf(sentry, "IPcache Entries:  %d\n",
+    storeAppendPrintf(sentry, "IPcache Entries In Use:  %d\n",
                       memInUse(MEM_IPCACHE_ENTRY));
+    storeAppendPrintf(sentry, "IPcache Entries Cached:  %d\n",
+                      ipcacheCount());
     storeAppendPrintf(sentry, "IPcache Requests: %d\n",
                       IpcacheStats.requests);
     storeAppendPrintf(sentry, "IPcache Hits:            %d\n",
@@ -1231,7 +1236,7 @@ snmp_netIpFn(variable_list * Var, snint * ErrP)
 
     case IP_ENT:
         Answer = snmp_var_new_integer(Var->name, Var->name_length,
-                                      memInUse(MEM_IPCACHE_ENTRY),
+                                      ipcacheCount(),
                                       SMI_GAUGE32);
         break;