Skip to content

feat: paged KV block-budget admission gate and eviction - #175

Merged
inureyes merged 1 commit into
mainfrom
feat/122-block-budget-admission
Jun 7, 2026
Merged

inureyes merged 1 commit into
mainfrom
feat/122-block-budget-admission

Conversation

@inureyes

@inureyes inureyes commented Jun 7, 2026

Copy link
Copy Markdown
Member

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_budget is None), so default behaviour is unchanged and the per-prefill gate is one branch on the hot path.

Changes

  • CachePool 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 − live (blocks acquirable: a fresh acquire reuses a freed block or mints a new one while live < 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.
  • BatchScheduler gates each prefill (admit_paged_prefill in execute_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 (existing try_evict_for_preemption) — and admit if room was made, else re-queue for a later tick.

Tests

6 new: free = budget − live after a free, budget surviving lazy pool creation, evict_one_lru dropping + queuing pins, cold-prefix eviction restoring the budget, plus the b1 cap tests. 28 paged_detach + 21 scheduler_prompt_cache + 181 server::batch pass.

Testing note: BatchScheduler is pub(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 --check clean; core regression + 181 server::batch + 21 scheduler_prompt_cache green.

Scope

This is the enforcement mechanism. Activation — deriving the budget from a config knob and --estimate-memory (now accurate via #52) and calling set_paged_block_budget in the worker setup — is the next sub-step (b3). Until then the gate is dormant (budget None).

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.
@inureyes inureyes added the type:enhancement New features, capabilities, or significant additions label Jun 7, 2026
@inureyes
inureyes merged commit 58f1a6c into main Jun 7, 2026
4 checks passed
@inureyes
inureyes deleted the feat/122-block-budget-admission branch June 7, 2026 12:24
@inureyes inureyes self-assigned this Jun 10, 2026
@inureyes inureyes added status:done Completed priority:medium Medium priority labels Jun 10, 2026
@inureyes inureyes added this to the 0.2 milestone Jun 21, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant