Merge blocked
变更摘要
本 PR(pid add)为 RoCE 远端内存管理引入进程 PID 维度,以区分同一网卡(EndpointDesc)上来自不同远端进程的内存导入。核心改动位于 experimental/base_comm/comm_mem/roce_mem.cc 与 experimental/base_comm/comm_mem/roce_mem.h:在 RoceRegedMemMgr::GetMemDesc 生成的内存描述符末尾追加本进程 getpid();GetParamsFromMemDesc 新增 uint32_t& pid 出参并从描述符末尾解析 PID;同时在头文件中新增 RemoteRdmaMemKey 结构体及其相等比较与 FNV-1a 哈希函数,将 remoteRdmaRmaBufferMgrs_ 的键由 EndpointDesc 改为 (EndpointDesc, pid) 组合键,使 MemoryImport/MemoryUnimport 能区分同一网卡上的不同远端进程。
主要改动
- 内存描述符追加并解析 PID:
GetMemDesc通过getpid()将本进程 PID 以字节形式追加到tempLocalMemDesc尾部;GetParamsFromMemDesc增加uint32_t& pid参数,从描述符末尾提取 PID,并将长度校验与EndpointDesc提取偏移统一调整为tailLen = sizeof(EndpointDesc) + sizeof(uint32_t)。 - 新增组合键
RemoteRdmaMemKey: 头文件中定义包含EndpointDesc endpointDesc与uint32_t pid的结构体,提供基于std::memcmp的operator==,并实现 64/32 位适配的 FNV-1a 哈希仿函数RemoteRdmaMemKeyHash。 - 远端内存管理器改以组合键索引:
remoteRdmaRmaBufferMgrs_由std::unordered_map<EndpointDesc, ...>改为std::unordered_map<RemoteRdmaMemKey, std::unique_ptr<RemoteRdmaRmaBufferMgr>, RemoteRdmaMemKeyHash>;MemoryImport与MemoryUnimport均以RemoteRdmaMemKey{endpointDesc, remotePid}进行查找、插入与删除,MemoryImport中新增打印远端 PID 的HCCL_INFO日志。


Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| experimental | ❌ (0/2)(You can also ask: 欧阳茜, 施秉辰, 胡林康, 林叶峰, 杨邵华) | ❌ (0/1)(You can also ask: 程祥乐, 颜业峰, 文学敏) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
hanjf, thanks for your pull request. All authors of the commits have signed the CLA. 👍


[MEDIUM] pid 作为远端进程唯一标识存在复用漂移风险,重启进程可能误拒导入或误删他人内存
第 34 行:uint32_t pid{0};
问题分析:RemoteRdmaMemKey 以 (endpointDesc, pid) 区分远端进程,pid 取自导出方 getpid()(roce_mem.cc:146)。Linux pid 是可复用的滚动编号:远端进程异常退出且未走 MemoryUnimport 时,本端 remoteRdmaRmaBufferMgrs_ 残留 key=(ep, pid) 条目;若新进程重启后拿到相同 pid 且 mmap 到与旧进程相同的地址区间(同二进制多次运行 VA 高度稳定),MemoryImport 中 Add(tempKey, ...) 会命中残留条目返回 HCCL_E_AGAIN,合法导入被误拒;反之框架延迟补发的 Unimport 会把新进程刚导入的同地址条目误删。容器/PID namespace 场景下不同远端容器进程 pid 撞号的概率进一步放大。
修复建议:
- 优先方案:导出侧改用进程生命周期内单调唯一且跨重启不重复的标识,如 pid + 进程启动时间戳(读 /proc/self/stat 第 22 字段),或直接复用通信域已有的全局唯一 ctx/comm id;
- 过渡方案:至少在 MemoryImport 的 Add 返回 false(HCCL_E_AGAIN 路径)时校验已存条目的 rkey 与本次 dto.rkey 是否一致(ExchangeRdmaBufferDto 含 rkey 字段),不一致说明是 pid 复用后的残留条目,应先清理旧条目再重新 Add,并在日志中告警;
- 若维持现状,须在 RemoteRdmaMemKey 的注释中明确记录「pid 复用场景下条目可能误命中」的边界假设,供部署评估。


[MEDIUM] key 维度扩展、加锁、空 Mgr 清理等行为变更无任何 UT 覆盖
第 207 行:HcclResult RoceRegedMemMgr::MemoryImport(const void* memDesc, uint32_t descLen, HcommMem* outMem)
问题分析:本 PR 引入三处行为变更——①remoteRdmaRmaBufferMgrs_ 的 key 从 EndpointDesc 扩展为 (EndpointDesc, pid);②MemoryImport/MemoryUnimport 新增 memMtx_ 互斥保护;③MemoryUnimport 在 Del 后对空 RemoteRdmaRmaBufferMgr 做 erase 清理(roce_mem.cc:273-275)。但 git diff 显示 test/ 目录零变更,PR 模板「补充的UT用例」栏也是空的。experimental/base_comm 参与编译链接(cpu_roce_endpoint.cc 直接构造 RoceRegedMemMgr),上述逻辑的正确性(尤其 Import/Unimport 的 key 对称性与清理时机)完全依赖人工验证,后续重构无回归防护。
修复建议:补充 UT 用例(建议放 test/ut/framework/next/comms/endpoints/reged_mems/ 下,仿 ut_roce_mem_test.cc 的 mockcpp 模式,对 experimental 版另建文件):
- 同 endpointDesc、不同 pid 的两次 MemoryImport,断言 remoteRdmaRmaBufferMgrs_ 生成两个独立 Mgr 条目、互不影响 Add/Del;
- MemoryUnimport 把某 Mgr 的最后一个条目删空后,断言该 remoteKey 从 map 中被 erase(size 变化用 #define private public 方式或新增计数接口断言);
- descLen 边界:descLen < sizeof(EndpointDesc)+sizeof(uint32_t) 时 GetParamsFromMemDesc 返回 HCCL_E_INTERNAL;
- memDesc 末 4 字节 pid 与 EndpointDesc 的拼接顺序往返一致性(GetMemDesc 生成 → GetParamsFromMemDesc 解析还原同一 pid 与 endpointDesc)。


您好,当前 PR 已超过 30 天未更新。如暂无合入需要,请及时关闭 PR;如仍有需要,请及时更新处理并推动检视合入。若 5 天内仍无更新,该 PR 将被自动关闭。


描述
变更类型
请选择本次引入的变更类型:
关联的Issue
测试
已完成的测试用例和场景:
1.
2.
补充的UT用例:
文档更新
合入检查