[BugFix] RDMA: retry ibv_post_send from bad_wr and drain CQ on failure - #8091
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8091 +/- ##
==========================================
Coverage ? 67.51%
==========================================
Files ? 475
Lines ? 66915
Branches ? 10321
==========================================
Hits ? 45178
Misses ? 18865
Partials ? 2872
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-07-02 11:54:02
📋 Review 摘要
PR 概述:修复 RDMA KV Cache ibv_post_send 失败后的重试位置和 CQ drain 逻辑
变更范围:fastdeploy/cache_manager/transfer_factory/kvcache_transfer/src/kvcache_rdma.cpp
影响面 Tag:[KVCache] [PD Disaggregation]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 Bug | fastdeploy/cache_manager/transfer_factory/kvcache_transfer/src/kvcache_rdma.cpp:1544 |
retry 时无归属地 drain 共享 CQ,可能消费其它发送路径等待的 CQE |
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | 失败后使用 poll_cq_with_timeout 导致每次 retry 最多阻塞 30 秒 |
✅ 已修复 |
📝 PR 规范检查
标题符合 [BugFix] Tag 规范。描述包含必填章节,但 Usage or Command、Accuracy Tests 未填写有效内容,Checklist 未按当前 PR 情况勾选;可直接使用以下完整描述:
PR 描述建议(点击展开,可直接复制)
## Motivation
生产环境中 KV Cache RDMA 传输出现间歇性 `ibv_post_send` 失败,错误为 `errno=36 (ENAMETOOLONG)`。该问题与 Send Queue 中 inflight WR 堆积、CQ 未及时消费有关,原重试逻辑会从 WR 链表头重新提交,可能重复提交已成功入队的 WR。
## Modifications
- `fastdeploy/cache_manager/transfer_factory/kvcache_transfer/src/kvcache_rdma.cpp`: 在 `post_send_with_retry` 中引入 `cur_wr`,失败后从 `bad_wr` 指向的第一个失败 WR 继续重试。
- 在重试前尝试 poll CQ,以释放已完成 WR 对应的 SQ slot。
## Usage or Command
N/A
## Accuracy Tests
N/A。本 PR 修改 RDMA KV Cache 传输失败重试路径,不改变模型计算逻辑或输出精度。
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [x] Provide accuracy results.
- [x] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.总体评价
当前修改解决了历史 review 中指出的阻塞式 retry 问题,但新增的 CQ drain 需要先避免跨调用消费 completion,否则并发 KV 传输下仍可能出现超时或误判失败。
There was a problem hiding this comment.
Pull request overview
该 PR 聚焦于修复生产环境 KV Cache RDMA 写入时 ibv_post_send 在 SQ 堆积场景下的重试失效问题,通过“从 bad_wr 续传”避免重复提交已入队 WR,并在失败重试前进行非阻塞 CQ drain 来尝试释放 SQ slot,从而提升在压力场景下的成功率与可恢复性。
Changes:
- 在
post_send_with_retry中引入cur_wr,失败后从bad_wr指向的 WR 继续重试,避免从链表头重复提交。 ibv_post_send失败时增加非阻塞ibv_poll_cq循环 drain CQ,尝试释放 SQ slot 后再 retry。- 增加注释解释为何不使用阻塞式
poll_cq_with_timeout来 drain。
| struct ibv_send_wr* cur_wr = wr_list; | ||
| do { | ||
| ret = ibv_post_send(ctx->qp, wr_list, &bad_wr); | ||
| ret = ibv_post_send(ctx->qp, cur_wr, &bad_wr); | ||
| if (ret == 0) { |
| { | ||
| struct ibv_wc wc_array[32]; | ||
| int n; | ||
| while ((n = ibv_poll_cq(ctx->cq, 32, wc_array)) > 0) { | ||
| } | ||
| } |
|
✅ Cherry-pick successful! Created PR: #8093 |
|
Thanks for your contribution! |
Motivation
生产环境中 KV Cache RDMA 传输时出现报错:
errno 36 (ENAMETOOLONG) 在 RDMA 上下文中表示 ibv_post_send 向 Send Queue(SQ)提交 Work Request(WR)失败,根本原因是 SQ 堆积——inflight WR 累积速度超过 CQ 消费速度,导致 SQ 无可用 slot。
原有重试逻辑存在两个问题:
Modifications
kvcache_rdma.cpp — post_send_with_retry
为什么不用 poll_cq_with_timeout:
ibv_post_send 失败并不保证 CQ 里有可消费的 CQE(如参数/QP 状态类同步错误,或 bad_wr 之前的 WR 均为无信号 WR 尚未产生 completion)。使用 30s 超时的阻塞式 poll 会导致每次 retry 卡住最长 30s,7 次重试共阻塞最多 210 秒。
修改前后对比
Usage or Command
Accuracy Tests
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.