From f3fe75347577ff883244bbe4584d36da8805c146 Mon Sep 17 00:00:00 2001 From: Liangsheng Yin Date: Mon, 5 Oct 2026 17:24:15 -0700 Subject: [PATCH] [misc] Rename `SGLANG_OPT_SWA_RELEASE_LEAF_LOCK_AFTER_WINDOW` to `SGLANG_OPT_RELEASE_PREFILL_SWA` (#42657) --- python/sglang/srt/environ.py | 6 +++++- python/sglang/srt/managers/schedule_batch.py | 11 ++++------- test/manual/dsv4/test_dsv4_swa_radix_retract.py | 2 +- .../unit/mem_cache/test_swa_eviction_interval.py | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/python/sglang/srt/environ.py b/python/sglang/srt/environ.py index 83e7f1671c..db80063997 100644 --- a/python/sglang/srt/environ.py +++ b/python/sglang/srt/environ.py @@ -691,7 +691,11 @@ class Envs: # - Source builds with a missing or unusable Rust toolchain. # This also applies when Rust is explicitly selected. SGLANG_UNIFIED_RADIX_TREE_CORE_BACKEND = EnvStr("rust") - SGLANG_OPT_SWA_RELEASE_LEAF_LOCK_AFTER_WINDOW = EnvBool(False) + # Once decode passes the sliding window, drop the SWA part of the prefill's + # tree lock; its SWA KV becomes evictable rather than freed. + SGLANG_OPT_RELEASE_PREFILL_SWA = EnvBoolWithAlias( + False, deprecated_name="SGLANG_OPT_SWA_RELEASE_LEAF_LOCK_AFTER_WINDOW" + ) # =================================================================== # PD disaggregation runtime diff --git a/python/sglang/srt/managers/schedule_batch.py b/python/sglang/srt/managers/schedule_batch.py index a769aee2df..9179c55c35 100755 --- a/python/sglang/srt/managers/schedule_batch.py +++ b/python/sglang/srt/managers/schedule_batch.py @@ -3919,9 +3919,8 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin): # Auxiliary windows check their own cursors and prefix locks. has_auxiliary_swa = self.tree_cache.supports_auxiliary_swa() - release_leaf_lock = ( - envs.SGLANG_OPT_SWA_RELEASE_LEAF_LOCK_AFTER_WINDOW.get() - and hasattr(self.tree_cache, "dec_swa_lock_only") + release_leaf_lock = envs.SGLANG_OPT_RELEASE_PREFILL_SWA.get() and hasattr( + self.tree_cache, "dec_swa_lock_only" ) eviction_interval = max(1, envs.SGLANG_SWA_EVICTION_INTERVAL.get()) @@ -3949,10 +3948,8 @@ class ScheduleBatch(ScheduleBatchDisaggregationDecodeMixin): ), ) - # Once the decode position has moved past the sliding window, - # the SWA portion of the prefill-time tree lock is no longer - # needed by this request. Convert it from protected to - # evictable so SWA LRU can reclaim it under pressure. + # Past the window the request no longer reads its prefill's SWA; + # release that part of the tree lock so SWA LRU can reclaim it. if ( release_leaf_lock and not req.swa_prefix_lock_released diff --git a/test/manual/dsv4/test_dsv4_swa_radix_retract.py b/test/manual/dsv4/test_dsv4_swa_radix_retract.py index 24a9a64b54..437fde58f2 100644 --- a/test/manual/dsv4/test_dsv4_swa_radix_retract.py +++ b/test/manual/dsv4/test_dsv4_swa_radix_retract.py @@ -7,7 +7,7 @@ of alignment slack, so this reproduces the historical trip conditions rather than a line that still exists. Trip conditions (all required): - 1. Fork-only SWA leaf early-release on (`SGLANG_OPT_SWA_RELEASE_LEAF_LOCK_AFTER_WINDOW=1`) + 1. Early SWA release of the prefill lock on (`SGLANG_OPT_RELEASE_PREFILL_SWA=1`) 2. Multiple requests share a long prefix (so one req's tombstoned leaf poisons match_prefix for others walking the same radix path). 3. Memory pressure forces retract while at least one req has tombstoned diff --git a/test/registered/unit/mem_cache/test_swa_eviction_interval.py b/test/registered/unit/mem_cache/test_swa_eviction_interval.py index 6fbf40761c..f9a1e0a113 100644 --- a/test/registered/unit/mem_cache/test_swa_eviction_interval.py +++ b/test/registered/unit/mem_cache/test_swa_eviction_interval.py @@ -47,7 +47,7 @@ class TestSWAEvictionInterval(unittest.TestCase): with ( self.subTest(protected=protected, shield=shield, auxiliary=auxiliary), envs.SGLANG_SWA_EVICTION_INTERVAL.override(128), - envs.SGLANG_OPT_SWA_RELEASE_LEAF_LOCK_AFTER_WINDOW.override(False), + envs.SGLANG_OPT_RELEASE_PREFILL_SWA.override(False), ): cache = _SwaCache(auxiliary=auxiliary) req = SimpleNamespace( @@ -113,7 +113,7 @@ class TestSWAEvictionInterval(unittest.TestCase): patch("sglang.srt.managers.schedule_batch._is_hip", True), envs.SGLANG_AMD_USE_FLYDSL_MEGA_MOE.override(True), envs.SGLANG_SWA_EVICTION_INTERVAL.override(128), - envs.SGLANG_OPT_SWA_RELEASE_LEAF_LOCK_AFTER_WINDOW.override(False), + envs.SGLANG_OPT_RELEASE_PREFILL_SWA.override(False), ): batch.maybe_evict_swa() free.assert_not_called()