From: Bruno Haible Date: Sun, 19 Jul 2026 15:18:31 +0000 (+0200) Subject: physmem: On NetBSD, consider the available swap space. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6bb21523280811c17e2c45ebaa75fe5ddef1fda;p=thirdparty%2Fgnulib.git physmem: On NetBSD, consider the available swap space. * lib/physmem.c (physmem_claimable): Also consider the number of available swap pages. --- diff --git a/ChangeLog b/ChangeLog index 18d02d1246..57d0203c19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2026-07-19 Bruno Haible + + 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 diffseq: Restore gcc 17 -fanalyzer customization (regr. yesterday). diff --git a/lib/physmem.c b/lib/physmem.c index ccfb596e42..9df908637b 100644 --- a/lib/physmem.c +++ b/lib/physmem.c @@ -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