]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Only create PC for threads that need it
authorOtto Moerbeek <otto@drijf.net>
Sun, 6 Feb 2022 09:49:41 +0000 (10:49 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 1 Apr 2022 08:07:49 +0000 (10:07 +0200)
pdns/lwres.cc
pdns/pdns_recursor.cc
pdns/rec_channel_rec.cc
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-main.hh
pdns/syncres.cc
pdns/syncres.hh

index c100c0503739f30959920f52d19f6cc41d6eaab4..1f3124de1dbb34d3a28dcdbd5fd7f0471b83f24a 100644 (file)
@@ -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"
index d5bb49d280422e96ff2af2d72f209f219c23472e..89f03882dbf6c7142e4267043452f4851de6d95a 100644 (file)
@@ -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) {
index 9ea9589dbcfe294af0ceed9966b970d4977a5ffe..c24f9eed4b43c8510b8add7246962fec27ee3f9b 100644 (file)
@@ -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<uint32_t>(*begin);
     return "New max packetcache entries: " + std::to_string(g_maxPacketCacheEntries) + "\n";
index be4ded3286174973ff2af4cf51dfadd932dfcf88..131b9021e12f2780c9f1824d706905dc7a64b5eb 100644 (file)
@@ -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<RecursorPacketCache>();
+    if (!::arg().mustDo("disable-packetcache") && (threadInfo.isDistributor() || threadInfo.isWorker())) {
+      t_packetCache = std::make_unique<RecursorPacketCache>();
+    }
 
 #ifdef NOD_ENABLED
     if (threadInfo.isWorker())
@@ -2704,7 +2705,7 @@ string doTraceRegex(vector<string>::const_iterator begin, vector<string>::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)
index 98eb57023e59a70e6a2c8298a638bb233ca15000..8a29e825d7b8f20696c527d45d2cc405736f7954 100644 (file)
@@ -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<std::shared_ptr<PacketID>, PacketBuffer, PacketIDCompare> MT_t;
 extern thread_local std::unique_ptr<MT_t> MT; // the big MTasker
+extern thread_local std::unique_ptr<RecursorPacketCache> t_packetCache;
 
 extern bool g_logCommonErrors;
 extern size_t g_proxyProtocolMaximumSize;
index 3f80f1caea5287072020f83349421aa90e77879c..dec95f4bf4b492dd89faeb534c7502d153cc4280 100644 (file)
@@ -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;
index c9e3abc0f1d446a17ae685a3c46189060c986a1a..95f11317325a295025ae340ae7cb4ffce46b0211 100644 (file)
@@ -39,7 +39,6 @@
 #include "circular_buffer.hh"
 #include "sstuff.hh"
 #include "recursor_cache.hh"
-#include "recpacketcache.hh"
 #include <boost/optional.hpp>
 #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<MemRecursorCache> g_recCache;
-extern thread_local std::unique_ptr<RecursorPacketCache> t_packetCache;
 
 struct RecursorStats
 {