Residency

Struct Residency 

Source
pub struct Residency<A: SlotArena, S: SwapStore> { /* private fields */ }
Expand description

2026-09-25: The page table from a u64 key to a SlotArena slot or a SwapStore record, evicting the least recently used resident to the store when the arena is full.

Implementations§

Source§

impl<A: SlotArena, S: SwapStore> Residency<A, S>

Source

pub fn new(arena: A, swap: S) -> Result<Self>

2026-09-25: Residency::new_capped with no disk cap.

Source

pub fn new_capped(arena: A, swap: S, max_disk_slots: usize) -> Result<Self>

2026-09-25: A residency over arena and swap with at most max_disk_slots live on-disk records (0: no cap). The file can still reach max_disk_slots + 1 records (see Residency::disk_high_water).

§Errors

slot_bytes() is 0, differs from swap.record_bytes(), or the arena has no slot.

Source

pub fn blob_bytes(&self) -> usize

Source

pub fn stats(&self) -> &SwapStats

Source

pub fn resident_count(&self) -> usize

Source

pub fn total_keys(&self) -> usize

Source

pub fn disk_count(&self) -> usize

2026-09-25: Keys on disk now; at most max_disk_slots when capped.

Source

pub fn disk_high_water(&self) -> usize

2026-09-25: The highest record index ever allocated, plus one: the swap file’s size in records. DirectSwapFile keeps the default no-op discard_record, so its file never shrinks and only index reuse through free_disk bounds it. Under a cap this reaches max_disk_slots + 1: Residency::locate’s OnDisk arm takes the faulting key out of disk_lru while its record is still live, so make_disk_room counts one fewer record than exist.

Source

pub fn max_disk_slots(&self) -> usize

2026-09-25: The on-disk record cap, 0 for none.

Source

pub fn arena(&self) -> &A

2026-09-25: The arena itself, for callers that move the bytes of a slot they got from Residency::alloc or Residency::locate; Residency::put_blob and Residency::get_blob do both steps.

Source

pub fn arena_mut(&mut self) -> &mut A

Source

pub fn slot_offset(&self, slot: usize) -> u64

2026-09-25: Byte offset of slot in the arena: slot * blob_bytes.

Source

pub fn alloc(&mut self, key: u64) -> Result<usize>

2026-09-25: Put, step 1: reserve an arena slot for key, spilling the coldest unpinned resident to the store when no slot is free. The caller writes the blob into the slot and then calls Residency::commit. A resident or reserved key keeps its slot; an on-disk key gets a new slot and its record is freed.

§Errors

Every slot is reserved or read-pinned, or the spill’s arena read or store write fails. On error the key keeps its previous location.

Source

pub fn commit(&mut self, key: u64) -> Result<()>

2026-09-25: Put, step 2: the blob is in the reserved slot; mark key resident and, unless read-pinned, the hottest in lru. Committing a resident key does nothing.

§Errors

key is neither reserved nor resident.

Source

pub fn locate(&mut self, key: u64) -> Result<Option<usize>>

2026-09-25: Get: the arena slot holding key, faulting an on-disk key back into a slot (which may spill another key). Ok(None) for an unknown key. A reserved key returns its slot, whose bytes the caller has not committed.

§Errors

No slot can be acquired, or the store read or arena write fails; the key then stays on disk and the acquired slot is freed.

Source

pub fn remove(&mut self, key: u64)

2026-09-25: Forget key, freeing its arena slot or store record. A read pin on it stays until unpin_read.

Source

pub fn pin_read(&mut self, key: u64)

2026-09-25: Read-pin key so its slot is not an eviction victim while a client reads it. Counted per reader; the first pin takes the key out of lru. Does nothing unless key is resident.

Source

pub fn unpin_read(&mut self, key: u64)

2026-09-25: Release one pin taken by Residency::pin_read. After the last one, a key that is still resident rejoins lru as the hottest. Does nothing for a key with no pin.

Source

pub fn read_pin_count(&self, key: u64) -> u32

2026-09-25: The number of read-pins on key.

Source

pub fn put_blob(&mut self, key: u64, bytes: &[u8]) -> Result<()>

2026-09-25: Put in one call: Residency::alloc, copy bytes into the slot, Residency::commit.

§Errors

bytes is not blob_bytes long, alloc fails, or the arena write fails, after which key is removed.

Source

pub fn get_blob(&mut self, key: u64, out: &mut [u8]) -> Result<bool>

2026-09-25: Get in one call: Residency::locate, then copy the slot into out. Ok(false) for an unknown key.

§Errors

out is not blob_bytes long, or locate or the arena read fails.

Auto Trait Implementations§

§

impl<A, S> Freeze for Residency<A, S>
where A: Freeze, S: Freeze,

§

impl<A, S> RefUnwindSafe for Residency<A, S>

§

impl<A, S> Send for Residency<A, S>

§

impl<A, S> !Sync for Residency<A, S>

§

impl<A, S> Unpin for Residency<A, S>
where A: Unpin, S: Unpin,

§

impl<A, S> UnwindSafe for Residency<A, S>
where A: UnwindSafe, S: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,