Unit 4 of 11 · about 4 hours · implement
Free lists, reserve policies, block tables and append
Key-value append, gather, layout conversion and quantized loads supplied the write kernel. The allocator must now prove that each destination exists and has one writer before that kernel runs.
You'll be able to
- Implement a free-list allocator with sequence tables and transactional append.
- Derive additional page demand from committed length and scheduled writes.
- Choose a reserve policy that leaves explicit headroom for running requests.
Covers
Read
In this order, only the parts listed
0 of 2 done
- Nano-vLLM: free list, admission and appendNano-vLLM - Block Manager and Sequence Lifecycle
Block.reset,_allocate_block,_deallocate_block,can_allocate,allocate,can_appendandmay_appendTrace private allocation first. Keep manager and sequence block sizes consistent. Do not copy the append boundary predicate without tracing when the sampled token enters the sequence.
- Nano-vLLM: logical length versus computed stateNano-vLLM - Block Manager and Sequence Lifecycle
scheduleprefill/decode branches andpostprocess; follownum_cached_tokens,num_scheduled_tokensandappend_tokenDraw the memory transitions only. Leave scheduling policy comparisons for Batching, Scheduling and Admission.
Focus on
- For private append of KV tokens to committed length , extra pages are . Validate capacity before changing the committed table or length.
- Nano-vLLM records a sampled token before its KV is computed. Its decode boundary check uses that convention. A token list, computed-KV length and allocated capacity are three different quantities.
- Allocation failure must leave the state unchanged or follow a documented rollback. A successful write publishes the new valid length only after its KV is ready.
- Reserve is a policy, not missing memory. Keep a configurable number of pages outside new-request admission and state which operations may consume it; account for the next batch's growth before dispatch.
Common mistakes · 3
- Mutating length before checking free capacity. A rejected append can leave the valid length beyond allocated storage.
- Using one-token decode logic for a multi-token append. Chunked prefill can cross several boundaries in one operation.
- Counting reserve twice or silently consuming it. Separate hard capacity from each operation's admission policy.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.At committed KV length 5 with block size 4, how many extra pages does a three-token append require?Answer
None. It fills the existing second page to length 8. The following one-token append needs a third page.
2.Can allocation succeed even though the newly reserved slots have no valid KV yet?Answer
Yes. Capacity can be reserved before computation. Consumers must still use the committed valid length and readiness state.
3.What must a failed append preserve?Answer
The committed tokens, valid length, ownership, block table and free-list accounting, unless an explicit rollback contract specifies equivalent restored state.
You're done when
Private allocate, append and release pass boundary, exhaustion, duplicate-ID and rollback checks against a separate logical-length ledger.
Only when you can do this without notes.
Leads to
Notes
Resources · 1 for this unit, 13 more in the section
- Nano-vLLM - Block Manager and Sequence LifecycleGeeeekExplorer · required
Trace nanovllm/engine/block_manager.py, sequence.py, scheduler.py and attention.py. Draw allocate, append, share, preempt and free transitions, then implement randomized allocator tests in your own project before touching production-engine code.
Also in this section
- Efficient Memory Management for Large Language Model Serving with PagedAttentionvLLM Project · primary
Read the memory-waste motivation, block-table design, sharing and copy-on-write sections, then reproduce the logical-to-physical translation on paper. Separate the paper's reported workloads from results on your engine and hardware.
- SGLang: Efficient Execution of Structured Language Model ProgramsSGLang Project · required
Study RadixAttention, longest-prefix matching, eviction and cache-aware scheduling. Compare its sequence-level radix index with vLLM's block-level paging instead of treating them as competing names for one mechanism.
- Hands-On LLM Serving and Optimization - Prefix Caching and Advanced KV CachingChi Wang and Peiheng Hu (O'Reilly) · required
Read "Prefix Caching" in Chapter 6 (RadixAttention, use cases, best practices, scaling the prefix cache) and "Advanced KV Caching" in Chapter 7 (long context, cost and latency, LMCache). Separate exact-reuse mechanisms from capacity extensions such as offload.
- AI Systems Performance Engineering - Chapter 18, tuning KV-cache utilizationChris Fregly (O'Reilly) · support
Read "Tuning KV Cache Utilization and Management" in Chapter 18 and "Prefix Caching" in Chapter 16. Leave the disaggregated pool and transfer sections for INF-7.
- Mini-SGLang - Radix Cache and Cache TestsSGLang Project · required
Read docs/structures.md, the cache allocation code and tests/core/test_cache_allocate.py. Compare exact prefix identity and lifecycle with Nano-vLLM, then add tenant and version fields to your own prefix index.
- vLLM Automatic Prefix Caching DesignvLLM Project · required
Check block hashing, extra hash keys (multimodal inputs, LoRA, cache salt), isolation and eviction against v0.31.0, the version pinned here; cache-key fields change between releases.
- SGLang documentation - Radix cache eviction and HiCacheSGLang Project · support
Use the radix eviction policy and session radix cache pages to compare eviction choices with vLLM, and the HiCache design page for a GPU, host and storage hierarchy.
- AI Performance Engineering - KV Cache SystemsWafer · reference
A curated index. Use Section 4 only to find a primary KV-cache source the other entries lack.
- 100 Days of LLM Inference - Days 5, 9, 10 and 16Elizabeth Thomas · support
Use the four notebooks for KV arithmetic, paged allocation, radix reuse and prompt-layout experiments. Re-run conclusions against your own property tests and workload because these notebooks are a supplementary learning journal.
- TensorTonic Language Modeling from Scratch - Find Reusable Prefixes in a KV TrieTensorTonic · support
Solve after the prefix-index unit and add the cases its public tests leave out to your own property tests.
- LLM Inference: From scratch, one token at a time - Modules 02 and 06Tushar Amrit · support
Use The KV Cache for fragmentation and reuse and Memory Optimization for paging, prefix sharing and KV compression. Work the checkpoints before the matching units.
- LLM Inference Systems Laboratory - KV StateRoadmap-Final · support
Implement the paged allocator and prefix index with differential, randomized, cancellation, collision, fork and pressure tests. Retain one reuse workload that improves hit rate but not goodput.
- vLLM 0.31.0 - cache specifications and connector lifecyclevLLM Project · reference
Read the per-layer attention, MLA and Mamba specifications for hybrid state contracts; read the V1 connector metadata, load synchronization and deferred-free methods for transfer ownership. These fill the pool's hybrid-state and connector-contract gaps, without requiring distributed execution.