Skip to main content

Dsv4WindowPool

Struct Dsv4WindowPool 

Source
pub struct Dsv4WindowPool { /* private fields */ }
Expand description

The window tier’s page-atomic bookkeeping: which window page backs each full page, and which window pages are still free.

Token-faced on the outside (the generic cache manager speaks tokens), page-atomic inside. Window pages are bound 1:1 to full pages and the per-page state ring requires exactly that, so the page-completeness of every call is asserted here rather than assumed.

Implementations§

Source§

impl Dsv4WindowPool

Source

pub fn new(sizes: &Dsv4PoolSizes, max_running_req: usize, radix: bool) -> Self

Build the pool-owned free list and the tail dummy binding.

The last full page and the last window page are the reserved dummy region: the page table’s dummy row points at full_token - P, permanently bound, so graph-padded rows scatter to a real slot instead of a negative index. That page is bound outside the free list – the allocator’s capacity is n_win_slots - P – which is also what makes the usable window count swa_num_tokens - 1, the same capacity convention the generic pool gets from reserving slot 0.

Source

pub fn page_size(&self) -> usize

P: the window page, the sliding window, and the radix block key.

Source

pub fn swa_num_tokens(&self) -> usize

The window pool in the generic capacity convention: allocatable slots plus one. The dummy page is already excluded from the free list, so the +1 re-encodes the same capacity == tokens - 1 the generic pool gets from its slot-0 sentinel.

Source

pub fn swa_available_size(&self) -> usize

Window slots that can still be handed out.

Source

pub fn prefill_chunk_budget(&self) -> usize

The largest prefill chunk this pool can hold the window for.

Source

pub fn bind_window_pages( &mut self, full_page_base: usize, window_page_base: usize, )

Permanently bind one full page to one window page, offsets preserved.

§Panics

On a base that is not page-aligned: the ring block layout is keyed on the page base, so an unaligned binding aliases two pages onto one ring block.

Source

pub fn unbind_window_pages(&mut self, full_locs: &[i64])

Drop the binding of these full locs, returning nothing to the free list. Negative locs are ignored.

Source

pub fn alloc_swa( &mut self, full_indices: &[i64], ) -> Result<(), FreeListExhausted>

Bind one window page per incoming full page.

full_indices must be whole contiguous ascending pages – the page-to-token expansion the caller already performs. The in-page offsets are preserved (window_slot = wbase + pos % P), which is what the state ring’s page-block layout requires: a slot permuted inside its page still lands in the right ring block, but on the wrong slot of it.

All or nothing: the pages are allocated before the first mapping row is written, so an exhausted pool leaves the mapping untouched.

§Panics

On a partial, unaligned or non-ascending page. Upstream gets these from the page expansion by construction; asserted here, not assumed.

Source

pub fn free_swa(&mut self, full_indices: &[i64])

Return the window pages backing these full locs and unbind them.

Page-atomic: the locs must cover every touched page completely. Idempotent over pages that are already unbound – a slide, a tombstone and an eviction pass may all name the same page, and only the first hands its window page back.

§Panics

On a partially covered page. Freeing half a page would return a window page whose other half is still mapped, so the next allocation gets a page two full pages read through.

Source

pub fn translate(&self, full_loc: i64) -> i64

The window slot holding full_loc, or NO_WINDOW_SLOT.

A negative loc reads the permanent sentinel row and returns -1, so callers carrying “no such position” as -1 need no special case – upstream gets the same effect from negative tensor indexing into the trailing row.

Source

pub fn state_loc(window_slot: i64, ring_size: usize, page: usize) -> i64

The compress-state ring location for a window slot – derived, never stored.

(ws / P) * ring_size + ws % ring_size: the page picks the ring block, the in-page offset picks the slot inside it. ring_size divides P, so distinct window pages land on disjoint blocks.

Deriving it on every use is the whole safety property. A stored state_loc outlives the binding it was derived from: free a window page and the next request to take it inherits the same ring block, so a cached location reads another request’s carry state – no error, no fault, just wrong numbers.

§Panics

When ring_size does not divide page, which is what makes the blocks disjoint in the first place.

Source

pub fn window_ctx(&self, pos: usize, full_locs: &[i64]) -> Dsv4WindowCtx

The ring context for one decode step: this position’s slot, the previous position’s, and the whole P-slot ring.

full_locs is the request’s snapshot – full loc per position – read instead of the live mapping so a concurrent allocation cannot redirect an in-flight step. Computed fresh every call: caching it freezes a replay at the capture-time ring slots, -1 fills included.

Source

pub fn check_integrity(&self)

Every window page is either free or bound to exactly one full page, and every binding is page-atomic.

The count is an equality: free units plus bound pages is the capacity exactly. A <= would catch a double free and tolerate a leak, and a leaked window page is the failure that shows up an hour later as a pool that admits nothing.

Trait Implementations§

Source§

impl Clone for Dsv4WindowPool

Source§

fn clone(&self) -> Dsv4WindowPool

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Dsv4WindowPool

Source§

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

Formats the value using the given formatter. Read more

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.