Expand description
kevy-madvise — thin pure-Rust madvise hints.
A single best-effort kernel hint: tell Linux a region is a candidate for
transparent huge pages (MADV_HUGEPAGE). Hand-bound with unsafe extern "C" against glibc — no libc crate, no third-party dependency. Off Linux
every entry point compile-time no-ops.
Carved out of kevy-sys so it can be used by other library crates (like
kevy-map) without dragging the rest of the OS-boundary internals along. See
advise_hugepage for the only entry point.
§Safety
unsafe is confined to a single extern "C" declaration of madvise(3)
and one wrapper call site. The wrapper rounds the request to page
boundaries, never reads or writes Rust memory, and silently no-ops when
the kernel returns EINVAL — making it safe to expose as a plain fn.
Functions§
- advise_
hugepage - Hint the kernel that the region
[ptr, ptr+len)is a candidate for transparent huge pages (LinuxMADV_HUGEPAGE). A best-effort kernel hint — returns nothing; mis-alignment / unsupported kernels silently no-op. Off Linux this is a compile-time no-op. - mmap_
anon_ aligned_ 2mb - Allocate
lenbytes via anonymousmmap, with the returned address 2 MiB-aligned AND the mapped length rounded up to a 2 MiB multiple. Then callsMADV_HUGEPAGEon the returned region. - munmap_
2mb ⚠ - Release a buffer previously returned by
mmap_anon_aligned_2mb.lenmust equal the original allocation length (or any value within the same 2 MiB-rounded total — the function rounds internally to match). Passing a pointer NOT obtained frommmap_anon_aligned_2mbis UB.