Skip to main content

madvise_aligned

Function madvise_aligned 

Source
unsafe fn madvise_aligned(base_ptr: *const u8, len_bytes: usize, advice: c_int)
Available on Linux and Unix and crate feature pager only.
Expand description

Issues madvise(advice) over the page-aligned interior of the byte range [base_ptr, base_ptr + len_bytes). madvise operates at page granularity, so the start rounds up and the end rounds down to page boundaries; a range that contains no whole page is skipped so we never advise pages we only partially own.

§Safety

base_ptr must point to the start of a live allocation of at least len_bytes bytes that stays valid for the duration of the call. advice must be a non-mutating hint (MADV_COLD/MADV_PAGEOUT): both only change the kernel’s reclaim decision and leave the bytes readable, so concurrent reads of the range remain sound.