From: Otto Moerbeek Date: Wed, 11 Dec 2019 13:01:59 +0000 (+0100) Subject: Better way for pruning if cleaning dead entries wasn't enough X-Git-Tag: dnsdist-1.5.0-alpha1~21^2^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=79a098932a92d3541f00018ba9ca28a06ce3f46d;p=thirdparty%2Fpdns.git Better way for pruning if cleaning dead entries wasn't enough --- diff --git a/pdns/cachecleaner.hh b/pdns/cachecleaner.hh index a29533c20e..c66e430bb4 100644 --- a/pdns/cachecleaner.hh +++ b/pdns/cachecleaner.hh @@ -204,20 +204,23 @@ template uint64_t pruneMutexCollectionsVect toTrim -= totErased; - // XXXX kinda desperate method while (toTrim > 0) { + size_t pershard = toTrim / maps_size + 1; for (auto& mc : maps) { const std::lock_guard lock(mc.mutex); mc.d_cachecachevalid = false; auto& sidx = boost::multi_index::get(mc.d_map); - auto i = sidx.begin(); - container.preRemoval(*i); - i = sidx.erase(i); - mc.d_entriesCount--; - totErased++; - toTrim--; - if (toTrim == 0) - break; + size_t removed = 0; + for (auto i = sidx.begin(); i != sidx.end() && removed < pershard; removed++) { + container.preRemoval(*i); + i = sidx.erase(i); + mc.d_entriesCount--; + totErased++; + toTrim--; + if (toTrim == 0) { + break; + } + } } } return totErased; diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index 3464b7f756..4ceb1a1f7e 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -33,7 +33,6 @@ MemRecursorCache::~MemRecursorCache() size_t MemRecursorCache::size() { - // XXX! size_t count = 0; for (auto& map : d_maps) { count += map.d_entriesCount;