io: SQ flow control rework — diagnostics, SqController, session lifecycle#305
Open
maning00 wants to merge 6 commits into
Open
io: SQ flow control rework — diagnostics, SqController, session lifecycle#305maning00 wants to merge 6 commits into
maning00 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Reworks RDMA send-queue (SQ) flow control and failure handling by introducing a per-endpoint SqController, expanding SQ/CQE diagnostics for SQ-full timeouts, and tightening session/endpoint lifecycle behavior when endpoints become terminal-degraded.
Changes:
- Introduces
SqControlleras the owner of SQ credit reservation/release, degraded state, and waiter coordination (with resume watermark hysteresis). - Refactors
SubmissionLedgerAPIs to return fullSubmissionRecords and adds orphan extraction/cancel APIs for exactly-once failure convergence. - Updates session caching/liveness behavior to evict unhealthy sessions and avoid allocating terminal-degraded endpoints; adds targeted unit tests.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/cpp/io/test_engine.cpp | Adds/extends unit tests for SubmissionLedger, SqController, orphaning helper, and session Alive() behavior. |
| src/io/rdma/ledger.cpp | Updates ledger APIs (InsertOrphaned, ReleaseByCqe, CancelTentative, ExtractOrphanedRecords, RecordCount). |
| src/io/rdma/executor.hpp | Replaces split return type with a richer WorkSplit (worker + ep + range). |
| src/io/rdma/executor.cpp | Implements round-robin “small batch” work splitting to avoid pinning small transfers to worker/ep 0. |
| src/io/rdma/common.hpp | Adds SqController, diagnostics structs/enums, extends EpPair, and declares SQ/CQE diagnostic + orphaning helpers. |
| src/io/rdma/common.cpp | Implements SqController, SQ-full diagnostic hinting, signal cadence env var, and unified orphaning/failure helper. |
| src/io/rdma/backend_impl.hpp | Switches session cache to shared_ptr and adds unhealthy-session invalidation helper. |
| src/io/rdma/backend_impl.cpp | Filters terminal-degraded endpoints for new sessions, adds CQ polling diagnostics, terminal CQE handling, session Alive() checks, and cache invalidation of unhealthy sessions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
SQ fullhint to print worker-local QP / sessionqpPerTransfer/numWorkerThreadsseparately, and add five per-EP CQE diagnostic counters (lastPollAttemptTime/lastNonEmptyCqeTime/recentCqeCount/recentBatchReleaseWr/ ledgerRecordCount) into the timeout hint so operators can triage CQ-poll stall vs slow drain vs submission burst from a single error line. Adds optionalMORI_IO_SQ_SIGNAL_INTERVAL_WR(default 0 = off) for in-call signal cadence, and aSplitWorksmall-batch round-robin that no longer pins single-entry transfers to worker 0 / global ep[0].SqControlleras the single owner of SQ credits / waiters / degraded state, with CAS + epoch-protectedcondition_variablewait andMORI_IO_SQ_RESUME_WATERMARK_WRhysteresis.SubmissionLedgerno longer mutatessqDepth; newCancelTentativeandExtractOrphanedRecordsreturn full records so callers can do exactly-once meta failure convergence. All four failure paths (TryReserveSqDepthfail,RecheckBeforePostfail,ibv_post_sendfail, fatal CQE) converge through one helperMovePendingUnsignaledToOrphanedForEndpointthat releases any held submit guard, takes unique recovery guard, marks endpoint terminal degraded, inserts an orphaned record, and fails unique metas. Fatal CQE white list:IBV_WC_RETRY_EXC_ERR / RNR / LOC_QP_OP_ERR / REM_ACCESS_ERR / REM_INV_REQ_ERR / FATAL_ERR;IBV_WC_WR_FLUSH_ERRstays as flush cascade only.RdmaBackendSession::Alive()reflects any endpoint terminal degraded;sessionCacheholdsshared_ptrand invalidates unhealthy entries on cache hit/miss;RdmaManager::CountEndpoint/GetAllEndpointfilter out terminal-degradedEpPairso new sessions only consume healthy endpoints (BuildRdmaConnrefillsqpPerTransferif needed).SqControllergrows a softqueuedDepth_(admitted but not yet posted) plusTryAcquireAdmission/ReleaseAdmission/WaitForAdmissionChangeso the executor reserves SQ slots before submitting work to a worker; under sustained SQ pressure callers block on the admission cv instead of failing on a worker-thread reserve timeout. New move-only RAIIAdmissionTokenis owned by eachTask— even on worker shutdown the queued tasks release their admission and complete withERR_BAD_STATE.MultithreadExecutor::RdmaBatchReadWriteWithAdmissionis the new dispatcher whenMORI_IO_SQ_EXECUTOR_ADMISSION=1; falls back to the legacySplitWorkpath when disabled (default). Three split policies viaMORI_IO_SQ_SPLIT_POLICY={static,least_loaded,capacity}:statickeeps the Phase 1A round-robin;least_loadedpicks the active QP with the lowestDepth + QueuedDepth(skipping degraded QPs);capacity(gated behindMORI_IO_SQ_ENABLE_EXPERIMENTAL_CAPACITY=1) splits a large batch by per-QP free slots. Admission-side WR estimation reuses a newEstimateMergedWrCounthelper (SGL merging aware) shared with the worker post path. Five new counters inSqCqeDiagnostics(executorAdmissionWaitCount/executorAdmissionWaitUs/executorAdmissionTimeoutCount/leastLoadedSelectionCount/queuedWrHighWatermark) appear in the SQ-full timeout hint so operators can confirm the gate is actively backpressuring upstream callers.Behavior summary
MORI_IO_SQ_BACKOFF_TIMEOUT_US, exactly-once orphan convergence, terminal-degradedEpPairfiltering,shared_ptrsession cache with unhealthy invalidation. SQ-full pressure still surfaces as user-visible errors when the backoff window closes.MORI_IO_SQ_EXECUTOR_ADMISSION=1): user thread blocks in the admission gate until the chosen QP has effective free slots; sustained pressure produces tail latency rather than errors (errors only when the admission deadline expires).New env vars (defaults are safe — Phase 3 is opt-in)
MORI_IO_SQ_BACKOFF_TIMEOUT_US10000(10 ms)MORI_IO_SQ_SIGNAL_INTERVAL_WR0(off)MORI_IO_SQ_RESUME_WATERMARK_WR0(off)MORI_IO_SQ_EXECUTOR_ADMISSIONfalseMORI_IO_SQ_ADMISSION_TIMEOUT_US1000000(1 s)MORI_IO_SQ_ADMISSION_RESUME_WATERMARK_WR2048MORI_IO_SQ_ADMISSION_WAIT_SLICE_US100MORI_IO_SQ_ADMISSION_CHUNK_WR0(auto)MORI_IO_SQ_ADMISSION_MAX_CHUNKS_PER_CALL0(=activeQps)MORI_IO_SQ_SPLIT_POLICYstaticstatic/least_loaded/capacityMORI_IO_SQ_ENABLE_EXPERIMENTAL_CAPACITYfalsecapacitypolicyTest plan
tests/cpp/io/test_engine(24/24 passing locally):submission_ledger_basic(extended forReleaseByCqe/CancelTentative/ExtractOrphanedRecords)sq_controller_reserve_release_wait(CV wakeup + resume watermark hysteresis)sq_controller_terminal_degraded(waiter wakes on degrade;ReleaseDrainedOrphaneddoes not restore admission)sq_controller_recheck_rolls_back(RecheckBeforePostrollback after degrade)sq_controller_admission_counters(admission acquire/release/WaitForAdmissionChange, hard + soft credit interaction)sq_controller_admission_degraded(terminal-degraded SQ rejects admission)sq_controller_admission_mark_degraded_wakes(MarkDegradedwakes admission waiters)admission_token_move_releases_once(move-only token RAII + idempotentRelease())worker_shutdown_drains_tokens_and_promises(worker shutdown releases queued tokens and completes promises withERR_BAD_STATE)pending_unsignaled_recheck_failure_orphans(1-EP helper path)pending_unsignaled_reserve_failure_orphans(2-EP helper path, multi-meta accumulation)pending_unsignaled_orphaning_closes_admission_before_recovery(admission closed before recovery guard)rdma_session_alive_checks_terminal_sqconc=1024/2048/4096regression, two configurations on the same workload:MORI_IO_SQ_BACKOFF_TIMEOUT_US=5000000, expect SQ-full timeout count to drop ~10× and the per-EP diagnostic counters in the timeout hint to classify residual stalls.MORI_IO_SQ_EXECUTOR_ADMISSION=1 MORI_IO_SQ_ADMISSION_TIMEOUT_US=2000000 MORI_IO_SQ_BACKOFF_TIMEOUT_US=1000000, expect SQ-full errors to approach 0 withexecutorAdmissionWaitCount > 0confirming the gate is actively backpressuring upstream.MORI_IO_SQ_SPLIT_POLICY=least_loadedA/B vsstaticat4QP/4Worker conc=4096— track per-QPDepthdistribution stddev andleastLoadedSelectionCount.MORI_IO_SQ_SIGNAL_INTERVAL_WR=64/128/256cadence matrix once thebackoff=1s, interval=0baseline is captured.4QP/4Worker conc=4096vs. baseline (no exclusive-guard fallback enabled).Follow-ups (separate PRs)
Alive()=false → InvalidateUnhealthySessions → fresh session, plusshared_ptrlifetime test under in-flight transfer + terminal degrade.RouteTableGC for terminal-degradedEpPair(use_count-guarded).RdmaManager::SearchGPU-branch fall-through fix (separate narrower change).least_loaded/capacitypolicy benchmark under non-uniform NIC link speeds (e.g., one slow rank in an 8-rank × 8-NIC node).MORI_IO_SQ_EXECUTOR_ADMISSION=1+MORI_IO_SQ_SPLIT_POLICY=least_loadedonce production validation is captured.