Skip to content

fix(offload): create the shared host regions through libc where Python has no os.memfd_create - #118

Merged
cennn merged 1 commit into
mainfrom
fix/memfd-without-os-binding
Nov 28, 2026
Merged

cennn merged 1 commit into
mainfrom
fix/memfd-without-os-binding

Conversation

@cennn

@cennn cennn commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

🗂️ PR Category

  • ✨ New Feature
  • 🚀 Optimization (performance, memory, etc.)
  • 💥 Breaking Change
  • 🐛 Bug Fix
  • 🛠️ Development / Refactoring
  • 📚 Documentation
  • 🧹 Chore (Dependencies, CI/CD, Configuration, etc.)
  • 🧪 Testing

📝 Description

Rank-shared host weights (offload_host_weight_sharing other than off) back each shared region with a memfd from os.memfd_create. CPython only defines that function when the glibc it was built against has memfd_create (2.27+), and conda builds Python on a glibc 2.17 sysroot. A conda Python, as some vendor PyTorch images ship under /opt/conda, therefore has no os.memfd_create even on a host whose glibc and kernel provide it, and the first shared region failed every rank:

host offload: shared host region writer failed: rank 0: AttributeError: module 'os' has no attribute 'memfd_create'

Without os.memfd_create, the region is now created by the running glibc's memfd_create through ctypes, with the same MFD_CLOEXEC flag. A failure raises OSError with its errno, so the existing ENOSPC handling (the chunk stays rank-private) applies unchanged. A Python that has os.memfd_create takes the same path as before.

Verified on a conda Python 3.12.11 on glibc 2.39: the region is a close-on-exec /memfd:magi_offload_* file that posix_fallocate sizes. The new test_a_python_without_os_memfd_create_still_creates_a_memfd deletes os.memfd_create and checks the same.

ComfyUI merged the same fallback (Comfy-Org/ComfyUI#17386); vLLM has one under review (vllm-project/vllm#69731).

…n has no os.memfd_create

A Python built against a glibc older than 2.27, as conda builds on its 2.17 sysroot, leaves out os.memfd_create
even though the running glibc and kernel provide it; per-host weight sharing then failed on its first region.
@cennn cennn added the ci:run Trigger CI integration tests label Nov 28, 2026
@github-actions github-actions Bot removed the ci:run Trigger CI integration tests label Nov 28, 2026

@jiahy0825 jiahy0825 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@cennn
cennn merged commit 89bec61 into main Nov 28, 2026
22 checks passed
@cennn
cennn deleted the fix/memfd-without-os-binding branch November 28, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants