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

Free lists, allocation and reserve policiesSequence block tables and append semantics
1

Read

In this order, only the parts listed

0 of 2 done

  1. Nano-vLLM: free list, admission and appendNano-vLLM - Block Manager and Sequence Lifecycle

    Block.reset, _allocate_block, _deallocate_block, can_allocate, allocate, can_append and may_append

    Trace 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.

  2. Nano-vLLM: logical length versus computed stateNano-vLLM - Block Manager and Sequence Lifecycle

    schedule prefill/decode branches and postprocess; follow num_cached_tokens, num_scheduled_tokens and append_token

    Draw the memory transitions only. Leave scheduling policy comparisons for Batching, Scheduling and Admission.

2

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.
3

Try it yourself

Closed-book, before checking anything

Implement a CPU private-page allocator from memory. With four pages of four slots and one page reserved from new-request admission, admit a five-token request, append three KV tokens without a new page, then append one with a new page. A further five-token append needs one more page: deny it if this append may not consume reserve, and verify unchanged length 9, table and free list. Release the request and recover all four pages. State your empty-request and duplicate-ID policies.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 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. 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. 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