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
impl Dsv4WindowPool
Sourcepub fn new(sizes: &Dsv4PoolSizes, max_running_req: usize, radix: bool) -> Self
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.
Sourcepub fn page_size(&self) -> usize
pub fn page_size(&self) -> usize
P: the window page, the sliding window, and the radix block key.
Sourcepub fn swa_num_tokens(&self) -> usize
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.
Sourcepub fn swa_available_size(&self) -> usize
pub fn swa_available_size(&self) -> usize
Window slots that can still be handed out.
Sourcepub fn prefill_chunk_budget(&self) -> usize
pub fn prefill_chunk_budget(&self) -> usize
The largest prefill chunk this pool can hold the window for.
Sourcepub fn bind_window_pages(
&mut self,
full_page_base: usize,
window_page_base: usize,
)
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.
Sourcepub fn unbind_window_pages(&mut self, full_locs: &[i64])
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.
Sourcepub fn alloc_swa(
&mut self,
full_indices: &[i64],
) -> Result<(), FreeListExhausted>
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.
Sourcepub fn free_swa(&mut self, full_indices: &[i64])
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.
Sourcepub fn translate(&self, full_loc: i64) -> i64
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.
Sourcepub fn state_loc(window_slot: i64, ring_size: usize, page: usize) -> i64
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.
Sourcepub fn window_ctx(&self, pos: usize, full_locs: &[i64]) -> Dsv4WindowCtx
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.
Sourcepub fn check_integrity(&self)
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
impl Clone for Dsv4WindowPool
Source§fn clone(&self) -> Dsv4WindowPool
fn clone(&self) -> Dsv4WindowPool
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Dsv4WindowPool
impl RefUnwindSafe for Dsv4WindowPool
impl Send for Dsv4WindowPool
impl Sync for Dsv4WindowPool
impl Unpin for Dsv4WindowPool
impl UnsafeUnpin for Dsv4WindowPool
impl UnwindSafe for Dsv4WindowPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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