#4807·valkey

[NEW] Grow the RDMA receive window on the same MR instead of locking it at rdma-rx-size

Author: quanyeyangCreated Sep 30, 2026Updated Sep 30, 2026
Labelsenhancement

The problem/use-case that the feature addresses

Valkey over RDMA does not have a TCP-style sliding window. The peer RDMA_WRITE_WITH_IMMs into a pinned MR that was registered at connect time. The remaining space is announced_length - offset. When that length is exhausted, the receiver must send RegisterXferMemory on the same QP as the data. The sender then sits in valkeyRdmaWrite until a new (addr, length, rkey) shows up on the CQ.

Today rdma-rx-size (default 1 MiB, immutable) is both the MR size and the announced window for the life of the connection. Re-announce rate is therefore fixed:

reannounces per GiB ≈ 1 GiB / rdma-rx-size
→ 1024 / GiB at 1 MiB, 64 / GiB at 16 MiB

That cost is not theoretical when the value size is in the same ballpark as the window. One SET fills the MR; the next SET cannot be posted until the control message comes back on the same QP. Raising rdma-rx-size for everyone avoids the stall but pins that much memory on every connection from t=0 (ibv_reg_mr + RLIMIT_MEMLOCK). The use case is: keep the 1 MiB default, and let a connection enlarge the announced window when the sender is actually blocked on a full window.

Description of the feature

  • New immutable config rdma-rx-max-size (0 = current static behaviour, compatible with older peers). Must be 0 or ≥ rdma-rx-size, cap 16 MiB.
  • At connect, register the MR once at max-size capacity. Announce rdma-rx-size as the initial window (same rkey).
  • Negotiate a feature bit (RX_GROW_WINDOW) plus the capacity. The client pre-sizes its staging buffer once. Older servers reply features=0 and stay static.
  • Sender sets IMM bit 31 when a WRITE exactly fills the current window and more bytes remain in obuf (the next loop iteration would block). Un-negotiated peers must not set the bit (old servers treat the whole IMM as a length).
  • At the safe boundary rx.pos == rx.length (every posted byte has been consumed), the server may double rx.length up to capacity and re-announce the same addr/rkey. v1: 2 consecutive pressured windows to grow, then 4 windows of cooldown. Grow only, no shrink.

Default remains static. Enabling max-size is opt-in.

Alternatives you've considered

  1. Just set rdma-rx-size 16mb. Gets the large-window throughput, but every connection pins 16 MiB from connect, and the value cannot change later without a reconnect (MR is registered at connect). This is the ceiling the experiment compares against, not a substitute for an opt-in grow path that leaves the default at 1 MiB.
  2. Re-register a larger MR on the fly. Would change rkey while WRs may still refer to the old region. We deliberately grow only the announced length on one MR.
  3. A second QP for control. Larger protocol change; not needed to test whether announced-window size is on the critical path.

Additional information

Test environment

Item Value
Commit 371d921c (experiment/rdma-rx-dynamic-window)
NIC Alibaba eRDMA erdma_0 (not software RXE)
Bind 10.0.0.144:16379
CPU Xeon Platinum 8475B, 4 cores / 8 threads, 1 NUMA node
Pinning server taskset -c 0, --io-threads 1; benchmark taskset -c 2, --threads 0
Clients 2 connections, pipeline 16, SET only, keepalive
Method Fixed wall-clock phases on persistent QPs (--data-size-phases), not -n
Repeats n = 1

Server and client are on different physical cores (SMT siblings are 0-1 and 2-3) so the comparison is the RX window, not vCPU contention. save/AOF off; leftover processes on the NIC stopped.

Phases (same sequence in every cell):

4KiB:20s, 64KiB:20s, 1MiB:30s, 4MiB:30s, 64KiB:30s, 4KiB:60s

Cells

One new server per cell (changing RX size requires a new MR).

Cell rdma-rx-size rdma-rx-max-size Meaning
A 1 MiB 0 Status quo: window locked at 1 MiB
B 1 MiB 16 MiB This proposal: grow announced length on the same MR
C 16 MiB 0 Ceiling: 16 MiB announced from connect

A vs B is the feature. C is the oracle: if the QP had been allowed a large window, how much of that does B recover. The claim is not “16 MiB is faster than 1 MiB in the abstract”; it is that the 1 MiB lock is expensive when value size ≈ window, and that growing the announced window on the same QP picks up the large-window result without changing the default rdma-rx-size.

Primary metrics: payload Gbps; stall_ratio = tx_wait_ns / wall_s (sender blocked waiting for RegisterXferMemory); reannounces_per_gib (must equal 1 GiB / announced_window if the model is right).

Harness: utils/rdma-rx-phase-benchmark.sh --transport physical --bind 10.0.0.144 --compare-dynamic --clients 2 --pipeline 16 --pin-server 0 --pin-client 2. Raw data: rdma-phase-results/20260930-211735/. Zero reconnects, no RDMA: FATAL.

