Skip to main content

starry_kernel/mm/aspace/
reclaim.rs

1//! Typed interfaces for reclaim capabilities that are not implemented yet.
2
3use super::{FrameLease, PageObject};
4
5/// A stable token identifying a future swap-cache entry.
6#[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    /// Starry currently has no swap device or swap cache implementation.
22    Unsupported,
23    Busy,
24    Io,
25}
26
27/// Capability boundary for anonymous swap.
28///
29/// Keeping this interface typed lets `MADV_PAGEOUT` and future reclaim code
30/// report an explicit unsupported result instead of pretending that a page was
31/// evicted.  Implementations must transfer frame ownership through
32/// `FrameLease`; callers never exchange a bare physical address.
33pub 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/// Default provider used until a swap device is wired into Starry.
39#[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}