Started: `memfile::hp`: `MFD_HUGETLB` can be used when a size is known to exceed into the boundary of a hugepage. Currently in the process of writing function to collect all possible hugepage sizes and generate the correct flag masks for `memfd_create(, MFD_HUGETLB | ...)` for each one; and the smallest one that contains the known size can be used for the `memfd_create()` call (if the size fits any at all.)
TODO: This will be a seperate comptime feature: `hugetlb`: Extend `memfile` with the ability to allocate apporpirately sized huge-pages when input size is known to extend into them. Fortune for collect's current commit: Blessing − 吉safe-memfd
parent
2c839da13b
commit
59363848a2
@ -0,0 +1,35 @@
|
|||||||
|
//! # Huge pages
|
||||||
|
//! Calculates available huge page sizes, and creates `memfd_create()` flag masks for a `MFD_HUGETLB` fd.
|
||||||
|
use super::*;
|
||||||
|
use std::{
|
||||||
|
path::Path,
|
||||||
|
};
|
||||||
|
use libc::{
|
||||||
|
MFD_HUGETLB,
|
||||||
|
MAP_HUGE_SHIFT,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The location in the kernel's API which shows all valid huge-page sizes.
|
||||||
|
///
|
||||||
|
/// This is a directory, and its subdirectories' *names* will contain the size in this format: `hugepages-(\d+)kB` (where the first capture-group is the size in kB.)
|
||||||
|
/// The contents of those subdirectories themselves are irrelevent for our purpose.
|
||||||
|
pub const HUGEPAGE_SIZES_LOCATION: &'static str = "/sys/kernel/mm/hugepages";
|
||||||
|
|
||||||
|
/// Take a directory path and try to parse the hugepage size from it.
|
||||||
|
///
|
||||||
|
/// All subdirectories from `HUGEPAGE_SIZES_LOCATION` should be passed to this, and the correct system-valid hugepage size will be returned for that specific hugepage.
|
||||||
|
fn find_size_bytes(path: impl AsRef<Path>) -> Option<usize>
|
||||||
|
{
|
||||||
|
let path= path.as_ref();
|
||||||
|
if !path.is_dir() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let dir_name = path.file_name()?;
|
||||||
|
// location of the `-` in the dir name
|
||||||
|
let split_loc = memchr::memchr(b'-', dir_name.as_bytes())?;
|
||||||
|
|
||||||
|
//TODO: find the `k` (XXX: Is it always in kB? Or do we have to find the last non-digit byte instead?) For now, we can just memchr('k') I think -- look into kernel spec for this later.
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
Loading…
Reference in new issue