From eb7fae646a6080fe1e1a913b65f5c01d619d373f Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Fri, 12 Jun 2020 12:24:26 +0200 Subject: [PATCH] Fix three shared cache issues: - Only prime share cache once on startup - Cache pruning could go into an infinite loop if not enough expired entries could be pruned. - Handler thread isn't run very often, but now the record cache pruning is done by it, so increase frequency of the housekeeping call for the handler thread. --- pdns/cachecleaner.hh | 5 +++-- pdns/pdns_recursor.cc | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pdns/cachecleaner.hh b/pdns/cachecleaner.hh index 18e5ea1474..7d42274bff 100644 --- a/pdns/cachecleaner.hh +++ b/pdns/cachecleaner.hh @@ -190,7 +190,7 @@ template uint64_t pruneMutexCollectionsVect toTrim -= totErased; - while (toTrim > 0) { + while (true) { size_t pershard = toTrim / maps_size + 1; for (auto& mc : maps) { const typename C::lock l(mc); @@ -204,11 +204,12 @@ template uint64_t pruneMutexCollectionsVect totErased++; toTrim--; if (toTrim == 0) { - break; + return totErased; } } } } + // Not reached return totErased; } diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 8e51e26350..f99dd5af58 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -4662,11 +4662,13 @@ try t_allowFrom = g_initialAllowFrom; t_udpclientsocks = std::unique_ptr(new UDPClientSocks()); t_tcpClientCounts = std::unique_ptr(new tcpClientCounts_t()); - primeHints(); + if (threadInfo.isHandler) { + primeHints(); + g_log<(new RecursorPacketCache()); - g_log<schedule(&g_now)); // MTasker letting the mthreads do their thing - if(!(counter%500)) { + // Use primes, it avoid not being scheduled in cases where the counter has a regular pattern. + // We want to call handler thread often, it gets scheduled about 2 times per second + if ((threadInfo.isHandler && counter % 11 == 0) || counter % 499 == 0) { MT->makeThread(houseKeeping, 0); } -- 2.47.2