Skip to content

[Core] Fail fast when /dev/shm is too small for the shm ring buffer - #48879

Merged
njhill merged 12 commits into
vllm-project:mainfrom
andreatassi:fix/shm-ring-buffer-freespace-check
Jul 27, 2026
Merged

njhill merged 12 commits into
vllm-project:mainfrom
andreatassi:fix/shm-ring-buffer-freespace-check

Conversation

@andreatassi

Copy link
Copy Markdown
Contributor

[Core] Fail fast when /dev/shm is too small for the shared-memory ring buffer

Purpose

With tensor parallelism (TP ≥ 2), MessageQueue allocates a POSIX shared-memory
ring buffer (default max_chunk_bytes=24 MiB × max_chunks=10 ≈ 240 MiB) in
/dev/shm. tmpfs allocation is lazy: SharedMemory(create=True, size=...)
succeeds even when /dev/shm is smaller than the requested buffer, and physical
pages only fault in later, under load. When usage crosses the tmpfs limit the
worker is killed by an uncatchable SIGBUS, which surfaces to the user as an
opaque EngineDeadError: EngineCore encountered an issue.

This is easy to hit on the common 64 MB default /dev/shm used by Docker and
by a plain Kubernetes Pod (unless the operator adds an emptyDir{medium: Memory}).
On such a deployment the server can start and serve text-only traffic, then die
under multimodal load. Observed reproduction: multiple prompts sent in parallel,
each with one image attached, with --tensor-parallel-size 2 on a 64 MB
/dev/shm — the per-request image payloads broadcast to the TP workers filled
enough ring-buffer chunks to exceed 64 MB and killed the engine. Text-only
prompts of the same shape stayed well under the limit, so the user-supplied image
data is the amplifier.

This PR makes the failure fail fast and actionable: a pre-flight free-space
check raises a clear RuntimeError at buffer-creation time instead of allowing a
later SIGBUS.

Root cause

ShmRingBuffer.__init__ (vllm/distributed/device_communicators/shm_broadcast.py)
calls shared_memory.SharedMemory(create=True, size=total_bytes_of_buffer) with no
check that /dev/shm can actually hold total_bytes_of_buffer.

Fix

  • Add check_shm_free_space(required_bytes, shm_path="/dev/shm"): compares the
    requested size against shutil.disk_usage(shm_path).free and raises a
    RuntimeError with remediation guidance (--shm-size / --ipc=host, or a
    larger /dev/shm such as a Kubernetes emptyDir with medium: Memory and a
    sizeLimit). The check is skipped when /dev/shm does not exist (non-Linux).
  • Call it in ShmRingBuffer.__init__ before the segment is allocated.

Correctly sized deployments (/dev/shm ≥ buffer) are unaffected.

Notes on severity

