Repository navigation
fix(core): evict prefix chain tails so leading pages stay reusable - #217
Open
HowardYangAI wants to merge 1 commit into
Open
HowardYangAI wants to merge 1 commit into
HowardYangAI wants to merge 1 commit into
Conversation
Prefix keys are chained: a page's key is computed from every page before it, so a lookup walks from the first page and stops at the first gap. Eviction picked the least recently used entry, and the first page is the one published earliest, so it went first and left every page behind it cached but impossible to find. Each entry now records which page comes before it and how many follow, and eviction takes the entry that has gone unused the longest with nothing chained after it. Tails are queued by their own use time, so a hit refreshes the pages it reached and eviction no longer rescans the cache for every page it drops. Queued records that a later hit or a new successor replaces are pruned once they outnumber the cache. Caching a 35-token prompt and letting a second prompt fill the cache, a re-request reused nothing before and now reuses 6, 16 and 32 tokens in 90-, 110- and 140-page pools.
HowardYangAI
force-pushed
the
fix/prefix-chain-eviction-order
branch
from
November 24, 2026 15:10
f32f6d2 to
24624ad
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Required human contributor answers
1. What outcome are you trying to achieve?
Once the cache fills up, the shared part of a prompt should still be usable, instead of having to compute it again while its pages are still cached.
2. What is the highest-leverage variable for that outcome?
Which page eviction drops. Drop a chain's first page and nothing behind it can be found; drop the last one and the pages before it still work.
3. How will this work move that variable rather than create busywork?
Eviction now drops the page that has gone unused the longest and has nothing chained after it, which is a chain's last page. That page is the least useful one at the time, so the same pool saves more repeated work.
4. Who is the customer or user, and what do they actually need?
Anyone running with
enable_prefix_caching=True. When several requests share a long prompt, they need that shared part to still be usable once the pool is busy, which is when skipping the work matters most.PR necessity and bugfix evidence
A PR is needed: the chaining and the eviction order both live in
KVCacheManager, so no configuration avoids this. Reported and reproduced in #216: with 90 cached pages, 20 entries survive eviction and the prompt that published them reuses 0 tokens. Reproduced locally on CPU, and each case below has a regression test.Purpose
Prefix keys are chained: a page's key is computed from every page before it, so a lookup walks from the first page and stops at the first gap. Eviction picked the least recently used entry, and the first page is the one published earliest, so it went first and left every page behind it cached but impossible to find.
vLLM gets the same order without this bookkeeping: a request frees its blocks last page first, so a chain's tail joins the free queue ahead of its head. Our prefix table is filled when a prefill publishes pages and is not tied to when a request finishes, so there is no free step to order, and this PR tracks the tails directly.
Addresses #216.
Test Plan
pre-commit run --all-files(Ruff lint, Ruff format and CPU regressions) and the full CPU suite.vllm-rlt Version / Commit: main
4821d47, head24624ad.Test Result
Reproducer from #216, re-requesting a 35-token prompt after a second prompt forced eviction:
The same entries stay cached either way; the difference is whether they can be found.
Six regression tests in
tests/test_prefix_growth.pycover eviction taking tails, a hit's first page outliving its own tail, a hit chain outliving a newer one, repeated hits not growing the queue, draining a long chain without rescanning, and the engine-level re-request. Each one fails if the ordering it checks is reverted.The unrelated GPU failures, all of which fail the same way on
4821d47:test_prefix_growth.py; the pinned flash-attn-4 release does not support SM89.test_pd_prefix_reuse_reduces_transfers_and_preserves_outputscases, which fail with a stage worker error on this host.