Repository navigation
[CI] Reclaim leaked /dev/shm segments on server startup - #28089
Merged
Merged
Conversation
Kangyan-Zhou
requested review from
CatherineSue,
JustinTong0323,
Ying1123,
ch-wan,
hnyls2002,
ispobock,
merrymercy,
slin1237,
xiezhq-hermann and
yizhang2077
as code owners
June 12, 2026 21:27
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
SGLang tears processes down with SIGKILL (kill_process_tree, PDEATHSIG),
which skips every Python-level shm unlink path. On CI runners the leaked
segments accumulate across jobs until /dev/shm (1 GiB on 1-GPU runners)
fills up and the next scheduler init dies with SIGBUS
("Fatal Python error: Bus error", exit code -7).
Fix: name our anonymous shared-memory segments with the creator pid
(sgl_shm_<kind>_<pid>_<rand>) and sweep dead-creator segments at server
startup. The sweep is gated on SGLANG_IS_IN_CI because pid-liveness is
only a trustworthy ownership signal in single-tenant runner containers.
- mm_utils ShmPointerMMData and shm_broadcast ShmRingBuffer now pass an
explicit pid-stamped name (multi_tokenizer_args_<pid> already does)
- cleanup_stale_shm() runs at Engine._launch_subprocesses, covering both
the HTTP server and Engine entrypoints
- unlinks only sgl_shm_* / multi_tokenizer_args_* whose creator pid is
dead; foreign psm_* segments are never touched
Verified end-to-end inside the h100-novita-host3-gpu-2 runner container.
Co-Authored-By: Claude Fable 5 <[email protected]>
…ymous shm sites - cleanup_stale_shm never raises (outer guard with logged warning) so a sweep failure can't block server startup - iterdir / unlink failures log warnings instead of silently no-oping; only the FileNotFoundError unlink race stays silent - reject non-positive pids in _creator_pid (os.kill(0/-1, 0) probes process groups, not a process) - convert the two remaining anonymous SharedMemory creators (parallel_state is_in_the_same_node, cuda_ipc ShmSyncBuffer) to pid-stamped names - tests: bind the ShmRingBuffer call site to the reclaimable name format, use a realistic psm_* foreign segment, cover non-positive pids Co-Authored-By: Claude Fable 5 <[email protected]>
Run the sweep once per CI job (right after killall, before installs) instead of at every engine startup: - the gate reads SGLANG_IS_IN_CI directly so the module is import-free and runnable by file path before sglang is installed - __main__ entry + cuda ci_install_dependency.sh step (best-effort, || true) - engine startup no longer calls the sweep - tests patch the env var and cover the run-by-path entry Co-Authored-By: Claude Fable 5 <[email protected]>
Kangyan-Zhou
force-pushed
the
shm-stale-cleanup
branch
from
June 12, 2026 22:21
0d22e46 to
fecf7a6
Compare
Collaborator
Author
|
/tag-and-rerun-ci |
Chronostasys
pushed a commit
to MindLab-Research/sglang
that referenced
this pull request
Aug 24, 2026
…28089) Co-authored-by: Claude Fable 5 <[email protected]>
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.
Motivation
CI jobs tear sglang down with SIGKILL (
kill_process_tree,PR_SET_PDEATHSIG), which skips every Python-level shared-memory unlink path (finallyblocks,atexit, the multiprocessing resource_tracker — itself SIGKILLed as part of the tree). Leakedpsm_*segments accumulate across jobs in long-lived runner containers until/dev/shm(1 GiB on 1-GPU runners) is 100% full, and the next scheduler init dies with:Observed on
h100-novita-host3-gpu-2(failingbase-b-test-1-gpu-largeon #28076): /dev/shm at 100% with hundreds of multi-MBpsm_*segments leaked by earlier SIGKILLed jobs.Modifications
sglang/srt/utils/stale_shm_cleanup.py:make_shm_name(kind)→sgl_shm_<kind>_<pid>_<rand>, so segments are attributable to their creator process.cleanup_stale_shm()— unlinksgl_shm_*/multi_tokenizer_args_*segments whose creator pid is dead. CI-only (gated onSGLANG_IS_IN_CI): pid-liveness is only a trustworthy ownership signal in single-tenant runner containers; never touches foreignpsm_*segments; pid-reuse degrades to under-collection, never to deleting a live segment. Best-effort: never raises, logs failures instead of silently no-oping.SharedMemory(create=True)sites now use pid-stamped names:ShmPointerMMData(mm_utils),ShmRingBuffer(shm_broadcast),ShmSyncBuffer(cuda_ipc_transport_utils),is_in_the_same_node(parallel_state).multi_tokenizer_args_<pid>already embedded the pid.scripts/ci/cuda/ci_install_dependency.sh(right afterkill_existing_processes, before installs). The module is import-free and invoked by file path, so it works before sglang is installed.Checklist
test/registered/utils/test_stale_shm_cleanup.py, registered inbase-a-test-cpu), including a call-site binding test forShmRingBufferand the run-by-path entry.🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #27519180685
Latest PR Test (Extra): ❌ Run #27519180607