[Bugfix][KV Offload] Track cache recency once per request (#51787)

Signed-off-by: mindungil <alswnsrlf12@naver.com>
Co-authored-by: Or Ozeri <oro@il.ibm.com>
This commit is contained in:
MINJUN GIL
2026-09-16 10:47:26 +03:00
committed by GitHub
co-authored by Or Ozeri
parent ab35354c21
commit f12fe10c5c
10 changed files with 916 additions and 169 deletions
@@ -40,6 +40,7 @@ from vllm.v1.kv_offload.base import (
TierMatcher,
make_offload_key,
)
from vllm.v1.kv_offload.cpu.policies.lru import LRUCachePolicy
from vllm.v1.kv_offload.tiering.base import (
JobResult,
SecondaryTierManager,
@@ -753,14 +754,64 @@ class TestTieringOffloadingManager:
# Touch chunks
self.manager.touch(chunks, _CTX)
# Verify touch was called on primary tier (check LRU order)
primary_keys = list(self.primary_tier._policy.evictable_chunks.keys())
assert primary_keys[-3:] == list(reversed(chunks))
# Verify touch was called on the primary tier (head is most recent).
policy = self.primary_tier._policy
assert isinstance(policy, LRUCachePolicy)
ranks = policy._ranks
assert ranks[chunks[2]] < ranks[chunks[1]] < ranks[chunks[0]]
# Verify touch was propagated to all secondary tiers
self.secondary_tier1.touch.assert_called_once_with(chunks, _CTX)
self.secondary_tier2.touch.assert_called_once_with(chunks, _CTX)
def test_request_order_survives_late_cascade_completion(self, manager_setup):
"""Cascade completion must not replace request order with I/O order."""
chunks = to_keys(range(5))
self._start_request()
output = self.manager.prepare_store(chunks, _CTX)
assert output is not None
self.manager.complete_store(chunks, _CTX, success=True)
# Finalize while both secondary-tier cascades still pin primary chunks.
self.manager.on_request_finished(_CTX)
self._simulate_on_schedule_end()
self._simulate_on_schedule_end()
evict_ctx = ReqContext(req_id="evict")
self._start_request(evict_ctx)
output = self.manager.prepare_store(to_keys([5]), evict_ctx)
assert output is not None
assert output.evicted_keys == [chunks[-1]]
def test_late_old_store_submission_does_not_override_newer_request_order(
self, manager_setup
):
"""Cascade submission after finish is not a new primary access."""
old_blocks = to_keys(range(2))
old_ctx = ReqContext(req_id="old")
self._start_request(old_ctx)
assert self.manager.prepare_store(old_blocks, old_ctx) is not None
self.manager.on_request_finished(old_ctx)
new_blocks = to_keys(range(2, 5))
new_ctx = ReqContext(req_id="new")
self._start_request(new_ctx)
assert self.manager.prepare_store(new_blocks, new_ctx) is not None
self.manager.complete_store(new_blocks, new_ctx, success=True)
self.manager.on_request_finished(new_ctx)
# The old GPU->primary write lands after the newer request finished.
# Its cascade pins must not turn it into the more recent request.
self.manager.complete_store(old_blocks, old_ctx, success=True)
self._simulate_on_schedule_end()
self._simulate_on_schedule_end()
evict_ctx = ReqContext(req_id="evict")
self._start_request(evict_ctx)
output = self.manager.prepare_store(to_keys([5]), evict_ctx)
assert output is not None
assert output.evicted_keys == [old_blocks[-1]]
def test_failed_store_no_cascade(self, manager_setup):
"""Test that failed GPU→primary store doesn't cascade."""
chunks = to_keys(range(3))
@@ -873,10 +924,10 @@ class TestTieringOffloadingManager:
job_metadata = self.secondary_tier1.submit_store.call_args.args[0]
assert job_metadata.req_context is ctx
def test_on_request_finished_delays_secondary_until_store_submitted(
def test_on_request_finished_delays_only_secondary_until_store_submitted(
self, manager_setup
):
"""Manager hook is eager; secondary hooks wait for cascade submission."""
"""Primary order commits immediately; secondary cleanup waits."""
chunks = to_keys(range(2))
ctx = ReqContext(req_id="req_delayed_secondary")
calls: list[tuple[str, str]] = []