Skip to main content

PageOrder

Struct PageOrder 

Source
pub struct PageOrder(/* private fields */);
Expand description

The order of a page frame block.

Order n represents 2^n contiguous pages:

  • Order 0: 1 page (4KB)
  • Order 1: 2 pages (8KB)
  • Order 2: 4 pages (16KB)
  • Order 9: 512 pages (2MB)

§Examples

use ruvix_physmem::PageOrder;

let order = PageOrder::new(2).unwrap();
assert_eq!(order.pages(), 4);
assert_eq!(order.bytes(), 16384);

Implementations§

Source§

impl PageOrder

Source

pub const MIN: Self

The minimum order (single page, 4KB).

Source

pub const MAX: Self

The maximum order (512 pages, 2MB).

Source

pub const fn new(order: usize) -> Option<Self>

Creates a new page order.

Returns None if the order is greater than or equal to MAX_ORDER.

§Arguments
  • order - The order value (0 to MAX_ORDER - 1).
§Examples
use ruvix_physmem::PageOrder;

assert!(PageOrder::new(0).is_some());
assert!(PageOrder::new(9).is_some());
assert!(PageOrder::new(10).is_none()); // MAX_ORDER = 10
Source

pub const fn new_unchecked(order: usize) -> Self

Creates a new page order without bounds checking.

§Safety

This is safe because we only store a u8 and the buddy allocator will validate the order. However, using an invalid order will result in unexpected behavior.

§Arguments
  • order - The order value.
Source

pub const fn as_usize(self) -> usize

Returns the order as a usize.

Source

pub const fn pages(self) -> usize

Returns the number of pages for this order.

§Examples
use ruvix_physmem::PageOrder;

assert_eq!(PageOrder::new(0).unwrap().pages(), 1);
assert_eq!(PageOrder::new(1).unwrap().pages(), 2);
assert_eq!(PageOrder::new(2).unwrap().pages(), 4);
assert_eq!(PageOrder::new(9).unwrap().pages(), 512);
Source

pub const fn bytes(self) -> usize

Returns the block size in bytes for this order.

§Examples
use ruvix_physmem::PageOrder;

assert_eq!(PageOrder::new(0).unwrap().bytes(), 4096);
assert_eq!(PageOrder::new(1).unwrap().bytes(), 8192);
assert_eq!(PageOrder::new(9).unwrap().bytes(), 2 * 1024 * 1024);
Source

pub const fn next(self) -> Option<Self>

Returns the next higher order, if it exists.

§Examples
use ruvix_physmem::PageOrder;

let order = PageOrder::new(2).unwrap();
assert_eq!(order.next().map(|o| o.as_usize()), Some(3));

let max = PageOrder::MAX;
assert!(max.next().is_none());
Source

pub const fn prev(self) -> Option<Self>

Returns the next lower order, if it exists.

§Examples
use ruvix_physmem::PageOrder;

let order = PageOrder::new(2).unwrap();
assert_eq!(order.prev().map(|o| o.as_usize()), Some(1));

let min = PageOrder::MIN;
assert!(min.prev().is_none());
Source

pub const fn from_pages(pages: usize) -> Option<Self>

Creates an order from a page count, rounding up if necessary.

Returns None if the resulting order would exceed MAX_ORDER - 1.

§Arguments
  • pages - The number of pages needed.
§Examples
use ruvix_physmem::PageOrder;

assert_eq!(PageOrder::from_pages(1).map(|o| o.as_usize()), Some(0));
assert_eq!(PageOrder::from_pages(2).map(|o| o.as_usize()), Some(1));
assert_eq!(PageOrder::from_pages(3).map(|o| o.as_usize()), Some(2)); // rounds up
assert_eq!(PageOrder::from_pages(4).map(|o| o.as_usize()), Some(2));
assert_eq!(PageOrder::from_pages(512).map(|o| o.as_usize()), Some(9));
assert!(PageOrder::from_pages(513).is_none()); // Too large
Source

pub const fn from_bytes(bytes: usize) -> Option<Self>

Creates an order from a byte size, rounding up if necessary.

Returns None if the resulting order would exceed MAX_ORDER - 1.

§Arguments
  • bytes - The number of bytes needed.
§Examples
use ruvix_physmem::PageOrder;

assert_eq!(PageOrder::from_bytes(1).map(|o| o.as_usize()), Some(0));
assert_eq!(PageOrder::from_bytes(4096).map(|o| o.as_usize()), Some(0));
assert_eq!(PageOrder::from_bytes(4097).map(|o| o.as_usize()), Some(1));
assert_eq!(PageOrder::from_bytes(8192).map(|o| o.as_usize()), Some(1));

Trait Implementations§

Source§

impl Clone for PageOrder

Source§

fn clone(&self) -> PageOrder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PageOrder

Source§

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

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

impl Default for PageOrder

Source§

fn default() -> PageOrder

Returns the “default value” for a type. Read more
Source§

impl Display for PageOrder

Source§

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

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

impl Hash for PageOrder

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 PageOrder

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for PageOrder

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for PageOrder

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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 Copy for PageOrder

Source§

impl Eq for PageOrder

Source§

impl StructuralPartialEq for PageOrder

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.