[Perf][V1] Skip LRU hash-split in free_blocks when prefix caching is off (#48017)

Signed-off-by: Dobrzyniewicz, Agata <agata.dobrzyniewicz@intel.com> Signed-off-by: Agata Dobrzyniewicz <160237065+adobrzyn@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

Agata Dobrzyniewicz committed Jul 25, 2026 at 11:06 UTC a82f1b388fe625038502eaa593690ed055fc4dd1
1 file changed +5 -3
vllm/v1/core/block_pool.py
+5 -3
@@ -724,18 +724,20 @@ class BlockPool:
724 ordered_blocks: A list of blocks to free ordered by their eviction
725 priority.
726 """
727 - # Identify blocks with hash (LRU cache) and without it (will never match in APC)
727 + # Identify blocks with hash (LRU cache) and without it (never match APC)
728 blocks_with_hash = []
729 blocks_without_hash = []
730 for block in ordered_blocks:
731 block.ref_cnt -= 1
732 if block.ref_cnt == 0 and not block.is_null:
733 - if block.block_hash is None:
733 + # When caching is disabled we always append for better
734 + # GPU cache locality from reusing recently used blocks
735 + if block.block_hash is None and self.enable_caching:
736 blocks_without_hash.append(block)
737 else:
738 blocks_with_hash.append(block)
739
738 - # Blocks without hash always get evicted first - prepend them last to the tail
740 + # Blocks without hash get evicted first - prepend them last to the tail
741 self.free_block_queue.prepend_n(blocks_without_hash)
742 self.free_block_queue.append_n(blocks_with_hash)
743