From: Otto Moerbeek Date: Sun, 6 Feb 2022 09:49:41 +0000 (+0100) Subject: Only create PC for threads that need it X-Git-Tag: rec-4.7.0-beta1~23^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5abc5e10c037764d2da5f3b8977a73bd58644e14;p=thirdparty%2Fpdns.git Only create PC for threads that need it --- diff --git a/pdns/lwres.cc b/pdns/lwres.cc index c100c05037..1f3124de1d 100644 --- a/pdns/lwres.cc +++ b/pdns/lwres.cc @@ -49,6 +49,7 @@ #include "ednssubnet.hh" #include "query-local-address.hh" #include "tcpiohandler.hh" +#include "ednsoptions.hh" #include "rec-protozero.hh" #include "uuid-utils.hh" diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index d5bb49d280..89f03882db 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1470,7 +1470,7 @@ void startDoResolve(void* p) #endif } - if (!SyncRes::s_nopacketcache && !variableAnswer && !sr.wasVariable()) { + if (t_packetCache && !variableAnswer && !sr.wasVariable()) { const auto& hdr = pw.getHeader(); if ((hdr->rcode != RCode::NoError && hdr->rcode != RCode::NXDomain) || (hdr->ancount == 0 && hdr->nscount == 0)) { minTTL = min(minTTL, SyncRes::s_packetcacheservfailttl); @@ -1724,15 +1724,18 @@ bool checkForCacheHit(bool qnameParsed, unsigned int tag, const string& data, string& response, uint32_t& qhash, RecursorPacketCache::OptPBData& pbData, bool tcp, const ComboAddress& source) { + if (!t_packetCache) { + return false; + } bool cacheHit = false; uint32_t age; vState valState; if (qnameParsed) { - cacheHit = !SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(tag, data, qname, qtype, qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp); + cacheHit = t_packetCache->getResponsePacket(tag, data, qname, qtype, qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp); } else { - cacheHit = !SyncRes::s_nopacketcache && t_packetCache->getResponsePacket(tag, data, qname, &qtype, &qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp); + cacheHit = t_packetCache->getResponsePacket(tag, data, qname, &qtype, &qclass, now.tv_sec, &response, &age, &valState, &qhash, &pbData, tcp); } if (cacheHit) { diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 9ea9589dbc..c24f9eed4b 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -354,7 +354,7 @@ static uint64_t dumpAggressiveNSECCache(int fd) static uint64_t* pleaseDump(int fd) { - return new uint64_t(t_packetCache->doDump(fd)); + return new uint64_t(t_packetCache ? t_packetCache->doDump(fd) : 0); } static uint64_t* pleaseDumpEDNSMap(int fd) @@ -855,6 +855,9 @@ static string setMaxPacketCacheEntries(T begin, T end) { if (end - begin != 1) return "Need to supply new packet cache size\n"; + if (::arg().mustDo("disable-packetcache")) { + return "Packet cache is disabled\n"; + } try { g_maxPacketCacheEntries = pdns::checked_stoi(*begin); return "New max packetcache entries: " + std::to_string(g_maxPacketCacheEntries) + "\n"; diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index be4ded3286..131b9021e1 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -1298,9 +1298,6 @@ static int serviceMain(int argc, char* argv[]) SyncRes::s_minimumTTL = ::arg().asNum("minimum-ttl-override"); SyncRes::s_minimumECSTTL = ::arg().asNum("ecs-minimum-ttl-override"); - - SyncRes::s_nopacketcache = ::arg().mustDo("disable-packetcache"); - SyncRes::s_maxnegttl = ::arg().asNum("max-negative-ttl"); SyncRes::s_maxbogusttl = ::arg().asNum("max-cache-bogus-ttl"); SyncRes::s_maxcachettl = max(::arg().asNum("max-cache-ttl"), 15); @@ -1870,11 +1867,13 @@ static void houseKeeping(void*) struct timeval now; Utility::gettimeofday(&now); - // Below are the tasks that run for every recursorThread, including handler and taskThread - static thread_local PeriodicTask packetCacheTask{"packetCacheTask", 5}; - packetCacheTask.runIfDue(now, []() { - t_packetCache->doPruneTo(g_maxPacketCacheEntries / (RecThreadInfo::numDistributors() + RecThreadInfo::numWorkers())); - }); + if (t_packetCache) { + // Below are the tasks that run for every recursorThread, including handler and taskThread + static thread_local PeriodicTask packetCacheTask{"packetCacheTask", 5}; + packetCacheTask.runIfDue(now, []() { + t_packetCache->doPruneTo(g_maxPacketCacheEntries / (RecThreadInfo::numDistributors() + RecThreadInfo::numWorkers())); + }); + } // This is a full scan static thread_local PeriodicTask pruneNSpeedTask{"pruneNSSpeedTask", 100}; @@ -2060,7 +2059,9 @@ static void recursorThread() } } - t_packetCache = std::make_unique(); + if (!::arg().mustDo("disable-packetcache") && (threadInfo.isDistributor() || threadInfo.isWorker())) { + t_packetCache = std::make_unique(); + } #ifdef NOD_ENABLED if (threadInfo.isWorker()) @@ -2704,7 +2705,7 @@ string doTraceRegex(vector::const_iterator begin, vector::const_ static uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree, uint16_t qtype) { - return new uint64_t(t_packetCache->doWipePacketCache(canon, qtype, subtree)); + return new uint64_t(t_packetCache ? 0 : t_packetCache->doWipePacketCache(canon, qtype, subtree)); } struct WipeCacheResult wipeCaches(const DNSName& canon, bool subtree, uint16_t qtype) diff --git a/pdns/recursordist/rec-main.hh b/pdns/recursordist/rec-main.hh index 98eb57023e..8a29e825d7 100644 --- a/pdns/recursordist/rec-main.hh +++ b/pdns/recursordist/rec-main.hh @@ -36,6 +36,7 @@ #include "rec-snmp.hh" #include "rec_channel.hh" #include "threadname.hh" +#include "recpacketcache.hh" #ifdef NOD_ENABLED #include "nod.hh" @@ -181,6 +182,7 @@ enum class PaddingMode typedef MTasker, PacketBuffer, PacketIDCompare> MT_t; extern thread_local std::unique_ptr MT; // the big MTasker +extern thread_local std::unique_ptr t_packetCache; extern bool g_logCommonErrors; extern size_t g_proxyProtocolMaximumSize; diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 3f80f1caea..dec95f4bf4 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -204,7 +204,6 @@ bool SyncRes::s_ecsipv6nevercache; bool SyncRes::s_doIPv4; bool SyncRes::s_doIPv6; -bool SyncRes::s_nopacketcache; bool SyncRes::s_rootNXTrust; bool SyncRes::s_noEDNS; bool SyncRes::s_qnameminimization; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index c9e3abc0f1..95f1131732 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -39,7 +39,6 @@ #include "circular_buffer.hh" #include "sstuff.hh" #include "recursor_cache.hh" -#include "recpacketcache.hh" #include #include "mtasker.hh" #include "iputils.hh" @@ -712,7 +711,6 @@ public: static bool s_noEDNSPing; static bool s_noEDNS; static bool s_rootNXTrust; - static bool s_nopacketcache; static bool s_qnameminimization; static HardenNXD s_hardenNXD; static unsigned int s_refresh_ttlperc; @@ -961,7 +959,6 @@ struct PacketIDBirthdayCompare } }; extern std::unique_ptr g_recCache; -extern thread_local std::unique_ptr t_packetCache; struct RecursorStats {