pub struct PagePool { /* private fields */ }Expand description
Manages free / allocated pages for the simulated SGLang KV cache.
SGLang’s paged allocator owns and frees whole pages even though its public interface returns flattened token indices. This pool preserves that ownership model and only expands page IDs while a request is active.
Implementations§
Source§impl PagePool
impl PagePool
pub fn new(total_tokens: usize, page_size: usize) -> Self
pub fn allocate_pages(&mut self, count: usize) -> Option<Vec<KvPageId>>
Sourcepub fn allocate_indices_into(
&mut self,
new_tokens: usize,
indices: &mut Vec<usize>,
) -> bool
pub fn allocate_indices_into( &mut self, new_tokens: usize, indices: &mut Vec<usize>, ) -> bool
Append flattened indices for new_tokens, allocating whole pages only
when the request’s current final page has no remaining slots.
pub fn expand_pages(&self, pages: &[KvPageId], token_count: usize) -> Vec<usize>
pub fn free_pages(&mut self, pages: &[KvPageId])
Sourcepub fn free_indices(&mut self, indices: &[usize]) -> Vec<KvPageId>
pub fn free_indices(&mut self, indices: &[usize]) -> Vec<KvPageId>
Free every distinct page represented by a contiguous request-index list.
pub fn available_pages(&self) -> usize
pub fn available(&self) -> usize
pub fn total(&self) -> usize
Auto Trait Implementations§
impl Freeze for PagePool
impl RefUnwindSafe for PagePool
impl Send for PagePool
impl Sync for PagePool
impl Unpin for PagePool
impl UnsafeUnpin for PagePool
impl UnwindSafe for PagePool
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
Mutably borrows from an owned value. Read more