trim_overshoot: cap swa_evicted_seqlen + unit test#22900
Merged
Conversation
This reverts commit 6e3351f.
…ncates output_ids)
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
hnyls2002
added a commit
that referenced
this pull request
Apr 15, 2026
…swa-cap # Conflicts: # python/sglang/srt/mem_cache/session_aware_cache.py
Collaborator
Author
|
/tag-and-rerun-ci |
Collaborator
Author
|
/rerun-test test_streaming_session.py test_streaming_session_unit.py test_session_control.py test_session_latency.py |
Contributor
|
✅ ✅ |
This was referenced Apr 15, 2026
jmamou
pushed a commit
to jmamou/sglang
that referenced
this pull request
Apr 20, 2026
yhyang201
pushed a commit
to yhyang201/sglang
that referenced
this pull request
Apr 22, 2026
zhangying098
pushed a commit
to zhangying098/sglang
that referenced
this pull request
Apr 23, 2026
kyx1999
pushed a commit
to KMSorSMS/sglang
that referenced
this pull request
Apr 27, 2026
4 tasks
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.
Problem
_trim_overshoot(added in #22897) capskv_committed_lenandkv_allocated_lenattarget = origin + finished_len, but leavesreq.swa_evicted_seqlenuntouched._free_tail(the match_prefix counterpart on the sameSessionAwareCache) caps all three. The asymmetry causes a SWA pool leak when a finishing round overshoots while SWA was actively evicting.swa_evicted_seqlenis a cursor —_evict_swareads it as the start position for the next eviction sweep:If overshoot pushed the cursor past the trim boundary (e.g.
swa_evicted = 42buttarget = 38),save_from_reqpropagates the stale 42 into the slot and next turn'srestore_to_reqhands it back. Next turn's prefill writes new SWA slots at positions[38, 42), but_evict_swastarts scanning from 42 — those slots are skipped forever and accumulate as a leak.Fix
One-line cap to mirror
_free_tail:This is the only other downward-cap site for
swa_evicted_seqlenoutside_free_tail(andreset_for_retract, which clears to 0). Both downward-moving paths now enforce the same invariant:swa_evicted_seqlen <= origin + committed.Test
Adds
test_trim_overshoot_postconditioncovering the full postcondition in one shot:kv_committed_len,kv_allocated_len,swa_evicted_seqlenall capped at target,output_idstruncated tofinished_len, and the page-aligned tail freed. Without the swa cap, the test fails onswa_evicted_seqlen == target(assert 42 == 38).