]> granicus.if.org Git - pdns/commitdiff
remove unnecessary locking in packetcache
authorKees Monshouwer <mind04@monshouwer.org>
Mon, 26 Sep 2016 18:30:20 +0000 (20:30 +0200)
committermind04 <mind04@monshouwer.org>
Sat, 1 Oct 2016 16:37:20 +0000 (18:37 +0200)
pdns/packetcache.cc
pdns/packetcache.hh

index 9e49cb7a27b406ceb3d049329e61568efb2a7cbc..9ec03e02868db16c61965187e0cd2b360ab45d05 100644 (file)
@@ -376,25 +376,10 @@ map<char,int> PacketCache::getCounts()
   return ret;
 }
 
-int PacketCache::size()
-{
-  uint64_t ret=0;
-  for(auto& mc : d_maps) {
-    ReadLock l(&mc.d_mut);
-    ret+=mc.d_map.size();
-  }
-  return ret;
-}
 
 /** readlock for figuring out which iterators to delete, upgrade to writelock when actually cleaning */
 void PacketCache::cleanup()
 {
-  d_statnumentries->store(0);
-  for(auto& mc : d_maps) {
-    ReadLock l(&mc.d_mut);
-
-    *d_statnumentries+=mc.d_map.size();
-  }
   unsigned int maxCached=::arg().asNum("max-cache-entries");
   unsigned int toTrim=0;
   
@@ -415,7 +400,7 @@ void PacketCache::cleanup()
   //  cerr<<"cacheSize: "<<cacheSize<<", lookAt: "<<lookAt<<", toTrim: "<<toTrim<<endl;
   time_t now=time(0);
   DLOG(L<<"Starting cache clean"<<endl);
-  //unsigned int totErased=0;
+  unsigned int totErased=0;
   for(auto& mc : d_maps) {
     WriteLock wl(&mc.d_mut);
     typedef cmap_t::nth_index<1>::type sequence_t;
@@ -436,16 +421,12 @@ void PacketCache::cleanup()
       if(lookedAt > lookAt / d_maps.size())
        break;
     }
-    //totErased += erased;
+    totErased += erased;
   }
   //  if(totErased)
   //  cerr<<"erased: "<<totErased<<endl;
   
-  d_statnumentries->store(0);
-  for(auto& mc : d_maps) {
-    ReadLock l(&mc.d_mut);
-    *d_statnumentries+=mc.d_map.size();
-  }
+  *d_statnumentries-=totErased;
   
   DLOG(L<<"Done with cache clean"<<endl);
 }
index fdfc48a710a4f9b961099823d793008aa35e72af..cd8ea9ad6bef4d0502d9d0a65215007760e520a4 100644 (file)
@@ -67,7 +67,7 @@ public:
   bool getEntry(const DNSName &qname, const QType& qtype, CacheEntryType cet, vector<DNSResourceRecord>& entry, int zoneID=-1);
   
 
-  int size(); //!< number of entries in the cache
+  int size() { return *d_statnumentries; } //!< number of entries in the cache
   void cleanupIfNeeded()
   {
     if(!(++d_ops % 300000)) {