[Core] Clearer comments in `BlockPool.free_blocks()` (#52076)
Signed-off-by: Nick Hill <nickhill123@gmail.com>
Nick Hill committed
Aug 12, 2026 at 20:36 UTC
f9538af28c99513ce580948eb107195f5ae0c4ca
1 file changed
+10
-9
vllm/v1/core/block_pool.py
+10
-9
@@ -725,21 +725,22 @@ class BlockPool:
725
priority.
726
"""
727
# Identify blocks with hash (LRU cache) and without it (never match APC)
728
- blocks_with_hash = []
729
- blocks_without_hash = []
728
+ blocks_to_evict_last = []
729
+ blocks_to_evict_first = []
730
for block in ordered_blocks:
731
block.ref_cnt -= 1
732
if block.ref_cnt == 0 and not block.is_null:
733
- # When caching is disabled we always append for better
734
- # GPU cache locality from reusing recently used blocks
733
if block.block_hash is None or not self.enable_caching:
736
- blocks_without_hash.append(block)
734
+ # LIFO reuse of non-cached blocks for better GPU locality.
735
+ blocks_to_evict_first.append(block)
736
else:
738
- blocks_with_hash.append(block)
737
+ # FIFO reuse of cached blocks for LRU eviction behavior.
738
+ blocks_to_evict_last.append(block)
739
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)
740
+ # Blocks to reuse first are prepended to the front of the free queue.
741
+ self.free_block_queue.prepend_n(blocks_to_evict_first)
742
+ # Blocks to reuse last are appended to the end of the free queue.
743
+ self.free_block_queue.append_n(blocks_to_evict_last)
744
745
def evict_blocks(self, block_ids: set[int]) -> None:
746
"""evict blocks from the prefix cache by their block IDs.