Files
vLLM/vllm/v1
MOVZXandHinata 633c758d4c [Scheduler] Pin a waiting request's prefix-cache hit until it is admitted
A follow-up turn that waits for admission holds no reference on its
cached prefix. With a prefix unit finer than the block, its whole hit
depends on every one of those blocks: the resume key sits in the top
attention block, and the only GDN state is the held tail. So the first
of them that another request's allocation popped from the free queue
turned the next turn into a cold prefill; that was usually its own top
block, which is freed first. Under a long-context multi-turn agent load
(8 conversations, 80-100K-token prompts) this gave 4-5 total misses per
300 s at unit 64/512 and none at unit 4096. All of them happened while
the pool was at 88-99 % with one or two conversations waiting, and the
conversation that missed was usually the next victim too.

Now the manager can pin a waiter's hit:

- pin_waiting_hit looks the request up and takes a ref on every
  non-null hit block in every group. It also pins the block holding the
  EAGLE/MTP proof unit: one unit past the key, dropped from the returned
  hit, and a different block when the key ends a block. The pinned
  blocks stay out of the free queue.
- release_pinned_hit drops a pin; yield_pinned_hits drops the most
  recently pinned waiters' first.
- allocate_slots releases the request's pin when it succeeds (its table
  holds the hit from then on), free releases it (abort, finish), and
  reset_prefix_cache yields every pin before resetting.

Pinned blocks are referenced, so admission and the watermark see them
as used.

The scheduler pins the front of the waiting queue after each scheduling
pass: arrival order, at most MAX_PINNED_WAITERS = 8, only requests that
have not computed anything yet, never with a KV connector. It does this
also while the running set is full, when a waiter is not even looked
up. A pin never costs anyone blocks. A running request that fails to
allocate yields one waiter's pin and retries before any preemption
victim is chosen. A head-of-line waiter whose admission fails yields the
pins of the waiters behind it and retries once. When pins are active
the scheduler logs one startup line saying so, with the bound, the hash
unit and the block size.

On a closed-loop CPU model of that load (6-8 conversations, 1-2
waiting, pool 88-100 %), total misses went from 3/1/1/5 to 2/0/0/0 with
every waiter pinned. The remaining two sit at 99.2 % use, where the
running set needed the pinned blocks themselves (two yields, 65
blocks). Unit 4096 is unaffected except where a waiter was losing its
boundary block.

Tests:
- A pinned waiter survives another follow-up's admission and a burst,
  and resumes at its tail (a total miss without the pin).
- Pool full and a running request needs a block: the pin yields, nobody
  is preempted, and the waiter is still admitted later.
- Pins are released on abort, admission, yield and reset without
  leaks; the bound is respected; yield order is newest first.
- The scheduler's pass pins in arrival order up to the bound and skips
  partly computed requests and connector setups.

Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
2026-10-09 20:16:37 +07:00
..