[Perf][KV Offload] Avoid quadratic ARC batch eviction - #50992
Conversation
Signed-off-by: MINJUN GIL <alswnsrlf12@naver.com>
Signed-off-by: MINJUN GIL <alswnsrlf12@naver.com> Assisted-by: Codex
7e3c0a1 to
6bdb52c
Compare
orozery
left a comment
There was a problem hiding this comment.
Thanks @mindungil !
Can you please add a test to cover for this:
Missing test coverage: the case where virtual_t1_size >= target_t1_size for the entire batch but T1's eligible entries run out mid-way (all remaining are protected/pinned), forcing repeated fallback to T2 with an exhausted T1 iterator. That's the path where the old re-scan and the new exhausted-iterator-returns-None differ most in mechanism.
Assisted-by: Codex Signed-off-by: MINJUN GIL <alswnsrlf12@naver.com>
|
Thanks for pointing this out. Added The test keeps Validation:
|
Purpose
ARC batch eviction repeatedly scans its internal cache lists from the beginning for each block selected. As a result, evicting many blocks can require quadratic work.
Fix
Keep monotonic iterators over those lists while collecting candidates, so each entry is visited at most once. Cache mutations remain deferred until all requested candidates are found, preserving atomic eviction.
This also preserves eviction order and protected/pinned block handling.
Performance
Manager-level microbenchmark with a full ARC cache, replacing half of its blocks (median of 3 runs, AMD EPYC 9355, Python 3.12.3):
This measures CPU eviction bookkeeping, not end-to-end serving throughput.
Related work
ARC was introduced in #27039, and #37874 later made eviction atomic by collecting all candidates before modifying cache state. This PR preserves that behavior while avoiding repeated scans during batch eviction.
#45757 skips eviction when failure can be determined in advance; this PR optimizes successful ARC eviction after that check passes.
No open PR was found for the same repeated-scan issue. #50422 changes the eviction interface but not ARC candidate selection.
Test Plan
Test Result
The regression tests verify single-pass scanning, repeated T2 fallback after the T1 iterator is exhausted while its virtual size remains above the target, and atomic failure.
Model evaluation: N/A. This changes CPU cache bookkeeping only and does not affect model output.
AI assistance
This PR includes AI-assisted code and analysis from OpenAI Codex. I reviewed the changes and take responsibility for the contribution.
Essential Elements of an Effective PR Description Checklist