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
Avril 2 years ago
parent 2c839da13b
commit 59363848a2
Signed by: flanchan
GPG Key ID: 284488987C31F630

2
Cargo.lock generated

@ -84,7 +84,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "collect"
version = "1.0.1"
version = "1.0.2"
dependencies = [
"bitflags",
"bytes",

@ -16,6 +16,9 @@ use std::{
pub mod fd;
pub mod error;
mod map;
//TODO: #[cfg(feature="hugetlb")]
mod hp;
/// Flags passed to `memfd_create()` when used in this module
const MEMFD_CREATE_FLAGS: libc::c_uint = libc::MFD_CLOEXEC;

@ -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…
Cancel
Save