Skip to content

Commit

Permalink
Add MapFlags::hugetlb_with_size method
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Sep 22, 2023
1 parent 9247191 commit b113b88
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/backend/linux_raw/mm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ bitflags! {
}
}

impl MapFlags {
/// Create `MAP_HUGETLB` with provided size of huge page.
///
/// Under the hood it computes `MAP_HUGETLB | (huge_page_size_log2 << MAP_HUGE_SHIFT)`.
/// `huge_page_size_log2` denotes logarithm of huge page size to use and should between 16 and 63
/// (inclusively). For example, `MapFlags::map_hugetlb_with_shift(30)` returns value equal to
/// `Some(MapFlags::HUGETLB | MapFlags::HUGE_1GB)`.
#[cfg(target_os = "linux")]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn hugetlb_with_size(huge_page_size_log2: u32) -> Option<Self> {
use linux_raw_sys::general::{MAP_HUGETLB, MAP_HUGE_SHIFT};
if (16..=63).contains(&huge_page_size_log2) {
let bits = MAP_HUGETLB | (huge_page_size_log2 << MAP_HUGE_SHIFT);
Self::from_bits(bits)
} else {
None
}
}
}

bitflags! {
/// `MREMAP_*` flags for use with [`mremap`].
///
Expand Down

0 comments on commit b113b88

Please sign in to comment.