]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
pagealign_alloc: Don't waste large amounts of memory (regr. 2025-09-10).
authorBruno Haible <bruno@clisp.org>
Sat, 13 Sep 2025 22:25:21 +0000 (00:25 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 13 Sep 2025 23:13:24 +0000 (01:13 +0200)
* lib/pagealign_alloc.c (get_default_impl): Choose a default that does
not waste large amounts of memory.

ChangeLog
lib/pagealign_alloc.c

index 78a8111497cdb59183392d4926d2fc9e0ef319f4..41303f9ce26655f0ac9a2446b60e14cbfe02eac3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-09-13  Bruno Haible  <bruno@clisp.org>
+
+       pagealign_alloc: Don't waste large amounts of memory (regr. 2025-09-10).
+       * lib/pagealign_alloc.c (get_default_impl): Choose a default that does
+       not waste large amounts of memory.
+
 2025-09-13  Bruno Haible  <bruno@clisp.org>
 
        pagealign_alloc: Add unit test for scalability.
index 332306bd41de7d9cb720db98a53524fcc81b9cf3..b730cceabd4937a54dc1368da1aec83b79347628 100644 (file)
@@ -70,11 +70,47 @@ static gl_map_t page_info_map;
 static pagealign_impl_t
 get_default_impl (void)
 {
-#if HAVE_POSIX_MEMALIGN
+  /* The default is chosen so as to
+     1. (most important) not waste memory, when possible.
+     2. when there is no waste of memory, avoid using the page_info_map,
+        when possible.
+     Regarding the amount of used memory, it was determined through the
+     'bench-pagealign_alloc' program.  The results were:
+
+                          b         c         d         e         f
+
+       glibc            176%      101%      175%       ---       ---
+       musl libc        198%      101%      197%       ---       ---
+       macOS            190%      100%      195%       ---       ---
+       FreeBSD          190%      100%      380%       ---       ---
+       NetBSD           185%      101%      379%       ---       ---
+       OpenBSD          177%      101%      101%       ---       ---
+       AIX              177%      101%      176%       ---       ---
+       Solaris 11.4     176%      101%      175%       ---       ---
+       Cygwin           181%      100%      181%       ---       ---
+       native Windows   184%       ---       ---      180%      100%
+       Android          182%      101%      181%       ---       ---
+
+     where
+       b = PA_IMPL_MALLOC
+       c = PA_IMPL_MMAP
+       d = PA_IMPL_POSIX_MEMALIGN
+       e = PA_IMPL_ALIGNED_MALLOC
+       f = PA_IMPL_VIRTUAL_ALLOC
+   */
+#if defined _WIN32 && !defined __CYGWIN__
+  /* Native Windows.  */
+  return PA_IMPL_VIRTUAL_ALLOC;
+#elif defined __OpenBSD__ && HAVE_POSIX_MEMALIGN
+  /* On OpenBSD, we may choose among PA_IMPL_MMAP and PA_IMPL_POSIX_MEMALIGN.
+     The latter does not need the page_info_map.  */
   return PA_IMPL_POSIX_MEMALIGN;
 #elif HAVE_SYS_MMAN_H
+  /* On all other platforms, PA_IMPL_MMAP is the only implementation that does
+     not waste memory.  */
   return PA_IMPL_MMAP;
 #else
+  /* Old platforms without mmap: use PA_IMPL_MALLOC.  */
   return PA_IMPL_MALLOC;
 #endif
 }