starry_kernel/mm/aspace/
reclaim.rs1use super::{FrameLease, PageObject};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct SwapToken(u64);
8
9impl SwapToken {
10 pub const fn new(value: u64) -> Self {
11 Self(value)
12 }
13
14 pub const fn get(self) -> u64 {
15 self.0
16 }
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum SwapError {
21 Unsupported,
23 Busy,
24 Io,
25}
26
27pub trait SwapProvider {
34 fn swap_out(&self, page: &PageObject) -> Result<SwapToken, SwapError>;
35 fn swap_in(&self, token: SwapToken, frame: FrameLease) -> Result<(), SwapError>;
36}
37
38#[derive(Debug, Default, Clone, Copy)]
40pub struct UnsupportedSwap;
41
42impl SwapProvider for UnsupportedSwap {
43 fn swap_out(&self, _page: &PageObject) -> Result<SwapToken, SwapError> {
44 Err(SwapError::Unsupported)
45 }
46
47 fn swap_in(&self, _token: SwapToken, _frame: FrameLease) -> Result<(), SwapError> {
48 Err(SwapError::Unsupported)
49 }
50}