kvbm-logical
Logical block lifecycle management for KVBM (KV Block Manager). Manages KV cache blocks for LLM inference through a type-safe state machine, registry, and pool system.
Block Lifecycle
Blocks follow a compile-time enforced state machine via the type-state pattern:
MutableBlock<T> → CompleteBlock<T> → ImmutableBlock<T> ⇄ WeakBlock<T>
(Reset) (Staged) (Registered) (Non-owning)
- MutableBlock — Allocated from the reset pool, writable. Drop returns to the reset pool.
- CompleteBlock — Staged with a
SequenceHashbut not yet registered. Drop returns to the reset pool. - ImmutableBlock — Registered in the block registry. Strong-ref prevents eviction. Drop moves to the inactive pool for caching.
- WeakBlock — Non-owning reference that does not prevent eviction. Upgradeable back to
ImmutableBlockvia two-phase lookup.
The type parameter T: BlockMetadata is a marker for the storage tier (e.g. GPU, CPU, disk).
Usage
use ;
#
Prometheus Metrics
All metrics carry a pool label identifying the storage tier.
Counters
| Name | Description |
|---|---|
kvbm_allocations_total |
Total blocks allocated from pools |
kvbm_allocations_from_reset_total |
Total blocks allocated from the reset pool |
kvbm_evictions_total |
Total blocks evicted from inactive pool |
kvbm_registrations_total |
Total blocks registered (CompleteBlock → ImmutableBlock) |
kvbm_duplicate_blocks_total |
Total duplicate blocks created (Allow policy) |
kvbm_registration_dedup_total |
Total block registrations deduplicated (Reject policy) |
kvbm_stagings_total |
Total MutableBlock → CompleteBlock transitions |
kvbm_match_hashes_requested_total |
Total hashes requested in match_blocks calls |
kvbm_match_blocks_returned_total |
Total blocks returned from match_blocks calls |
kvbm_scan_hashes_requested_total |
Total hashes requested in scan_matches calls |
kvbm_scan_blocks_returned_total |
Total blocks returned from scan_matches calls |
Gauges
| Name | Description |
|---|---|
kvbm_inflight_mutable |
Current MutableBlocks held outside pool |
kvbm_inflight_immutable |
Current ImmutableBlocks held outside pool |
kvbm_reset_pool_size |
Current reset pool size |
kvbm_inactive_pool_size |
Current inactive pool size |