Permalink
Browse files

remove unnecessary locking in packetcache

  • Loading branch information...
1 parent c1d283d commit 5656e1271b2355919261ed5b479f7ea0d3e1d75e @mind04 mind04 committed with mind04 Sep 26, 2016
Showing with 4 additions and 23 deletions.
  1. +3 −22 pdns/packetcache.cc
  2. +1 −1 pdns/packetcache.hh
View
@@ -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);
}
View
@@ -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)) {

0 comments on commit 5656e12

Please sign in to comment.