Skip to main content

PageSize

Enum PageSize 

Source
#[repr(usize)]
pub enum PageSize { K4 = 4_096, K16 = 16_384, K64 = 65_536, }
Expand description

Strongly-typed virtual memory page size representing hardware MMU translation granules

Across supported operating systems and CPU architectures, base virtual memory page sizes form a strictly bounded set corresponding to hardware translation granules:

  • 4 KiB (4,096 bytes): Standard on x86/x86_64, Windows, and default Linux AArch64
  • 16 KiB (16,384 bytes): Apple Silicon macOS and 16k Linux kernels
  • 64 KiB (65,536 bytes): Enterprise Linux AArch64 (RHEL, CentOS Stream, Amazon Linux)

§Example

use frozen_core::memmap::PageSize;

let ps = PageSize::try_from(4096).unwrap();
assert_eq!(ps, PageSize::K4);
assert_eq!(ps.as_usize(), 4096);
assert_eq!(ps.as_u32(), 4096);
assert!(ps.is_power_of_two());

Variants§

§

K4 = 4_096

4 KiB (4,096 bytes) - Standard x86_64, Windows, and default Linux AArch64

§

K16 = 16_384

16 KiB (16,384 bytes) - Native Apple Silicon macOS and 16k Linux kernels

§

K64 = 65_536

64 KiB (65,536 bytes) - Enterprise Linux AArch64 (RHEL, CentOS, Amazon Linux)

Implementations§

Source§

impl PageSize

Source

pub const fn as_usize(self) -> usize

Returns the page size in bytes as usize

Source

pub const fn as_u32(self) -> u32

Returns the page size in bytes as u32

Source

pub const fn is_power_of_two(self) -> bool

Returns true since all valid hardware page sizes are powers of two

Source

pub fn validate_platform(self) -> FrozenResult<Self>

Validates whether this page size is supported on the active host operating system and architecture

§Platform rules
  • Windows: Only PageSize::K4 (4096 bytes) is valid
  • macOS: PageSize::K16 or PageSize::K4 on aarch64; PageSize::K4 on x86_64
  • Linux: PageSize::K4 on x86/x86_64; PageSize::K4, PageSize::K16, PageSize::K64

Trait Implementations§

Source§

impl Clone for PageSize

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PageSize

Source§

impl Debug for PageSize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PageSize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PageSize

Source§

impl From<PageSize> for usize

Source§

fn from(ps: PageSize) -> Self

Converts to this type from the input type.
Source§

impl From<PageSize> for u32

Source§

fn from(ps: PageSize) -> Self

Converts to this type from the input type.
Source§

impl From<PageSize> for u64

Source§

fn from(ps: PageSize) -> Self

Converts to this type from the input type.
Source§

impl Hash for PageSize

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for PageSize

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for PageSize

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for PageSize

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for PageSize

Source§

impl TryFrom<usize> for PageSize

Source§

type Error = FrozenError

The type returned in the event of a conversion error.
Source§

fn try_from(size: usize) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.