Skip to main content

Interview Lab

Can this request start with only two free pages?

A new request needs three KV-cache pages and has no prefix hit. The cache has two empty pages, five pages in use, and one page holding a cached prefix. Assume the cached page can be evicted if no active request uses it, and the scheduler does not preempt active requests.

Can the new request start if the cached page is unused? What changes if an active request still references it?

Animated solution

KV-cache pages at admission

The cached prefix is unused

2 free / 3 needed

  1. 1Active
  2. 2Active
  3. 3Active
  4. 4Active
  5. 5Active
  6. 6Cached prefix
  7. 7Free
  8. 8Free

An active request holds the prefix

2 free / 3 needed

  1. 1Active
  2. 2Active
  3. 3Active
  4. 4Active
  5. 5Active
  6. 6Active prefix
  7. 7Free
  8. 8Free

A new request needs three pages.

Both caches have two empty pages. The third page depends on whether an existing entry is still in use.

Worked solution

Admit if the cached page is unused. Reclaim its physical page and combine it with the two empty ones. The scheduler now has all three pages. Evicting the prefix gives up a possible future cache hit.

Queue if an active request still uses it. The cache still has only two allocatable pages. The new request has to wait until another page becomes available.

An unused cached block can retain its contents until allocation needs the space. Engines such as vLLM keep zero-reference blocks eligible for reuse or eviction. vLLM prefix-cache design