Skip to content

perf(sglang): batch prefix-cache frees during runtime shrink - #635

Open
jeff3071 wants to merge 2 commits into
ovg-project:mainfrom
jeff3071:perf/sglang-batch-shrink-frees
Open

jeff3071 wants to merge 2 commits into
ovg-project:mainfrom
jeff3071:perf/sglang-batch-shrink-frees

Conversation

@jeff3071

@jeff3071 jeff3071 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Stack on #627 ; review increment change. Runtime shrink evicts prefix cache through SGLang's native eviction, which frees each evicted radix node separately. One shrink eviction therefore issues many kvcached free() calls, and the scheduler stalls while they run.

Each shrink eviction now runs in an allocator free group, so each pool frees its victims once.

  • Inside a scheduler free group, reclaim keeps the existing behavior: groups cannot nest, so its frees wait for the scheduler.
  • The group ends even if eviction fails.
  • Victim selection is unchanged. Token-cap retention and priority reclaim are unchanged.

Related: #621.

Test

Compared #627 (ac48814) with This PR (eff693d).

Setup

  • NVIDIA RTX PRO 6000 Blackwell 96GB, Gemma 4 12B (FULL + SWA), SGLang 0.5.20
  • Fill the prefix cache with 500 ShareGPT requests under a high limit
  • Start 8 streaming requests (256-token prompts, 400 output tokens), then publish a low limit that evicts most of the cache at once
  • Two servers per configuration, two shrinks per server, alternating; every shrink started from the same cache

One large shrink

Median of four shrinks (min–max).

Metric #627 This PR
Cached tokens before shrink (FULL / SWA) 202k / 177k 202k / 177k
Eviction time (ms) 416.6 (414–432) 183.3 (173–209)
Native eviction time (ms) 305.0 (301–312) 66.0 (65–81)
Limit published → both pools shrunk (ms) 471.8 (465–477) 366.6 (356–417)
Steady-state ITL, median (ms) 22.4 22.5
Max ITL during shrink (ms) 442.8 (439–458) 344.4 (334–379)

Native eviction time decreased by 78%, and the longest decode stall during the shrink decreased from 443 ms to 344 ms. The remaining time is mostly page-aware victim selection from #627.

jeff3071 and others added 2 commits November 13, 2026 13:43
Native eviction frees each evicted radix node separately. Run each
shrink eviction in an allocator free group so each pool frees its
victims once. Inside a scheduler free group, reclaim keeps waiting for
the scheduler's frees; the group ends even if eviction fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant