[mem_cache] Free hybrid SWA pages by one representative per page on page_size > 1 - #38159
Merged
Merged
Conversation
hnyls2002
requested review from
Ying1123,
alphabetc1,
hanming-lu,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
September 5, 2026 21:08
# Conflicts: # python/sglang/srt/mem_cache/allocator/token.py
This was referenced Sep 8, 2026
This was referenced Sep 8, 2026
This was referenced Sep 8, 2026
5 tasks
5 tasks
This was referenced Sep 11, 2026
mqhc2020
pushed a commit
to mqhc2020/sglang
that referenced
this pull request
Sep 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
free_swa_segment(idx, *, start_pos), the SWA-only counterpart offree_segment/free_full_segment, and route every kv-row caller through it;free_swa(idx)stays the set-shaped form (alloc rollback)page_size > 1the SWA side now frees by host-derived page ids (mapping[idx[::page_size]] // page_size) instead of expanding pages, filtering> 0and dedup'ing throughtorch.unique, so a hybrid SWA free no longer synchronizes the scheduler stream at any page size (follows [mem_cache] Makefree_swasync-free onpage_size == 1#36723, which coveredpage_size == 1)free_page_ids(page_ids)to the paged and token allocators as the page-native primitive (exact pages, no dedup);free_segmentis built on itDetails
swa_page_ids_group) and flushes them with onefree_page_ids, so the group flush is fixed-shape toofree_swa_out_of_window_slots,SWARadixCachenode frees (free_swa/free/free_fullon page-aligned node values), the unifiedFreeComponentDeviceSlotaction;UnifiedSWATokenToKVPoolAllocatorsplits its existingstart_posbranch intofree_swa_segmentso both hybrid allocators share the APIseq_lens, HiCache load-back pairs equal-length page-aligned chunks), so the first token of a page maps into the whole peer pageTests
test_swa_unittest.py: page-set equivalence againsttorch.uniqueover every tail length with the mapping cleared per page,set_sync_debug_mode("error")on the segment path in and out of a group (CUDA), the_SWA_PEER_MAPPEDpredicate onpage_size == 4, tree eviction never reaching the innerfree, and the group-ownership test parametrized overpage_size in (1, 4)Original commits
80197780d1b0dff8cc3bd556e790de7e7900653cCI States
Latest PR Test (Base): ✅ Run #34162095517
Latest PR Test (Extra): ✅ Run #34162095388
Latest PR Test (AMD ROCm 7.2): ❌ Run #34162095509