From 311f8ab2c7e36a4267c4e0b8870b79df28f36440 Mon Sep 17 00:00:00 2001 From: Andrew Battat Date: Tue, 10 Feb 2026 21:56:49 +0000 Subject: [PATCH] Test disable MADV_HUGEPAGE --- .../src/page_map/page_allocator/mmap.rs | 51 +++++++++++-------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/rs/replicated_state/src/page_map/page_allocator/mmap.rs b/rs/replicated_state/src/page_map/page_allocator/mmap.rs index 3ac2b05a4c6b..9127be46e237 100644 --- a/rs/replicated_state/src/page_map/page_allocator/mmap.rs +++ b/rs/replicated_state/src/page_map/page_allocator/mmap.rs @@ -19,13 +19,17 @@ use std::os::unix::io::RawFd; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; +// TODO(EXC-XXXX): MADV_HUGEPAGE disabled; these are temporarily unused. #[cfg(target_os = "linux")] +#[allow(unused_imports)] use ic_sys::HUGE_PAGE_SIZE; #[cfg(target_os = "linux")] +#[allow(unused_imports)] use ic_types::NumOsPages; /// The minimum number of huge pages where the actual huge page optimization /// will kick in. This corresponds to 64 MiB of memory (because the huge page size is 2 MiB) #[cfg(target_os = "linux")] +#[allow(dead_code)] const MIN_NUM_HUGE_PAGES_FOR_OPTIMIZATION: NumOsPages = NumOsPages::new(32); const MIN_PAGES_TO_FREE: usize = 10000; @@ -622,28 +626,33 @@ impl MmapBasedPageAllocatorCore { ) }) as *mut u8; + // TODO(EXC-XXXX): Disabled MADV_HUGEPAGE to work around a suspected + // kernel 6.17 regression where MADV_REMOVE (hole-punching) on large + // folios in shmem-backed memfd mappings can silently zero adjacent + // pages, causing PageValidation assertion failures and replica crashes. + // // Do madvise transparent huge page performance optimization only on Linux. - #[cfg(target_os = "linux")] - { - // Huge pages are 2MiB on x86_64. We only use huge pages for - // memory allocations that are at least MIN_NUM_HUGE_PAGES_FOR_OPTIMIZATION huge pages (i.e., 64 MiB). - if mmap_size >= MIN_NUM_HUGE_PAGES_FOR_OPTIMIZATION.get() as usize * HUGE_PAGE_SIZE { - unsafe { - madvise( - mmap_ptr as *mut c_void, - mmap_size, - MmapAdvise::MADV_HUGEPAGE, - ) - }.unwrap_or_else(|err| { - // We don't need to panic, madvise failing is not a problem, - // it will only mean that we are not using huge pages. - println!( - "MmapPageAllocator failed to madvise {} bytes at address {:?} for memory file #{}: {}", - mmap_size, mmap_ptr, self.file_descriptor, err - ) - }); - } - } + // #[cfg(target_os = "linux")] + // { + // // Huge pages are 2MiB on x86_64. We only use huge pages for + // // memory allocations that are at least MIN_NUM_HUGE_PAGES_FOR_OPTIMIZATION huge pages (i.e., 64 MiB). + // if mmap_size >= MIN_NUM_HUGE_PAGES_FOR_OPTIMIZATION.get() as usize * HUGE_PAGE_SIZE { + // unsafe { + // madvise( + // mmap_ptr as *mut c_void, + // mmap_size, + // MmapAdvise::MADV_HUGEPAGE, + // ) + // }.unwrap_or_else(|err| { + // // We don't need to panic, madvise failing is not a problem, + // // it will only mean that we are not using huge pages. + // println!( + // "MmapPageAllocator failed to madvise {} bytes at address {:?} for memory file #{}: {}", + // mmap_size, mmap_ptr, self.file_descriptor, err + // ) + // }); + // } + // } self.chunks.push(Chunk { ptr: mmap_ptr,