]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add "-T maxcachesize=..." command line option
authorMichał Kępień <michal@isc.org>
Mon, 31 Aug 2020 11:15:33 +0000 (13:15 +0200)
committerMichał Kępień <michal@isc.org>
Mon, 31 Aug 2020 21:41:24 +0000 (23:41 +0200)
An implicit default of "max-cache-size 90%;" may cause memory use issues
on hosts which run numerous named instances in parallel (e.g. GitLab CI
runners) due to the cache RBT hash table now being pre-allocated [1] at
startup.  Add a new command line option, "-T maxcachesize=...", to allow
the default value of "max-cache-size" to be overridden at runtime.  When
this new option is in effect, it overrides any other "max-cache-size"
setting in the configuration, either implicit or explicit.  This
approach was chosen because it is arguably the simplest one to
implement.

The following alternative approaches to solving this problem were
considered and ultimately rejected (after it was decided they were not
worth the extra code complexity):

  - adding the same command line option, but making explicit
    configuration statements have priority over it,

  - adding a build-time option that allows the implicit default of
    "max-cache-size 90%;" to be overridden.

[1] see commit aa72c31422bf04c34afd539dc9986a9bac976901

(cherry picked from commit 9ac1f6a9bce355948f413de60a74cbded0f6a2be)

bin/named/include/named/globals.h
bin/named/main.c
bin/named/server.c

index eb38625f44a745b00b93bf1f86f3cf67614a8572..f125b29591cb56bc4b2143543d2e1bee0de6ba39 100644 (file)
@@ -143,6 +143,7 @@ EXTERN bool named_g_memstatistics INIT(false);
 EXTERN bool named_g_keepstderr   INIT(false);
 
 EXTERN unsigned int named_g_tat_interval INIT(24 * 3600);
+EXTERN unsigned int named_g_maxcachesize INIT(0);
 
 #if defined(HAVE_GEOIP2)
 EXTERN dns_geoip_databases_t *named_g_geoip INIT(NULL);
index 728bb611a2d287e5349acc6242381994eaa545fb..026e811c004f03e1bacbb87a42f11ed313ba0e13 100644 (file)
@@ -659,6 +659,8 @@ parse_T_opt(char *option) {
                named_g_nosyslog = true;
        } else if (!strcmp(option, "notcp")) {
                notcp = true;
+       } else if (!strncmp(option, "maxcachesize=", 13)) {
+               named_g_maxcachesize = atoi(option + 13);
        } else if (!strcmp(option, "maxudp512")) {
                maxudp = 512;
        } else if (!strcmp(option, "maxudp1460")) {
index a8e89f692ffd809c649ab4a6f5d9a1a2a993a733..75077a090d1c667d2dc316dbccc31a4b2a377286 100644 (file)
@@ -4111,7 +4111,16 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
        obj = NULL;
        result = named_config_get(maps, "max-cache-size", &obj);
        INSIST(result == ISC_R_SUCCESS);
-       if (cfg_obj_isstring(obj)) {
+       /*
+        * If "-T maxcachesize=..." is in effect, it overrides any other
+        * "max-cache-size" setting found in configuration, either implicit or
+        * explicit.  For simplicity, the value passed to that command line
+        * option is always treated as the number of bytes to set
+        * "max-cache-size" to.
+        */
+       if (named_g_maxcachesize != 0) {
+               max_cache_size = named_g_maxcachesize;
+       } else if (cfg_obj_isstring(obj)) {
                str = cfg_obj_asstring(obj);
                INSIST(strcasecmp(str, "unlimited") == 0);
                max_cache_size = 0;