dsa_capacity

Function dsa_capacity 

Source
pub fn dsa_capacity(max_context: usize, index_kpool: usize) -> usize
Expand description

THE authoritative indexer-capacity computation. Everything that needs to know how many rows a sequence’s indexer cache holds calls this — max_dsa_context for the allocation side, and the serve’s pre-model reserve for the budget side.

🔴 It exists because there were two spellings. The allocation rounds down to whole pools; the budget (Glm5NextTextSkeleton::state_budget) is expressed per TOKEN, so multiplying it by a raw --max-seq-len charges a capacity the allocation never reserves. They agree for every index_kpool-multiple context — GLM-5.3 ships index_kpool = 4, so every power-of-two --max-seq-len masks it — and disagree by up to index_kpool - 1 rows a layer otherwise. One function, so a config that does not divide evenly cannot make them drift.

Whole pools only: a trailing partial pool is not a pool (contiguous_pool_count). index_kpool == 0 is refused by Glm5NextDsaConfig::validate; clamped here so this stays total for callers that have not validated yet (the reserve runs before the model exists).