Repository navigation
[Bugfix][Store] Register ShmHelper memory with SPDK for NoF zero-copy transfers #3717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
91097b7
Register ShmHelper memory with SPDK for NoF zero-copy transfers
NUABO eee6a6a
Fix DummyClient::register_buffer size check for SPDK-padded segments
NUABO 42f3005
Fix static destruction-order UB in ShmHelper SPDK unregister
NUABO 93b171d
Register receiver-side mapping with SPDK for NoF zero-copy (standalon…
NUABO 6a8bec2
Fix receiver teardown leaks and unregister consistency
NUABO 350b0fd
Force hugepages for ShmHelper memory under MC_STORE_REGISTER_SPDK
NUABO 8d90395
Retain SPDK-registered shm mappings when spdk_mem_unregister fails
NUABO aa443f8
format code
NUABO f8955c7
trigger CI pipeline
NUABO 76cce5a
Retain mappings when transfer engine unregister fails during teardown
NUABO 84b32f9
Clear spdk_registered on TE-only quarantine
NUABO e1d8ffe
Report RPC_FAIL when Ascend context setup blocks a shm teardown
NUABO 00179e3
Retain SPDK mappings unless spdk_mem_unregister confirms cleanup
NUABO 0877bb5
Merge branch 'main' into fix-nof-alloc
NUABO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <sys/mman.h> | ||
|
|
||
| #include "common/client_buffer_allocation.h" | ||
|
|
||
| namespace mooncake { | ||
|
|
||
| /** | ||
| * @brief Place a memfd mapping at a 2MB-aligned address while keeping the file | ||
| * offset at 0, so the returned base matches what a peer process mapping the fd | ||
| * at offset 0 sees (cross-process fd sharing is unchanged). | ||
| * | ||
| * SPDK before 26.09 (e.g. the v23.01.1 pinned by dependencies.sh) rejects | ||
| * spdk_mem_register() unless both the start and the length are 2MB-aligned; | ||
| * plain mmap only guarantees 4KB alignment. Reserve a PROT_NONE region large | ||
| * enough to contain a 2MB-aligned window, then MAP_FIXED the memfd into it | ||
| * (which only replaces the reservation, never live mappings), and release the | ||
| * unaligned head/tail. `size` should be a multiple of 2MB (callers align it). | ||
| * | ||
| * NOTE: virtual 2MB alignment is NECESSARY but NOT sufficient on the pinned | ||
| * SPDK: in iova=pa mode spdk_mem_register additionally checks each segment's | ||
| * PHYSICAL address (vtophys pagemap path, `paddr & MASK_2MB`), so the memory | ||
| * must also be hugepage-backed or registration fails with -EINVAL. HugeTLB | ||
| * mappings are automatically 2MB/1GB-aligned, so this helper is only needed | ||
| * where the source cannot be hugepage-backed; today it is used solely by the | ||
| * receiver (RealClient::map_shm_internal_with_device) for the shared fd | ||
| * (1GB-hugepage fds whose MAP_FIXED here fails fall back to a plain mmap). The | ||
| * sender (ShmHelper::allocate) always maps hugepages under | ||
| * MC_STORE_REGISTER_SPDK=1 and needs no aligned base. SPDK >= 26.09 (commit | ||
| * d6dc356ff) relaxes the API check to 4KB, but iova=pa still needs hugepages, | ||
| * so a plain mmap remains insufficient for SPDK registration regardless of | ||
| * version. | ||
| * | ||
| * @param size Mapping length; must be a multiple of 2MB for a clean head/tail. | ||
| * @param fd memfd to map at offset 0. | ||
| * @return The 2MB-aligned base, or MAP_FAILED on error. | ||
| */ | ||
| inline void* mmap_shm_2mb_aligned(size_t size, int fd) { | ||
| const size_t reserve_size = size + SZ_2MB; | ||
| void* hint = mmap(nullptr, reserve_size, PROT_NONE, | ||
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
| if (hint == MAP_FAILED) { | ||
| return MAP_FAILED; | ||
| } | ||
| const uintptr_t hint_addr = reinterpret_cast<uintptr_t>(hint); | ||
| const uintptr_t target = static_cast<uintptr_t>( | ||
| align_up(static_cast<size_t>(hint_addr), SZ_2MB)); | ||
| void* base = | ||
| mmap(reinterpret_cast<void*>(target), size, PROT_READ | PROT_WRITE, | ||
| MAP_SHARED | MAP_FIXED | MAP_POPULATE, fd, 0); | ||
| if (base == MAP_FAILED) { | ||
| munmap(hint, reserve_size); | ||
| return MAP_FAILED; | ||
| } | ||
| // Release the unaligned head and tail of the reservation. | ||
| const uintptr_t base_addr = reinterpret_cast<uintptr_t>(base); | ||
| if (base_addr > hint_addr) { | ||
| munmap(hint, base_addr - hint_addr); | ||
| } | ||
| const uintptr_t reserve_end = hint_addr + reserve_size; | ||
| const uintptr_t tail = base_addr + size; | ||
| if (tail < reserve_end) { | ||
| munmap(reinterpret_cast<void*>(tail), reserve_end - tail); | ||
| } | ||
| return base; | ||
| } | ||
|
|
||
| } // namespace mooncake |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.