The crash is reachable by unauthenticated clients on the common 64 MB default, so
there is a plausible denial-of-service angle. It is submitted here as a public
hardening PR (it depends on deployment sizing that vLLM already documents, and
related reports — #1111, #1393, #1710 — were resolved as "increase shm"). Happy to
route it through the security process instead if maintainers prefer.

Test Plan

  • New unit tests in tests/distributed/test_shm_broadcast.py covering the helper
    (insufficient → raises, sufficient → passes, missing path → skipped) and the
    integration path (ShmRingBuffer creation raises before allocation).
  • pre-commit run --files on both changed files (ruff, ruff-format, mypy, typos,
    SPDX headers, and the other applicable hooks).
.venv/bin/python -m pytest tests/distributed/test_shm_broadcast.py \
  -k "check_shm_free_space or ring_buffer_creation_checks" -v

Test Result

tests/distributed/test_shm_broadcast.py::test_check_shm_free_space_raises_when_insufficient PASSED
tests/distributed/test_shm_broadcast.py::test_check_shm_free_space_passes_when_sufficient PASSED
tests/distributed/test_shm_broadcast.py::test_check_shm_free_space_skipped_when_path_missing PASSED
tests/distributed/test_shm_broadcast.py::test_shm_ring_buffer_creation_checks_free_space PASSED
4 passed, 6 deselected

pre-commit run --files vllm/distributed/device_communicators/shm_broadcast.py tests/distributed/test_shm_broadcast.py — ruff, ruff-format, mypy (Python 3.10),
typos, SPDX headers, and all other applicable hooks passed.

Manually verified against a real /dev/shm that the guard reads statvfs
correctly (raises when the request exceeds real free space, passes otherwise).

Model evaluation

Not applicable — this is a startup pre-flight guard on inter-process shared memory.
It does not touch model execution, sampling, or outputs, so accuracy/serving
quality are unaffected.

AI assistance disclosure

AI assistance was used to develop this change. The submitting author has reviewed
every changed line and run the tests above.


Authored-by: Dr Andrea Tassi, Verticular Ltd (andrea@verticular.uk)

With tensor parallelism (TP >= 2), MessageQueue allocates a POSIX
shared-memory ring buffer (default 24 MiB x 10 = ~240 MiB) in /dev/shm.
tmpfs allocation is lazy, so SharedMemory(create=True, size=...) succeeds
even when /dev/shm is smaller than the buffer; pages only fault in under
load and the worker is then killed by an uncatchable SIGBUS, surfacing as
an opaque EngineDeadError. This is easy to hit on the common 64 MB
default /dev/shm used by Docker and Kubernetes.

Add check_shm_free_space() and call it before creating the segment in
ShmRingBuffer. When the requested buffer exceeds the free space of
/dev/shm, raise a clear RuntimeError at startup with actionable
remediation (--shm-size / --ipc=host / a larger emptyDir) instead of
crashing later with SIGBUS. Correctly sized deployments are unaffected;
the check is skipped when /dev/shm is absent (non-Linux).

Signed-off-by: Dr Andrea Tassi <andrea@verticular.uk>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@joerunde joerunde left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lpgtm!

Big fan of up front checks for invalid configs 👍

@njhill

njhill commented Jul 22, 2026

Copy link
Copy Markdown
Member

Also LGTM, I just feel the comments and error message are a bit too verbose.

Signed-off-by: Dr Andrea Tassi <andrea@verticular.uk>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@andreatassi

Copy link
Copy Markdown
Contributor Author

Also LGTM, I just feel the comments and error message are a bit too verbose.

Comments and error message trimmed down. Thanks

@njhill njhill added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 22, 2026
@njhill

njhill commented Jul 23, 2026

Copy link
Copy Markdown
Member

@andreatassi please don't rebase more, it restarts a full CI run

@andreatassi

Copy link
Copy Markdown
Contributor Author

@andreatassi please don't rebase more, it restarts a full CI run

sorry! I was on "autopilot mode" :(

@njhill
njhill enabled auto-merge (squash) July 23, 2026 21:50
@njhill
njhill merged commit 831d384 into vllm-project:main Jul 27, 2026
5 checks passed
pawel-olejniczak added a commit to pawel-olejniczak/vllm-gaudi that referenced this pull request Jul 28, 2026
…hm ring-buffer /dev/shm size guard on HPU

Root cause: vLLM PR #48879 added an eager check_shm_free_space guard that rejects the 240 MiB nominal shm ring buffer on the 64 MiB /dev/shm of HPU CI containers, aborting EngineCore start-up on TP2/DP/multi-proc tests.
Upstream: vllm-project/vllm#48879
Fix: monkey-patch check_shm_free_space to a no-op on HPU, restoring the pre-#48879 lazy tmpfs allocation that fit the container /dev/shm.

Signed-off-by: Paweł Olejniczak <pawelx.olejniczak@intel.com>
pawel-olejniczak added a commit to pawel-olejniczak/vllm-gaudi that referenced this pull request Jul 29, 2026
…hm ring-buffer /dev/shm size guard on HPU

Root cause: vLLM PR #48879 added an eager check_shm_free_space guard that rejects the 240 MiB nominal shm ring buffer on the 64 MiB /dev/shm of HPU CI containers, aborting EngineCore start-up on TP2/DP/multi-proc tests.
Upstream: vllm-project/vllm#48879
Fix: monkey-patch check_shm_free_space to a no-op on HPU, restoring the pre-#48879 lazy tmpfs allocation that fit the container /dev/shm.

Signed-off-by: Paweł Olejniczak <pawelx.olejniczak@intel.com>
fank added a commit to fank/vllm that referenced this pull request Sep 3, 2026
… site

VLLM_MQ_MAX_CHUNK_BYTES_MB is documented as bounding the shm ring buffers,
but only rpc_broadcast_mq reads it. worker_response_mq falls back to the
24 MiB signature default in both the multiproc and Ray v2 executors, and is
created once PER WORKER, so at TP=2 it requests 2 x 24 MiB x 10 = 480 MiB no
matter what the env var says.

On a host with the common 64 MiB /dev/shm the env var therefore cannot bring
usage under the limit. Since vllm-project#48879 added check_shm_free_space this is a hard
failure at startup:

  RuntimeError: Insufficient space in /dev/shm: 240 MiB required, 64 MiB free.

Setting VLLM_MQ_MAX_CHUNK_BYTES_MB=4 moves the broadcast queue from 160 to
40 MiB but leaves the 480 MiB untouched. With this change the same setting
yields 40 + 2 x 40 MiB, and 1 MiB yields 10 + 2 x 10 = 30 MiB, which fits.

This matters most where /dev/shm cannot be resized: a plain Kubernetes Pod
needs an emptyDir{medium: Memory} mount to raise it, which some managed
platforms do not expose. vllm-project#49568 makes it configurable in the Helm chart; this
gives deployments that cannot mount volumes a way to fit within what they have.

Co-authored-by: Claude
Signed-off-by: Florian Kinder <florian.kinder@enthus.de>
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
…llm-project#48879)

Signed-off-by: Dr Andrea Tassi <andrea@verticular.uk>
Co-authored-by: Dr Andrea Tassi <andrea@verticular.uk>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants