Split SWA leaf to one window on insert (#26919)

This commit is contained in:
Ke Bao
2026-06-01 23:46:55 +08:00
committed by GitHub
parent d8a5a25c36
commit f59bbef841
2 changed files with 108 additions and 29 deletions
@@ -261,6 +261,32 @@ class SWAComponent(TreeComponent):
node.component_data[self.component_type].value = swa_value
self.cache.lru_lists[self.component_type].insert_mru(node)
self.cache.component_evictable_size_[self.component_type] += len(swa_value)
else:
# Entire leaf is outside the SWA window — left as a tombstone.
return
self._maybe_split_leaf_for_swa_lock(node)
def _maybe_split_leaf_for_swa_lock(self, leaf: UnifiedTreeNode) -> None:
"""Cap a fresh SWA leaf at one page-aligned window so locking it pins
only one window of SWA pool, not the whole (long chunked-prefill) leaf.
"""
ct = self.component_type
cd = leaf.component_data[ct]
if leaf is self.cache.root_node or cd.value is None or cd.lock_ref > 0:
return
page_size = self.cache.page_size
# Smallest page-aligned size that still covers the sliding window.
tail_size = (self.sliding_window_size + page_size - 1) // page_size * page_size
leaf_len = len(leaf.key)
if leaf_len <= tail_size:
return
split_at = leaf_len - tail_size
if page_size > 1 and (split_at % page_size != 0 or leaf_len % page_size != 0):
return
self.cache._split_node(leaf.key, leaf, split_at)
def redistribute_on_node_split(
self, new_parent: UnifiedTreeNode, child: UnifiedTreeNode