[HiCache] buffer mode: anchor-lock staged prefetches by default (#37464)

This commit is contained in:
Zhiqiang Xie
2026-09-03 12:08:22 -07:00
committed by GitHub
parent 68978f8d52
commit d0c95f6c91
3 changed files with 8 additions and 17 deletions
+7 -3
View File
@@ -723,9 +723,9 @@ class Envs:
SGLANG_HICACHE_FILE_BACKEND_ENABLE_METADATA_CACHE = EnvBool(False)
# Positive cache TTL for filesystem metadata lookups (-1 disables positive expiration)
SGLANG_HICACHE_FILE_BACKEND_METADATA_TTL = EnvFloat(5.0)
# Buffer mode: pin a staged prefetch's device anchor from IO commit to
# consumption so eviction cannot waste the fetch; cap = fraction of pool.
SGLANG_ENABLE_HICACHE_BUFFER_ANCHOR_LOCK = EnvBool(False)
# Buffer mode: staged prefetches pin their device anchor from IO commit
# to consumption so eviction cannot waste the fetch. Cap = fraction of
# the pool the pins may hold; 0 disables pinning.
SGLANG_HICACHE_BUFFER_ANCHOR_LOCK_CAP = EnvFloat(0.5)
SGLANG_HICACHE_NIXL_BACKEND_STORAGE_DIR = EnvStr(None)
# Enable O_DIRECT when opening NIXL POSIX backend files (bypasses OS page cache).
@@ -1765,6 +1765,10 @@ _DEPRECATED_ENVS: Dict[str, _DeprecatedEnv] = {
"SGLANG_FLASHINFER_PR4266_SOURCE": _DeprecatedEnv(),
# DSV4 compressor V2 is always used.
"SGLANG_OPT_USE_COMPRESSOR_V2": _DeprecatedEnv(),
"SGLANG_ENABLE_HICACHE_BUFFER_ANCHOR_LOCK": _DeprecatedEnv(
note="Buffer-mode anchor pinning is always on; set "
"SGLANG_HICACHE_BUFFER_ANCHOR_LOCK_CAP=0 to disable it."
),
# Replaced by CLI flags.
"SGLANG_ENABLE_GRPC": _DeprecatedEnv(
note="Please use '--grpc-port' to enable the native gRPC server."
@@ -222,8 +222,6 @@ class BufferModePipeline:
# Metadata-only pending-write backlog cap; beyond it new intents
# are dropped at admission (re-trigger on a later hit).
self.write_backlog_cap = write_backlog_cap
# Anchor-lock knobs; the cap keeps queued holds from pinning the pool.
self.anchor_lock_enabled = envs.SGLANG_ENABLE_HICACHE_BUFFER_ANCHOR_LOCK.get()
from sglang.srt.mem_cache.swa_memory_pool import SWAKVPool
kvcache = cache.token_to_kv_pool_allocator.get_kvcache()
@@ -239,8 +237,7 @@ class BufferModePipeline:
),
)
logger.info(
"BufferModePipeline anchor_lock_enabled=%s cap_tokens=%d",
self.anchor_lock_enabled,
"BufferModePipeline anchor_lock_cap_tokens=%d",
self.anchor_lock_cap_tokens,
)
self.reset()
@@ -690,8 +687,6 @@ class BufferModePipeline:
O(prefix path)). Returns "locked", "no_anchor" (nothing to pin),
"cap_skip" (over cap; launches unlocked), or "anchor_lost" (splice
base gone — the caller cancels the storage IO)."""
if not self.anchor_lock_enabled:
return "no_anchor"
if req_id in self.anchor_locks:
return "locked"
prefix_ctx = self._prefetch_prefix_ctx.get(req_id)
@@ -966,7 +966,6 @@ class TestUnifiedRadixCacheEagleHiCacheStorageKey(CustomTestCase):
)
pipeline = BufferModePipeline.__new__(BufferModePipeline)
pipeline.anchor_lock_enabled = True
pipeline.anchor_locks = {}
pipeline.anchor_locked_tokens_ = 0
pipeline.anchor_lock_cap_tokens = 10_000
@@ -3793,9 +3792,6 @@ class UnifiedRadixCacheSuite:
if self.cfg.components != (ComponentType.FULL,) or self.cfg.page_size != 4:
self.skipTest("one FULL page_size=4 fixture covers namespace routing")
anchor_lock = envs.SGLANG_ENABLE_HICACHE_BUFFER_ANCHOR_LOCK.override(True)
anchor_lock.__enter__()
self.addCleanup(anchor_lock.__exit__, None, None, None)
storage_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, storage_dir, ignore_errors=True)
@@ -4001,9 +3997,6 @@ class UnifiedRadixCacheSuite:
# the retained per-fixture device memory stays bounded.
if self.cfg.page_size != 1 or self.cfg.sliding_window_size != 4:
self.skipTest("requires page_size=1, sliding_window_size=4")
cm = envs.SGLANG_ENABLE_HICACHE_BUFFER_ANCHOR_LOCK.override(True)
cm.__enter__()
self.addCleanup(cm.__exit__, None, None, None)
storage_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, storage_dir, ignore_errors=True)
from sglang.srt.mem_cache.swa_memory_pool import SWAKVPool
@@ -8921,7 +8914,6 @@ class TestAnchorLockOutcomePolicy(CustomTestCase):
from sglang.srt.mem_cache.buffer_mode.pipeline import BufferModePipeline
pipeline = BufferModePipeline.__new__(BufferModePipeline)
pipeline.anchor_lock_enabled = True
pipeline.anchor_locks = {}
pipeline.anchor_locked_tokens_ = 0
pipeline.anchor_lock_cap_tokens = cap_tokens