Repository navigation
feat: paged KV block-budget admission gate and eviction - #175
Merged
Merged
Conversation
Sub-step b2 of #122 — the admission + eviction mechanism that enforces the b1 block budget. Opt-in: a no-op until a budget is configured (free_paged_block_budget is None), so default behaviour is unchanged and the per-prefill gate adds one branch on the hot path. CachePool now stores the configured budget and applies it when the paged pool is lazily created, so set_paged_block_budget before the first paged allocation sticks; paged_block_budget() returns the stored intent. free_block_budget is redefined as budget minus LIVE blocks (blocks acquirable: a fresh acquire reuses a freed block or mints a new one while live < budget), so eviction/preemption that drops refcounts raises the figure even though allocated rows are retained for reuse. PromptCacheStore gains evict_one_lru(): drop the single LRU entry on demand, routing its paged pins to the pending-release queue so the caller frees the blocks. BatchScheduler gates each prefill in execute_prefill (admit_paged_prefill): estimate the prompt's block need (ceil(prompt/block_size) times num_layers); admit if it fits; reject if it exceeds the whole budget; otherwise reclaim — evict cold prompt-cache prefixes (releasing their pins), then preempt running sequences — and admit if room was made, else re-queue for a later tick. Adds 6 tests: free=budget-live after a free, the budget surviving lazy pool creation, evict_one_lru dropping and queuing pins, cold-prefix eviction restoring the budget, plus the cap tests. The scheduler-loop integration follows the file's existing approach — BatchScheduler is pub(crate) and not constructed in tests, so its decision policy is mirrored and its primitives unit-tested. Activation (deriving the budget from a config knob and --estimate-memory) is the next sub-step.
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
Sub-step b2 of lablup#122 — the admission + eviction mechanism that enforces the b1 block budget. Opt-in: a no-op until a budget is configured (free_paged_block_budget is None), so default behaviour is unchanged and the per-prefill gate adds one branch on the hot path. CachePool now stores the configured budget and applies it when the paged pool is lazily created, so set_paged_block_budget before the first paged allocation sticks; paged_block_budget() returns the stored intent. free_block_budget is redefined as budget minus LIVE blocks (blocks acquirable: a fresh acquire reuses a freed block or mints a new one while live < budget), so eviction/preemption that drops refcounts raises the figure even though allocated rows are retained for reuse. PromptCacheStore gains evict_one_lru(): drop the single LRU entry on demand, routing its paged pins to the pending-release queue so the caller frees the blocks. BatchScheduler gates each prefill in execute_prefill (admit_paged_prefill): estimate the prompt's block need (ceil(prompt/block_size) times num_layers); admit if it fits; reject if it exceeds the whole budget; otherwise reclaim — evict cold prompt-cache prefixes (releasing their pins), then preempt running sequences — and admit if room was made, else re-queue for a later tick. Adds 6 tests: free=budget-live after a free, the budget surviving lazy pool creation, evict_one_lru dropping and queuing pins, cold-prefix eviction restoring the budget, plus the cap tests. The scheduler-loop integration follows the file's existing approach — BatchScheduler is pub(crate) and not constructed in tests, so its decision policy is mirrored and its primitives unit-tested. Activation (deriving the budget from a config knob and --estimate-memory) is the next sub-step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sub-step b2 of #122 — the admission + eviction mechanism that enforces the b1 (#174) block budget. Part of #122. Opt-in: a no-op until a budget is configured (
free_paged_block_budgetisNone), so default behaviour is unchanged and the per-prefill gate is one branch on the hot path.Changes
CachePoolstores the configured budget and applies it when the paged pool is lazily created (soset_paged_block_budgetbefore the first paged allocation sticks);paged_block_budget()returns the stored intent.free_block_budgetis redefined asbudget − live(blocks acquirable: a freshacquirereuses a freed block or mints a new one whilelive < budget), so eviction/preemption that drops refcounts raises it even though allocated rows are retained for reuse.PromptCacheStore::evict_one_lru()— drop the single LRU entry on demand, routing its paged pins to the pending-release queue so the caller frees the blocks.BatchSchedulergates each prefill (admit_paged_prefillinexecute_prefill): estimate the prompt's block need (ceil(prompt/block_size) × num_layers); admit if it fits; reject if it exceeds the whole budget; otherwise reclaim — evict cold prompt-cache prefixes (releasing pins), then preempt running sequences (existingtry_evict_for_preemption) — and admit if room was made, else re-queue for a later tick.Tests
6 new:
free = budget − liveafter a free, budget surviving lazy pool creation,evict_one_lrudropping + queuing pins, cold-prefix eviction restoring the budget, plus the b1 cap tests. 28paged_detach+ 21scheduler_prompt_cache+ 181server::batchpass.Testing note:
BatchSchedulerispub(crate)and not constructed in tests (the file mirrors its decision policy and unit-tests its primitives instead — the codebase's existing approach). The gate's building blocks are covered directly; the eviction tier-1 (cold-prefix → budget reclaimed) has an end-to-end CachePool+store test.Validation
Cold
cargo clippy --tests(both crates) clean;cargo fmt --checkclean; core regression + 181server::batch+ 21scheduler_prompt_cachegreen.Scope
This is the enforcement mechanism. Activation — deriving the budget from a config knob and
--estimate-memory(now accurate via #52) and callingset_paged_block_budgetin the worker setup — is the next sub-step (b3). Until then the gate is dormant (budgetNone).