From a82f1b388fe625038502eaa593690ed055fc4dd1 Mon Sep 17 00:00:00 2001 From: Agata Dobrzyniewicz <160237065+adobrzyn@users.noreply.github.com> Date: Sat, 25 Jul 2026 11:06:20 +0200 Subject: [PATCH] [Perf][V1] Skip LRU hash-split in free_blocks when prefix caching is off (#48017) Signed-off-by: Dobrzyniewicz, Agata Signed-off-by: Agata Dobrzyniewicz <160237065+adobrzyn@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 --- vllm/v1/core/block_pool.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vllm/v1/core/block_pool.py b/vllm/v1/core/block_pool.py index b42c7662d2..a64b7e3215 100644 --- a/vllm/v1/core/block_pool.py +++ b/vllm/v1/core/block_pool.py @@ -724,18 +724,20 @@ class BlockPool: ordered_blocks: A list of blocks to free ordered by their eviction priority. """ - # Identify blocks with hash (LRU cache) and without it (will never match in APC) + # Identify blocks with hash (LRU cache) and without it (never match APC) blocks_with_hash = [] blocks_without_hash = [] for block in ordered_blocks: block.ref_cnt -= 1 if block.ref_cnt == 0 and not block.is_null: - if block.block_hash is None: + # When caching is disabled we always append for better + # GPU cache locality from reusing recently used blocks + if block.block_hash is None and self.enable_caching: blocks_without_hash.append(block) else: blocks_with_hash.append(block) - # Blocks without hash always get evicted first - prepend them last to the tail + # Blocks without hash get evicted first - prepend them last to the tail self.free_block_queue.prepend_n(blocks_without_hash) self.free_block_queue.append_n(blocks_with_hash)