Skip to main content

Crate kevy_madvise

Crate kevy_madvise 

Source
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 (Linux MADV_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 len bytes via anonymous mmap, with the returned address 2 MiB-aligned AND the mapped length rounded up to a 2 MiB multiple. Then calls MADV_HUGEPAGE on the returned region.
munmap_2mb
Release a buffer previously returned by mmap_anon_aligned_2mb. len must 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 from mmap_anon_aligned_2mb is UB.