Skip to main content

RadixCache

Struct RadixCache 

Source
pub struct RadixCache {
    pub page_pool: PagePool,
    pub evictable_leaves: FxHashSet<NodeId>,
    pub evictable_size: usize,
    pub protected_size: usize,
    /* private fields */
}
Expand description

Radix tree for SGLang KV cache simulation.

Fields§

§page_pool: PagePool§evictable_leaves: FxHashSet<NodeId>

Total token count in evictable nodes.

§evictable_size: usize§protected_size: usize

Total token count in protected (locked) nodes.

Implementations§

Source§

impl RadixCache

Source

pub fn new(total_tokens: usize, page_size: usize) -> Self

Source

pub fn root(&self) -> NodeId

Source

pub fn node(&self, id: NodeId) -> &TreeNode

Source

pub fn page_size(&self) -> usize

Source

pub fn num_nodes(&self) -> usize

Source

pub fn match_prefix(&mut self, key: &[u32]) -> (usize, NodeId)

Source

pub fn prefix_match_len(&self, key: &[u32]) -> usize

Read-only prefix match length (does not mutate timestamps or split nodes). Used for LPM scheduling scoring.

Source

pub fn insert(&mut self, key: &[u32], value: &[usize]) -> NodeId

Insert a token sequence into the tree. Key is page-aligned before insertion.

Source

pub fn insert_from_node( &mut self, prefix_node: NodeId, prefix_len: usize, key: &[u32], value: &[usize], ) -> NodeId

Insert only the suffix after a retained, page-aligned prefix.

prefix_node must be the locked terminal node for prefix_len. Keeping that handle lets decode growth avoid walking the full sequence from the root on every completed page.

Source

pub fn is_leaf(&self, id: NodeId) -> bool

Source

pub fn inc_lock_ref(&mut self, node_id: NodeId)

Source

pub fn dec_lock_ref(&mut self, node_id: NodeId)

Source

pub fn evict(&mut self, num_tokens: usize) -> (usize, Vec<KvPageId>)

Evict tokens from the cache by LRU order, rounding partial leaves to full pages. Returns (num_tokens_evicted, evicted_page_ids).

Source

pub fn available_tokens(&self) -> usize

Source

pub fn total_tokens(&self) -> usize

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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