1use kernel::relaxed_atomic::RelaxedAtomicI64;
6
7#[repr(u8)]
11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
12pub enum VmPageState {
13 Free = 0,
14 Alloc,
15 Object,
16 Wired,
17 Heap,
18 Mmu,
20 Iommu,
22 Ipc,
23 Cache,
24 Slab,
25 Zram,
26 FreeLoaned,
27
28 Count,
29}
30
31impl VmPageState {
32 #[inline]
34 pub const fn index(self) -> usize {
35 self as usize
36 }
37}
38
39#[repr(C)]
41#[derive(Debug, Default)]
42pub struct VmPageCounts {
43 pub by_state: [RelaxedAtomicI64; (VmPageState::Count).index()],
45}
46
47#[inline]
49pub const fn page_state_to_string(state: VmPageState) -> &'static str {
50 match state {
51 VmPageState::Free => "free",
52 VmPageState::Alloc => "alloc",
53 VmPageState::Object => "object",
54 VmPageState::Wired => "wired",
55 VmPageState::Heap => "heap",
56 VmPageState::Mmu => "mmu",
57 VmPageState::Ipc => "ipc",
58 VmPageState::Cache => "cache",
59 VmPageState::Slab => "slab",
60 VmPageState::Zram => "zram",
61 _ => "unknown",
62 }
63}
64
65impl core::fmt::Display for VmPageState {
66 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67 f.write_str(page_state_to_string(*self))
68 }
69}
70
71const _: () = assert!(core::mem::size_of::<VmPageState>() == 1);
72const _: () = assert!(core::mem::align_of::<VmPageState>() == 1);
73const _: () = assert!(core::mem::size_of::<VmPageCounts>() == 12 * 8);
74const _: () = assert!(core::mem::align_of::<VmPageCounts>() == 8);
75const _: () = assert!(core::mem::offset_of!(VmPageCounts, by_state) == 0);