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 5cea3dd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 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,24 @@ 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)`.
pub const fn hugetlb_with_size(huge_page_size_log2: u32) -> Option<Self> {
use linux_raw_sys::general::{MAP_HUGETLB, MAP_HUGE_SHIFT};
if 16 <= huge_page_size_log2 && huge_page_size_log2 <= 63 {
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 5cea3dd

Please sign in to comment.