Results

reann/GiB is ~1024 with a 1 MiB announced window and ~64 with 16 MiB.

Phase Value A static 1 MiB B dynamic 1→16 MiB C static 16 MiB
Gbps / stall / reann/GiB / p50
0 4 KiB 14.23 / 4.1% / 1024 / 0.07 ms 14.22 / 0.26% / 65 / 0.07 ms 14.23 / 0.26% / 64 / 0.07 ms
1 64 KiB 14.18 / 33.5% / 1024 / 1.03 ms 13.63 / 2.7% / 64 / 1.19 ms 13.61 / 2.8% / 64 / 1.18 ms
2 1 MiB 11.46 / 16.7% / 1024 / 23.1 ms 12.87 / 6.3% / 64 / 20.4 ms 12.14 / 8.5% / 64 / 21.7 ms
3 4 MiB 9.03 / 12.7% / 1024 / 117 ms 9.09 / 11.8% / 64 / 117 ms 8.94 / 12.2% / 64 / 118 ms
4 64 KiB 14.26 / 33.6% / 1024 / 1.04 ms 13.63 / 2.7% / 64 / 1.19 ms 13.67 / 2.8% / 64 / 1.19 ms
5 4 KiB 14.34 / 4.2% / 1024 / 0.07 ms 14.34 / 0.26% / 64 / 0.07 ms 14.34 / 0.26% / 64 / 0.07 ms
mermaid
xychart-beta
    title "1 MiB SET payload (Gbps) — the phase where value ≈ default window"
    x-axis ["A static 1MiB", "B dynamic 1→16", "C static 16MiB"]
    y-axis "Gbps" 8 --> 14
    bar [11.46, 12.87, 12.14]
mermaid
xychart-beta
    title "Sender stall waiting for RegisterXferMemory (1 MiB SET phase)"
    x-axis ["A static 1MiB", "B dynamic 1→16", "C static 16MiB"]
    y-axis "stall_ratio" 0 --> 0.2
    bar [0.167, 0.063, 0.085]

On the 1 MiB phase, A has tx_wait_count ≈ requests (41378 vs 41376): one SET fills the window, the next waits on the same QP. B vs A: +12.3% Gbps, stall 16.7% → 6.3%, p50 23.1 → 20.4 ms. B tracks C (12.87 vs 12.14 Gbps). That is the lock we care about.

Other phases:

  • 4 KiB: ~14.2 Gbps on all three. Stall still drops ~16× (1024 → 64 reann/GiB), but the main thread is already at the protocol ceiling.
  • 64 KiB: stall 33% → 3%, Gbps slightly lower on B/C. Bottleneck has left the re-announce path.
  • 4 MiB: ~9 Gbps on all three. Two 4 MiB memcpys on the main thread dominate; stall stays ~12% even at 16 MiB (consume rate < fill rate).

Mechanism counters (INFO rdma at end of cell)

Counter A B C
rx_window_reannounce_count 298783 18815 18609
rx_window_grow_count 0 8 (2 QPs × 1→2→4→8→16) 0
rx_window_grow_request_count 0 18813 0
rx_window_grow_suppressed_count 0 18773 (already at cap) 0
rx_window_peak_size — 16 MiB —
client tx_window_peak 1 MiB 16 MiB 16 MiB
rx_mr_register_count 5 5 5

Same rx_mr_register_count in all cells: growth does not re-register. B hits a 16 MiB announced window during phase 0 (sustained pipeline fills a 1 MiB MR even with 4 KiB SET). After that B and C are the same announced window, which is why they stay aligned. v1 does not shrink.

mermaid
sequenceDiagram
    participant C as client (CPU 2)
    participant QP as same QP
    participant S as server (CPU 0)
    C->>QP: RDMA_WRITE_WITH_IMM into announced RX MR
    Note over C,S: offset reaches announced length
    C->>C: valkeyRdmaWrite blocks (tx_wait_ns)
    S->>S: pos == length, maybe double rx.length
    S->>QP: RegisterXferMemory (same addr/rkey, new length)
    QP->>C: new window
    C->>QP: next WRITE

What this does not show

  • n = 1, one NIC, SET-only. The direction on the 1 MiB phase is usable; treat +12% as a single-run delta, not a CI.
  • Enabling rdma-rx-max-size still ibv_reg_mrs the full capacity at connect. This data is about announced length and same-QP stall, not “B pins less memory than C”.
  • No shrink; an idle connection that grew stays at the large announced window (MR was already at capacity).

Open questions

  • Is v1 grow policy (threshold 2, cooldown 4, no shrink) acceptable, or should growth require something closer to “value/fill rate warrants a larger window” so tiny SET pipelines do not race to cap?
  • Should the MR itself start at rdma-rx-size and grow (new rkey), to make max-size cheaper on connections that never pressure the window?