]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
physmem: On NetBSD, consider the available swap space.
authorBruno Haible <bruno@clisp.org>
Sun, 19 Jul 2026 15:18:31 +0000 (17:18 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 19 Jul 2026 15:18:31 +0000 (17:18 +0200)
* lib/physmem.c (physmem_claimable): Also consider the number of
available swap pages.

ChangeLog
lib/physmem.c

index 18d02d12462d140d77367cd134880bd60f2b8bfa..57d0203c19120c2dab1a90fe218b32aac22215d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-07-19  Bruno Haible  <bruno@clisp.org>
+
+       physmem: On NetBSD, consider the available swap space.
+       * lib/physmem.c (physmem_claimable): Also consider the number of
+       available swap pages.
+
 2026-07-18  Bruno Haible  <bruno@clisp.org>
 
        diffseq: Restore gcc 17 -fanalyzer customization (regr. yesterday).
index ccfb596e42f634e78fe24b374d3cc29d04d241ce..9df908637b9c66ba33b7ffdce732b97122dece91 100644 (file)
@@ -312,7 +312,18 @@ physmem_claimable (double aggressivity)
         && len == sizeof uvmexp)
       {
         double pagesize = getpagesize ();
-        return (uvmexp.free + uvmexp.inactive) * pagesize;
+        /* On NetBSD, a process needs a number of memory pages and a comparable
+           number of swap pages.  When not enough swap pages are available, the
+           process might be killed with "killed: out of swap", or the machine
+           might become unresponsive.  */
+        double available_memory_pages = uvmexp.free + uvmexp.inactive;
+        double available_swap_pages =
+          (unsigned long long) ((uvmexp.swpages - uvmexp.swpginuse) * 0.85);
+        double available_pages =
+          (available_memory_pages < available_swap_pages
+           ? available_memory_pages
+           : available_swap_pages);
+        return available_pages * pagesize;
       }
   }
 #endif