Repository navigation
fix(dynamicemb): size HostVMMTensor mapping to need, grow via mremap - #425
Merged
Merged
Conversation
Collaborator
Author
|
/build |
Contributor
Collaborator
|
❌ Pipeline #54914686 -- failed
Result: 14/17 jobs passed |
HostVMMTensor reserved the entire machine's physical RAM as an anonymous mmap for every host tensor, intending it as a VA window that extend() would grow into in place. With many tables (e.g. the test_alignment suite), these multi-TB reservations accumulate and exhaust the process virtual address space, so mmap eventually fails with ENOMEM even for tiny tensors: RuntimeError: mmap virtual memory failed (size=2164192202752 bytes): Cannot allocate memory Map only the bytes actually backed (page-aligned) and grow the mapping on demand in extend() via mremap(MREMAP_MAYMOVE). Relocation is safe: callers rebuild value-buffer pointers after extend() per the get_table_ptrs() contract. Robustness: - restore_to_size() centralizes rollback: on any failure after the mapping has grown (mremap/mlock/cudaHostRegister/cudaHostGetDevicePointer), drop the CUDA registration, shrink the mapping back, and re-register, leaving the object consistent (m_size == m_reserved == old size) and safe to reuse/retry. - Record the grown extent (m_reserved) immediately after a successful mremap so the destructor's munmap always covers the whole mapping (no tail leak). - Free the mmap'd + mlocked buffer if CUDA registration fails in the constructor (the destructor does not run on a failed construction). - Treat madvise(MADV_WILLNEED) as the advisory hint it is: non-fatal in both the constructor and extend() (memset + mlock are the real fault-in/pin), warning with errno instead of aborting or silently ignoring it. - Destructor is best-effort (never throws); add _GNU_SOURCE for mremap and include errno/size in the mmap error message. Fixes the host path of test/unit_tests/test_alignment.py; verified passing at WORLD_SIZE=1/4/8 plus the test_vmm_tensor.py extend stress test. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
jiashuy
force-pushed
the
fix_host_vmm_bug
branch
from
June 17, 2026 06:33
0c12c7a to
ffe3351
Compare
shijieliu
approved these changes
Jun 17, 2026
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.
HostVMMTensor reserved the entire machine's physical RAM as an anonymous mmap for every host tensor, intending it as a VA window that extend() would grow into in place. With many tables (e.g. the test_alignment suite), these multi-TB reservations accumulate and exhaust the process virtual address space, so mmap eventually fails with ENOMEM even for tiny tensors:
RuntimeError: mmap virtual memory failed (size=2164192202752 bytes):
Cannot allocate memory
Map only the bytes actually backed (page-aligned) and grow the mapping on demand in extend() via mremap(MREMAP_MAYMOVE). Relocation is safe: callers rebuild value-buffer pointers after extend() per the get_table_ptrs() contract. CUDA registration is re-done around the remap, with rollback to the previous size on mremap/mlock/cudaHostRegister failure. Add _GNU_SOURCE for mremap and include errno/size in the mmap error message.
Fixes the host path of test/unit_tests/test_alignment.py; verified passing at WORLD_SIZE=1/4/8 plus the test_vmm_tensor.py extend stress test.
Description
Checklist