From 928a1cb034e6f9e8edcdd1dc07264cd703e00827 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Tue, 17 Jan 2023 17:13:50 +0100 Subject: Alloc: Disable transparent huge pages 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/unix/alloc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sysdep/unix/alloc.c') diff --git a/sysdep/unix/alloc.c b/sysdep/unix/alloc.c index e7c4e6b0..5d9c6bcd 100644 --- a/sysdep/unix/alloc.c +++ b/sysdep/unix/alloc.c @@ -19,6 +19,10 @@ #include #endif +#ifdef CONFIG_DISABLE_THP +#include +#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); -- cgit v1.2.3