From d46efebbf7d0ae1e091595843a7581d551cace92 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 2 May 2022 00:50:36 +0100 Subject: [PATCH] Added huge-page mask calculation algorithm to comment of module file `memfile::hp`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fortune for collect's current commit: Middle blessing − 中吉 --- src/memfile/hp.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/memfile/hp.rs b/src/memfile/hp.rs index 61e2235..fdad374 100644 --- a/src/memfile/hp.rs +++ b/src/memfile/hp.rs @@ -1,5 +1,15 @@ //! # Huge pages //! Calculates available huge page sizes, and creates `memfd_create()` flag masks for a `MFD_HUGETLB` fd. +//! +//! ## Method of calculating HUGETLB masks +//! * Enumerate and find the numbers matching on the subdirectories in dir `/sys/kernel/mm/hugepages/hugepages-(\d+)kB/` +//! * Multiply that number by `1024`. +//! * Calculate the base-2 logorithm (`log2()`) of the resulting number. +//! * Left shift that number by `MAP_HUGE_SHIFT`. This produces a valid `MAP_HUGE_...`-useable flag the same as the builtin `sys/mman.h` flags (`MAP_HUGE_2MB`, `MAP_HUGE_1GB`, etc..) +//! * The resulting number is a valid flag to pass to `memfd_create()` if it is `|`d with `MFD_HUGETLB` +//! +//! All `MAP_HUGE_...` flags must be bitwise OR'd with that flag in `memfd_create()`, however other memory handling syscalls that support hugepages will also accept the constructed `MAP_HUGE_...` flag as valid as per their own specification. + use super::*; use std::{ path::Path,