From: Remi Gacogne Date: Wed, 3 Mar 2021 13:49:03 +0000 (+0100) Subject: dnsdist: Remove now unused shard index, we scan every shard anyway X-Git-Tag: dnsdist-1.6.0-alpha2~1^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1942c541dc6987f47f4b19bcaa225591636928f6;p=thirdparty%2Fpdns.git dnsdist: Remove now unused shard index, we scan every shard anyway --- diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index 5d2d3a07ba..753d241001 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -302,14 +302,14 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now) const size_t maxPerShard = upTo / d_shardCount; size_t removed = 0; - size_t scannedMaps = 0; + uint32_t shardIndex = 0; do { - uint32_t shardIndex = (d_expungeIndex++ % d_shardCount); - scannedMaps++; + auto& shard = d_shards.at(shardIndex); + ++shardIndex; - WriteLock w(&d_shards.at(shardIndex).d_lock); - auto& map = d_shards.at(shardIndex).d_map; + WriteLock w(&shard.d_lock); + auto& map = shard.d_map; if (map.size() <= maxPerShard) { continue; } @@ -322,14 +322,14 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now) if (value.validity <= now) { it = map.erase(it); --toRemove; - --d_shards[shardIndex].d_entriesCount; + --shard.d_entriesCount; ++removed; } else { ++it; } } } - while (scannedMaps < d_shardCount); + while (shardIndex < d_shardCount); return removed; } diff --git a/pdns/dnsdist-cache.hh b/pdns/dnsdist-cache.hh index bfbf17cfc7..25b1a0dd42 100644 --- a/pdns/dnsdist-cache.hh +++ b/pdns/dnsdist-cache.hh @@ -136,7 +136,6 @@ private: pdns::stat_t d_ttlTooShorts{0}; size_t d_maxEntries; - uint32_t d_expungeIndex{0}; uint32_t d_shardCount; uint32_t d_maxTTL; uint32_t d_tempFailureTTL;