]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: report error when linux map limit is too low
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 15 May 2024 09:03:07 +0000 (11:03 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 23 May 2024 06:56:46 +0000 (08:56 +0200)
(cherry picked from commit 49a683354132788191a55af9f7ab2ef44d72f271)

pdns/recursordist/rec-main.cc

index adcf9556efe509e448298579e7c8762951e1ccba..bcc7bcf051464dac74cf5f4ca44b6a408a76e4f8 100644 (file)
@@ -905,6 +905,24 @@ static void checkLinuxIPv6Limits([[maybe_unused]] Logr::log_t log)
 #endif
 }
 
+static void checkLinuxMapCountLimits([[maybe_unused]] Logr::log_t log)
+{
+#ifdef __linux__
+  string line;
+  if (readFileIfThere("/proc/sys/vm/max_map_count", &line)) {
+    auto lim = std::stoull(line);
+    // mthread stack use 3 maps per stack (2 guard pages + stack itself). Multiple by 4 for extra allowance.
+    // Also add 2 for handler and task threads.
+    auto mapsNeeded = 4ULL * g_maxMThreads * (RecThreadInfo::numTCPWorkers() + RecThreadInfo::numUDPWorkers() + 2);
+    if (lim < mapsNeeded) {
+      SLOG(g_log << Logger::Error << "sysctl kern.max_map_count= <" << mapsNeeded << ", this may cause 'bad_alloc' exceptions" << endl,
+           log->info(Logr::Error, "sysctl kern.max_map_count < mapsNeeded, this may cause 'bad_alloc' exceptions",
+                     "kern.max_map_count", Logging::Loggable(lim), "mapsNeeded", Logging::Loggable(mapsNeeded)));
+    }
+  }
+#endif
+}
+
 static void checkOrFixFDS(Logr::log_t log)
 {
   unsigned int availFDs = getFilenumLimit();
@@ -2138,6 +2156,8 @@ static int serviceMain(Logr::log_t log)
 
   g_maxMThreads = ::arg().asNum("max-mthreads");
 
+  checkLinuxMapCountLimits(log);
+
   int64_t maxInFlight = ::arg().asNum("max-concurrent-requests-per-tcp-connection");
   if (maxInFlight < 1 || maxInFlight > USHRT_MAX || maxInFlight >= g_maxMThreads) {
     SLOG(g_log << Logger::Warning << "Asked to run with illegal max-concurrent-requests-per-tcp-connection, setting to default (10)" << endl,