]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Alloc: Disable transparent huge pages
authorOndrej Zajicek <santiago@crfreenet.org>
Tue, 17 Jan 2023 16:13:50 +0000 (17:13 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Tue, 17 Jan 2023 16:13:50 +0000 (17:13 +0100)
The usage pattern implemented in allocator seems to be incompatible with
transparent huge pages, as memory released using madvise(MADV_DONTNEED)
with regular page size and alignment does not seem to trigger demotion
of huge pages back to regular pages, even when significant number of
pages is released. Even if demotion is triggered when system memory
is low, it still breaks memory accounting.

sysdep/cf/README
sysdep/cf/linux.h
sysdep/unix/alloc.c

index 68078bbe7e21f999c69e351e6f29be2b7766a998..af65aaec49a3fc441127026000e41fff5566ea59 100644 (file)
@@ -14,3 +14,6 @@ CONFIG_DONTROUTE_UNICAST Use MSG_DONTROUTE flag for unicast packets (def for Fre
 CONFIG_USE_HDRINCL     Use IP_HDRINCL instead of control messages for source address on raw IP sockets.
 
 CONFIG_RESTRICTED_PRIVILEGES   Implements restricted privileges using drop_uid()
+
+CONFIG_MADV_DONTNEED_TO_FREE   To free pages, use MADV_DONTNEED instead of MADV_FREE (linux)
+CONFIG_DISABLE_THP     Disable transparent huge pages (linux)
index 9c37dd8a61d6ec7f9ae0b866111d1c821bd20cea..5edc49695a2c7bccf0d693f8f8109b0ae5e0bb82 100644 (file)
@@ -24,6 +24,7 @@
 #define CONFIG_INCLUDE_SYSPRIV_H "sysdep/linux/syspriv.h"
 
 #define CONFIG_MADV_DONTNEED_TO_FREE
+#define CONFIG_DISABLE_THP
 
 #ifndef AF_MPLS
 #define AF_MPLS 28
index e7c4e6b0e2d0a3aa906ddf4c0979ef058e0e223c..5d9c6bcd695c775bb9bdae0e7c2c023619ec2aca 100644 (file)
 #include <sys/mman.h>
 #endif
 
+#ifdef CONFIG_DISABLE_THP
+#include <sys/prctl.h>
+#endif
+
 long page_size = 0;
 
 #ifdef HAVE_MMAP
@@ -218,6 +222,12 @@ global_free_pages_cleanup_event(void *data UNUSED)
 void
 resource_sys_init(void)
 {
+#ifdef CONFIG_DISABLE_THP
+  /* Disable transparent huge pages, they do not work properly with madvice(MADV_DONTNEED) */
+  if (prctl(PR_SET_THP_DISABLE,  (unsigned long) 1,  (unsigned long) 0,  (unsigned long) 0,  (unsigned long) 0) < 0)
+    die("prctl(PR_SET_THP_DISABLE) failed: %m");
+#endif
+
 #ifdef HAVE_MMAP
   ASSERT_DIE(global_free_pages.cnt == 0);