]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Incorporate comments from @rgacogne
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 7 Dec 2022 09:09:25 +0000 (10:09 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 7 Dec 2022 10:08:25 +0000 (11:08 +0100)
pdns/bpf-filter.cc

index 7d5e018370a94cbd921065dd54b38a4b8a2d60b1..435c0f16f7f274a8b9f928ed8e78503113443b64 100644 (file)
@@ -357,22 +357,24 @@ BPFFilter::BPFFilter(std::unordered_map<std::string, MapConfiguration>& configs,
   }
 
   struct rlimit old_limit;
-  const rlim_t new_limit_size = 1024 * 1024;
-
   if (getrlimit(RLIMIT_MEMLOCK, &old_limit) != 0) {
     throw std::runtime_error("Unable to get memory lock limit: " + stringerror());
   }
 
-  /* Check if the current soft memlock limit is 64k */ 
-  if (old_limit.rlim_cur < (64 * 1024)) {
+  const rlim_t minimal_limit_size = 64 * 124;
+  const rlim_t new_limit_size = 1024 * 1024;
+
+  /* Check if the current soft memlock limit is at least minimal_limit */
+  if (old_limit.rlim_cur < minimal_limit_size) {
+    infolog("The current limit of locked memory (soft: %d, hard: %d) is too low for eBPF, trying to raise it to %d", old_limit.rlim_cur, old_limit.rlim_max, new_limit_size);
+
     struct rlimit new_limit;
-    new_limit.rlim_cur = new_limit_size; /* Increase soft limit to 1024k */
-    new_limit.rlim_max = new_limit_size; /* Increase hard limit to 1024k */
-  
+    new_limit.rlim_cur = new_limit_size;
+    new_limit.rlim_max = new_limit_size;
+
     if (setrlimit(RLIMIT_MEMLOCK, &new_limit) != 0) {
-      errlog("Unable to raise the maximum amount of locked memory for eBPF from %d to %d, consider raising RLIMIT_MEMLOCK or setting LimitMEMLOCK=infinity in the systemd unit: %s", old_limit.rlim_cur, new_limit.rlim_cur, stringerror());
+      warnlog("Unable to raise the maximum amount of locked memory for eBPF from %d to %d, consider raising RLIMIT_MEMLOCK or setting LimitMEMLOCK in the systemd unit: %d", old_limit.rlim_cur, new_limit.rlim_cur, stringerror());
     }
-    infolog("The current limit of locked memory (soft: %d, hard: %d) is too low for eBPF, trying to raise it to %d", old_limit.rlim_cur, old_limit.rlim_max, new_limit_size);
   }
 
   auto maps = d_maps.lock();