]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove 'unlimited' setting for the max-cache-size
authorOndřej Surý <ondrej@isc.org>
Sat, 17 Jan 2026 08:56:31 +0000 (09:56 +0100)
committerOndřej Surý <ondrej@isc.org>
Mon, 30 Mar 2026 19:46:44 +0000 (21:46 +0200)
Since TTL-based cache cleaning has been removed, an unlimited
max-cache-size would eventually exhaust system memory.

Both 'max-cache-size unlimited;' and 'max-cache-size 0;' now fall
back to the default value (90% of physical memory for recursive
views).

bin/named/server.c
doc/arm/reference.rst
lib/dns/cache.c
lib/dns/include/dns/cache.h

index 8deb3e7cb5eeb2a455b01bbf8ef9b136240545c8..6d6fabc707ed07ed62c38e30bb5c6dd429b3326c 100644 (file)
@@ -3872,17 +3872,27 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                }
        }
 
+       if (max_cache_size == 0) {
+               cfg_obj_log(obj, ISC_LOG_WARNING,
+                           "'max-cache-size' can't be zero or unlimited; "
+                           "falling back to default");
+               max_cache_size = SIZE_AS_PERCENT;
+               max_cache_size_percent = 90;
+       }
+
        if (max_cache_size == SIZE_AS_PERCENT) {
                uint64_t totalphys = isc_meminfo_totalphys();
 
-               max_cache_size =
-                       (size_t)(totalphys * max_cache_size_percent / 100);
                if (totalphys == 0) {
-                       cfg_obj_log(obj, ISC_LOG_WARNING,
+                       cfg_obj_log(obj, ISC_LOG_ERROR,
                                    "Unable to determine amount of physical "
-                                   "memory, setting 'max-cache-size' to "
-                                   "unlimited");
+                                   "memory, setting 'max-cache-size' to the "
+                                   "minimum value");
+                       max_cache_size = 1;
                } else {
+                       max_cache_size = (size_t)(totalphys *
+                                                 max_cache_size_percent / 100);
+
                        cfg_obj_log(obj, ISC_LOG_INFO,
                                    "'max-cache-size %d%%' "
                                    "- setting to %" PRIu64 "MB "
index 4abd94e192a064750a877d24450e292f3b693971..9964718dd65fe9753819e00829419074416df107 100644 (file)
@@ -3832,9 +3832,12 @@ system.
      - 2 MB for views with :any:`recursion` set to ``no``.
 
    Any positive value smaller than 2 MB is ignored and reset to 2 MB.
-   The keyword ``unlimited``, or the value ``0``, places no limit on the
-   cache size; records are then purged from the cache only when they
-   expire (according to their TTLs).
+
+   .. warning::
+
+       Previously, the keyword ``unlimited``, or the value ``0``, placed
+       no limit on the cache size; this is no longer permitted as
+       TTL-based cleaning has been removed from :iscman:`named`.
 
    .. note::
 
@@ -3847,7 +3850,7 @@ system.
    .. note::
 
        :any:`max-cache-size` does not work reliably for a maximum
-       amount of memory of 100 MB or lower.
+       amount of memory of 256 MB or lower.
 
    Upon startup and reconfiguration, caches with a limited size
    preallocate a small amount of memory (less than 1% of
@@ -3856,10 +3859,13 @@ system.
    internal cache structures.
 
    On systems where detection of the amount of physical memory is not
-   supported, percentage-based values fall back to ``unlimited``. Note
-   that the amount of physical memory available is only detected on
-   startup, so :iscman:`named` does not adjust the cache size limits if the
-   amount of physical memory is changed at runtime.
+   supported, the :iscman:`named` will fail to start.
+
+   .. note::
+
+       The amount of physical memory available is only detected on startup, so
+       :iscman:`named` does not adjust the cache size limits if the amount of
+       physical memory is changed at runtime.
 
    On Linux, the system administrator can use `cgroup`_ (Control Group)
    mechanism to limit the amount of available memory to the process.  This limit
index e60eadfb44e460a214c328548eb8b215b021c9f0..ca3a641574271f44f96e8787c15ebf98eb32052f 100644 (file)
@@ -213,11 +213,7 @@ static void
 updatewater(dns_cache_t *cache) {
        size_t hi = cache->size - (cache->size >> 3); /* ~ 7/8ths. */
        size_t lo = cache->size - (cache->size >> 2); /* ~ 3/4ths. */
-       if (cache->size == 0U || hi == 0U || lo == 0U) {
-               isc_mem_clearwater(cache->tmctx);
-       } else {
-               isc_mem_setwater(cache->tmctx, hi, lo);
-       }
+       isc_mem_setwater(cache->tmctx, hi, lo);
 }
 
 void
@@ -228,7 +224,7 @@ dns_cache_setcachesize(dns_cache_t *cache, size_t size) {
         * Impose a minimum cache size; pathological things happen if there
         * is too little room.
         */
-       if (size != 0U && size < DNS_CACHE_MINSIZE) {
+       if (size < DNS_CACHE_MINSIZE) {
                size = DNS_CACHE_MINSIZE;
        }
 
index e4286b2bc4af2d555d4e18f7f8337f58e5c5f044..c2f0ba7a47f470f0ce58ca52d06f2797ff0eb0c6 100644 (file)
@@ -130,7 +130,7 @@ dns_cache_getname(dns_cache_t *cache);
 void
 dns_cache_setcachesize(dns_cache_t *cache, size_t size);
 /*%<
- * Set the maximum cache size.  0 means unlimited.
+ * Set the maximum cache size.
  */
 
 size_t