RDMA Explained: How Remote Direct Memory Access Works
Remote Direct Memory Access (RDMA) is a foundational technology in high-performance computing (HPC), distributed storage, and modern AI infrastructure. It enables network adapters to transfer data directly between registered memory regions on different machines, significantly reducing CPU overhead, memory-copy operations, and communication latency.
Among the available RDMA transport technologies, RoCEv2 (RDMA over Converged Ethernet v2) has become an important option for deploying RDMA over standard Ethernet and IP networks. It combines the performance advantages of RDMA with familiar data center networking infrastructure, making it suitable for large-scale GPU clusters, distributed training, cloud storage, and high-performance computing.
Unlike conventional TCP/IP communication, where data typically passes through the operating system’s networking stack, RDMA allows the NIC to perform data movement directly between application memory buffers using DMA.
The host CPU still participates in operations such as memory registration, work-request submission, connection management, and completion processing. However, the actual data-transfer path can bypass much of the conventional CPU-driven networking stack.
This article provides a technical walkthrough of how RDMA works, covering memory registration, Protection Domains, Queue Pairs, connection establishment, RoCEv2 packet encapsulation, and the complete RDMA Write operation.
🚀 What Is RDMA and Why Does It Matter? #
RDMA allows one machine to access memory on another machine without requiring the remote CPU to process every individual data transfer.
Depending on the operation, an application can remotely read or write a registered memory region through the RDMA NIC.
For example, when a client performs an RDMA Write, its NIC reads data from a local registered buffer and sends it to the destination NIC. The destination NIC validates the remote memory access and writes the data directly into the target buffer.
This avoids the conventional sequence of receiving data into kernel-managed network buffers, copying it into application memory, and involving the remote CPU in every stage.
The result is lower CPU utilization, fewer memory copies, and reduced communication latency.
Traditional Networking vs. RDMA #
In conventional socket-based networking, a typical data-transfer path involves:
- The application prepares data in user-space memory.
- The operating system processes the network transmission request.
- The kernel networking stack prepares packets.
- The NIC transmits the packets.
- The receiving NIC delivers the data into host memory.
- The operating system processes the received data and makes it available to the application.
RDMA significantly reduces this processing overhead.

With RDMA, the application posts a Work Request to the NIC. The NIC uses its DMA capabilities and registered-memory metadata to transfer data directly between the appropriate memory regions.
Major RDMA Use Cases #
RDMA is particularly valuable in workloads where communication performance directly affects application throughput.
- AI and machine learning: Distributed GPU training, gradient synchronization, and collective communication.
- High-performance computing: Low-latency communication between compute nodes in supercomputers and HPC clusters.
- Distributed storage: High-performance storage platforms such as Ceph, DAOS, and NVMe over Fabrics (NVMe-oF).
- Cloud infrastructure: High-throughput communication between virtualized workloads and storage services.
- Real-time analytics: Low-latency data exchange between distributed processing nodes.
For a practical example of RDMA optimization in distributed AI infrastructure, ByteDance’s ByteExpress architecture explores memory-registration reuse, QP multiplexing, and software-assisted traffic scheduling to improve large-scale AI inference performance.
RDMA Transport Technologies #
Several technologies implement RDMA using different networking infrastructures:
| Technology | Network Infrastructure | Characteristics |
|---|---|---|
| InfiniBand | Dedicated InfiniBand fabric | Native RDMA transport with specialized switches and adapters |
| RoCEv1 | Ethernet Layer 2 | RDMA over Ethernet without IP routing |
| RoCEv2 | Ethernet and IP networks | UDP/IP encapsulation with support for routed networks |
| iWARP | TCP/IP | RDMA over TCP-based transport |
RoCEv2 is especially relevant to modern data centers because it allows RDMA communication to operate across IP-based Ethernet fabrics.
Understanding PFC and ECN in RoCEv2 Networks #
RoCEv2 uses UDP/IP encapsulation, but reliable RDMA communication requires appropriate congestion handling and packet-loss recovery.
Many traditional RoCEv2 deployments use a carefully configured low-loss or lossless Ethernet fabric. Two important mechanisms are:
Priority Flow Control (PFC)
PFC provides link-level flow control for individual traffic priorities. When a switch buffer approaches a configured congestion threshold, it can send pause frames to temporarily stop traffic belonging to the affected priority.
This helps prevent packet drops caused by buffer exhaustion, although poorly configured PFC can introduce head-of-line blocking and congestion propagation.
Explicit Congestion Notification (ECN)
ECN allows network devices to mark packets when congestion is detected rather than relying exclusively on packet drops.
The receiving side can generate congestion feedback, allowing the sender to adjust its transmission rate.
Algorithms such as DCQCN use ECN feedback to regulate RoCEv2 traffic.
Importantly, PFC and ECN serve different purposes. PFC provides link-level backpressure, while ECN enables end-to-end congestion feedback. RoCEv2 itself does not require every Ethernet network to enable PFC, and modern RDMA implementations can also be designed to operate over lossy networks.
For example, ByteDance’s veRoCE explores how RDMA can maintain reliability over lossy Ethernet fabrics through enhanced retransmission, packet sequencing, and out-of-order delivery mechanisms.
🔧 RDMA Workflow Overview #
A typical RDMA Write operation between two machines involves four major stages:
- Memory allocation and registration.
- Queue Pair (QP) creation.
- RDMA connection initialization.
- RDMA Write execution.
For clarity, this guide uses two compute nodes:
- Client Compute Node (CCN): The machine initiating the RDMA Write operation.
- Server Compute Node (SCN): The machine providing the destination memory buffer.
The overall workflow is:
Client Compute Node (CCN) Server Compute Node (SCN)
+-------------------------+ +-------------------------+
| Application | | Application |
| | | |
| Source Buffer | | Destination Buffer |
+------------+------------+ +------------+------------+
| |
v v
+-------------------------+ +-------------------------+
| Client RDMA NIC | | Server RDMA NIC |
| | | |
| Send Queue (SQ) | | Memory Protection |
| DMA Read | | R_Key Validation |
| Packet Generation | | DMA Write |
+------------+------------+ +------------+------------+
| ^
| |
+------------ RoCEv2 Network ------------+
Before the transfer can begin, both endpoints must establish their memory-access permissions and connection parameters.
🧩 Step 1: Memory Allocation and Registration #
RDMA NICs cannot safely access arbitrary application memory.
Before a memory buffer can participate in RDMA operations, it must generally be registered with the RDMA device.
Memory registration establishes the relationship between an application memory region, the RDMA protection mechanism, and the hardware’s DMA translation and access-control metadata.
1.1 Create a Protection Domain (PD) #
A Protection Domain (PD) is an RDMA resource that groups related communication objects and memory resources.
The PD provides an access-control boundary between:
- Queue Pairs (QPs).
- Memory Regions (MRs).
- Other associated RDMA resources.
A QP and an MR generally need to belong to compatible protection domains for the NIC to authorize operations involving that memory region.
In the Linux RDMA Verbs API, a PD can be allocated with:
struct ibv_pd *pd;
pd = ibv_alloc_pd(context);
if (!pd) {
perror("ibv_alloc_pd");
return -1;
}Here, context represents an initialized RDMA device context.
1.2 Register a Memory Region #
After allocating application memory, the application registers it with the RDMA device.
A typical operation uses ibv_reg_mr():
struct ibv_mr *mr;
mr = ibv_reg_mr(
pd,
buffer,
buffer_size,
IBV_ACCESS_LOCAL_WRITE |
IBV_ACCESS_REMOTE_WRITE
);
if (!mr) {
perror("ibv_reg_mr");
return -1;
}The registration operation associates the memory region with the specified PD and establishes the permissions required for local and remote access.
The access flags have the following meanings:
| Access Flag | Description |
|---|---|
IBV_ACCESS_LOCAL_WRITE |
Allows the local NIC to write into the registered memory |
IBV_ACCESS_REMOTE_WRITE |
Allows a remote RDMA peer to write into the memory |
IBV_ACCESS_REMOTE_READ |
Allows a remote RDMA peer to read from the memory |
IBV_ACCESS_REMOTE_ATOMIC |
Allows supported remote atomic operations |
Local read access is normally enabled by default through the Verbs interface. Additionally, remote write and remote atomic permissions require local write permission on the memory region.
1.3 L_Key and R_Key #
After successful memory registration, the RDMA device provides two important access keys:
L_Key (Local Key)
The local key is used by the local NIC to validate access to a registered buffer when the application posts a work request.
It is associated with the local scatter/gather entry (SGE).
R_Key (Remote Key)
The remote key allows another RDMA endpoint to access the registered memory region, subject to the registered permissions and address-range restrictions.
The remote application must obtain the R_Key and use it when posting an appropriate RDMA operation.
For example:
uint32_t local_lkey = mr->lkey;
uint32_t remote_rkey = mr->rkey;The two keys serve different purposes:
| Key | Used By | Purpose |
|---|---|---|
| L_Key | Local RDMA NIC | Validate local buffer access |
| R_Key | Remote RDMA NIC | Authorize remote memory access |
An R_Key alone does not provide unrestricted access to the machine’s memory. The NIC also enforces the associated memory permissions and registered address boundaries.
1.4 Example: Client and Server Memory Registration #
In our example:
Client Compute Node
The client registers its source buffer for local NIC access.
The NIC uses the L_Key to validate the source memory when performing DMA reads for transmission.
Server Compute Node
The server registers its destination buffer with remote write permission.
The server communicates the appropriate virtual address and R_Key to the client.
The client then uses these values when constructing its RDMA Write Work Request.

The memory registration stage is fundamental to RDMA security and performance. It allows the NIC to perform DMA efficiently while restricting access to explicitly registered memory regions.
🧱 Step 2: Queue Pair (QP) Creation #
A Queue Pair (QP) is one of the fundamental building blocks of RDMA communication.
It provides the work queues through which applications submit communication operations to the RDMA NIC.
A QP consists of two primary queues:
- Send Queue (SQ): Stores outgoing work requests.
- Receive Queue (RQ): Stores receive buffers posted by the application.
Completion Queues are separate RDMA objects associated with QPs. A QP has a send CQ and a receive CQ, which may reference the same CQ. Completion Queues can also be shared by multiple QPs.
2.1 Send Queue (SQ) #
The Send Queue contains operations submitted by the application.
Common operations include:
- RDMA Write
- RDMA Write with Immediate
- RDMA Read
- Send
- Send with Immediate
- Supported atomic operations
When an application submits a Work Request, the RDMA NIC retrieves and processes the corresponding Work Queue Element (WQE).
2.2 Receive Queue (RQ) #
The Receive Queue contains buffers that the application makes available for incoming receive operations.
For conventional Send/Receive communication, the receiver must post sufficient receive buffers before incoming messages can be consumed.
An important distinction is that ordinary one-sided RDMA Write and RDMA Read operations do not consume a remote Receive Queue entry.
However, RDMA Write with Immediate generates a receive completion at the remote endpoint and requires an appropriate posted receive buffer.
2.3 Completion Queue (CQ) #
The Completion Queue records the completion status of submitted RDMA operations.
When a Work Request completes, the NIC may generate a Work Completion (WC), which becomes available as a Completion Queue Entry (CQE).
The application can retrieve completion information through polling or completion-channel notifications.
Completion processing allows the application to determine whether an operation succeeded or failed.
Not every Work Request necessarily generates a CQE. For example, applications can use unsignaled send requests to reduce completion-processing overhead.
2.4 Creating a Queue Pair #
A QP is associated with a Protection Domain and references its Send and Receive Completion Queues.
A simplified Linux Verbs example looks like this:
struct ibv_qp_init_attr qp_init_attr = {0};
qp_init_attr.send_cq = send_cq;
qp_init_attr.recv_cq = recv_cq;
qp_init_attr.qp_type = IBV_QPT_RC;
qp_init_attr.cap.max_send_wr = 128;
qp_init_attr.cap.max_recv_wr = 128;
qp_init_attr.cap.max_send_sge = 1;
qp_init_attr.cap.max_recv_sge = 1;
struct ibv_qp *qp;
qp = ibv_create_qp(pd, &qp_init_attr);
if (!qp) {
perror("ibv_create_qp");
return -1;
}The example creates a Reliable Connected (RC) QP.
RC is commonly used when applications require reliable, ordered communication between two connected endpoints.
2.5 QP Attributes and Identifiers #
A QP has several important attributes:
| Attribute | Description |
|---|---|
| QP Number (QPN) | Identifies the QP within its local RDMA device |
| QP Type | Specifies the communication service type |
| PD | Protection Domain associated with the QP |
| Send CQ | Completion Queue for outgoing operations |
| Receive CQ | Completion Queue for incoming operations |
| SQ | Queue for outgoing Work Requests |
| RQ | Queue for incoming receive buffers |
| P_Key Index | Selects a local partition-key table entry where applicable |
A QP number is a 24-bit identifier.
The P_Key field is part of the InfiniBand transport header and is also present in RoCEv2 packets. However, it should not be confused with a VXLAN VNI or treated as a general-purpose Ethernet network-isolation mechanism. InfiniBand partition-management semantics are not equivalent to Ethernet VLAN or VXLAN segmentation.

🔗 Step 3: RDMA Connection Initialization #
Before two RC QPs can exchange data, their connection parameters must be configured consistently.
These parameters include:
- Local and remote QP numbers.
- Packet Sequence Numbers (PSNs).
- Address information.
- Path MTU.
- Connection and retry parameters.
- Relevant memory and access configuration.
When applications use the RDMA Connection Manager (RDMA CM), connection establishment commonly follows a three-message sequence:
- REQ (Request)
- REP (Reply)
- RTU (Ready to Use)
This is the connection-management handshake, not a mandatory handshake for every RDMA programming model. Applications can also configure QP connections directly through the Verbs interface.
3.1 REQ: Connection Request #
The initiating node sends a connection request to the remote endpoint.
The request carries connection information required to establish the communication relationship.
Relevant information can include:
- Initiator QP information.
- Starting Packet Sequence Number.
- Connection parameters.
- Path and addressing information.
- Optional application-specific private data.
For RoCEv2, GID and associated IP-network addressing information are important parts of path configuration.
3.2 REP: Connection Reply #
The remote endpoint processes the request and sends a reply.
The response provides the information required by the initiating endpoint to configure its corresponding QP.
This allows both sides to establish the necessary connection parameters.
3.3 RTU: Ready to Use #
The initiating endpoint sends the final Ready to Use message.
At this stage, the connection-management exchange establishes that both endpoints have progressed through the connection setup procedure.
The application or RDMA CM coordinates the necessary QP configuration and transitions.
3.4 QP State Transitions #
An RC QP normally progresses through the following states:
RESET
|
v
INIT
|
v
RTR
|
v
RTS
These states represent:
| State | Meaning |
|---|---|
| RESET | Newly created or reset QP |
| INIT | Initialized QP; basic access configuration is established |
| RTR | Ready to Receive |
| RTS | Ready to Send |
The transitions require specific QP attributes.
RESET → INIT
The application configures basic parameters such as:
- Protection and access flags.
- Physical port.
- P_Key table index where applicable.
INIT → RTR
The application configures receive-side connection parameters, including:
- Address vector.
- Destination QP number.
- Path MTU.
- Receive-side PSN.
RTR → RTS
The application configures send-side parameters, including:
- Send-side PSN.
- Retry count.
- RNR retry configuration.
- Timeout and outstanding RDMA operation limits where applicable.
Once the QP reaches RTS, it is ready to process outgoing Work Requests.

At this point, the client and server have established the communication context required for RDMA data transfer.
📤 Step 4: Performing an RDMA Write Operation #
With memory regions registered and the QP in the appropriate state, the application can submit an RDMA Write operation.
RDMA Write is a one-sided operation: the initiating application specifies the remote memory location, while the remote CPU does not need to process the individual data-transfer request.
4.1 Posting a Work Request #
The client submits a Work Request to its Send Queue.
An RDMA Write Work Request contains several important fields:
| Field | Description |
|---|---|
| Opcode | Identifies the operation as RDMA Write |
| Local Buffer Address | Starting address of the source memory |
| L_Key | Validates local memory access |
| Remote Address | Target virtual address on the remote node |
| R_Key | Authorizes remote memory access |
| Length | Number of bytes to transfer |
A simplified example:
struct ibv_sge sge = {
.addr = (uintptr_t)local_buffer,
.length = transfer_size,
.lkey = local_mr->lkey
};
struct ibv_send_wr wr = {0};
wr.wr_id = 1;
wr.sg_list = &sge;
wr.num_sge = 1;
wr.opcode = IBV_WR_RDMA_WRITE;
wr.send_flags = IBV_SEND_SIGNALED;
wr.wr.rdma.remote_addr = remote_addr;
wr.wr.rdma.rkey = remote_rkey;
struct ibv_send_wr *bad_wr = NULL;
if (ibv_post_send(qp, &wr, &bad_wr)) {
perror("ibv_post_send");
return -1;
}This example assumes that:
- The local buffer has already been registered.
- The remote endpoint has registered its destination memory.
- The client has obtained the remote address and R_Key.
- The QP has reached RTS.
- The memory permissions allow the requested operation.
The IBV_SEND_SIGNALED flag requests a completion entry for this Work Request.
Without this flag, a successful operation does not necessarily generate an individual completion entry.
4.2 RoCEv2 Packet Encapsulation #
After receiving the Work Request, the client NIC processes the operation and generates the appropriate network packets.
For RoCEv2, the packet is encapsulated using Ethernet, IP, and UDP.
A simplified RDMA Write packet structure is:
+----------------------------------+
| Ethernet Header |
+----------------------------------+
| IP Header (IPv4 / IPv6) |
+----------------------------------+
| UDP Header |
| Destination Port: 4791 |
+----------------------------------+
| Base Transport Header (BTH) |
| - Opcode |
| - P_Key |
| - Destination QP |
| - Packet Sequence Number (PSN) |
+----------------------------------+
| RDMA Extended Transport Header |
| - Virtual Address |
| - R_Key |
| - Data Length |
+----------------------------------+
| RDMA Payload |
+----------------------------------+
| Invariant CRC (iCRC) |
+----------------------------------+
The two important RDMA transport headers are BTH and RETH.
Base Transport Header (BTH)
The BTH provides transport-level information, including:
- Operation code.
- Partition Key field.
- Destination QP number.
- Packet Sequence Number.
The destination QP number allows the receiving NIC to identify the appropriate communication context.
The PSN supports transport sequencing and reliability mechanisms.
RDMA Extended Transport Header (RETH)
For an RDMA Write request, the RETH carries:
- Remote virtual address.
- Remote R_Key.
- Transfer length.
These fields identify the registered destination memory region and the range to which the incoming payload should be written.
UDP Encapsulation
RoCEv2 uses UDP/IP encapsulation, with UDP destination port 4791.
This makes it possible to transport RDMA packets through IP-based Ethernet networks.

4.3 Receiving and Processing the RDMA Write #
When the packet reaches the Server Compute Node, the receiving NIC processes the incoming RoCEv2 traffic.
The simplified processing sequence is:
- Receive and validate the Ethernet, IP, and UDP encapsulation.
- Identify the destination QP.
- Validate the transport information and packet sequence.
- Validate the R_Key and remote memory access permissions.
- Check that the requested memory range is valid.
- Perform DMA into the registered destination memory region.
The NIC uses the memory registration metadata to translate and authorize the requested remote memory access.
The destination data is written directly into the registered memory buffer without requiring the remote CPU to copy each packet into application memory.
4.4 RDMA Write Completion and Remote Notification #
An important distinction exists between completing an RDMA Write and notifying the remote application.
For a conventional RDMA Write:
- The sender can receive a completion entry if the Work Request was submitted as signaled.
- The receiving NIC performs the remote memory write.
- The remote application does not automatically receive a receive CQE for an ordinary RDMA Write.
This is one of the defining characteristics of one-sided RDMA operations.
When the receiving application needs notification that data has arrived, it can use RDMA Write with Immediate.
This operation combines remote memory writing with an immediate-data notification.
The receiving QP must have an appropriate receive buffer posted, and the receiving application can obtain a completion entry containing the immediate data.
The distinction is important when designing producer-consumer communication protocols because successful remote memory placement does not automatically mean that the remote application has been notified to process the new data.

🌟 Major Benefits of RDMA #
RDMA provides several important advantages over conventional networking, particularly for communication-intensive applications.
1. Ultra-Low Latency #
By reducing kernel networking overhead, memory copies, and CPU processing, RDMA can achieve very low communication latency.
This is especially valuable for latency-sensitive HPC applications, distributed databases, and AI communication workloads.
2. High Throughput #
Modern RDMA NICs support high-speed data transfer with hardware-assisted packet processing and DMA.
This makes RDMA suitable for high-bandwidth communication between servers and accelerator nodes.
3. Reduced CPU Overhead #
The RDMA NIC handles much of the communication data path.
The host CPU is still responsible for application logic, submitting work requests, managing connections, and handling completions, but it does not need to process every data packet through the traditional networking stack.
4. Efficient Memory Access #
Registered memory and direct DMA enable efficient data movement without conventional intermediate-buffer copying.
This is particularly valuable for large transfers and workloads that repeatedly exchange data between distributed nodes.
5. Scalable Distributed Computing #
RDMA provides an efficient communication foundation for large-scale distributed systems.
As clusters grow, reducing communication overhead becomes increasingly important for maintaining accelerator utilization and application performance.
6. Flexible Ethernet Deployment #
RoCEv2 allows RDMA communication to operate over Ethernet and IP-based infrastructure.
With suitable congestion-control, routing, and packet-loss management, it can support large-scale data center deployments.
🔍 RDMA vs. Traditional TCP/IP Networking #
The following table summarizes the key architectural differences:
| Feature | Traditional TCP/IP | RDMA |
|---|---|---|
| Data Path | Conventional OS networking stack | NIC-assisted direct memory transfer |
| CPU Involvement | Higher per-packet processing overhead | Reduced data-path involvement |
| Memory Copies | May require multiple copies | Can avoid intermediate copies |
| Latency | Generally higher | Generally lower |
| Throughput | Depends on CPU and NIC efficiency | High-throughput hardware-assisted transfer |
| Memory Access | Socket-based data exchange | Registered memory regions |
| Transport Management | TCP or UDP | RDMA transport services |
| Hardware Requirements | Standard network interface | RDMA-capable NIC and compatible infrastructure |
| Typical Applications | General-purpose networking | HPC, AI, distributed storage, and low-latency services |
RDMA is not a universal replacement for TCP/IP.
TCP remains appropriate for general application communication, while RDMA is especially valuable when low latency, high throughput, and reduced CPU overhead justify its additional hardware and programming requirements.
🧭 Conclusion #
RDMA, particularly RoCEv2 over IP-based Ethernet networks, is an important foundation for modern high-performance distributed systems.
By allowing RDMA NICs to transfer data directly between registered memory regions, it reduces conventional networking overhead and enables efficient communication between compute nodes.
Understanding its fundamental components is essential when designing or optimizing RDMA-based infrastructure:
- Memory Registration: Establishes the memory-access permissions required by the NIC.
- Protection Domain: Provides an access-control boundary for RDMA resources.
- L_Key and R_Key: Control local and remote memory access.
- Queue Pair: Provides the Send and Receive Queues used to submit communication operations.
- Completion Queue: Reports the completion status of RDMA operations.
- Connection Initialization: Establishes the communication parameters between RDMA endpoints.
- RDMA Write: Allows one endpoint to transfer data directly into a registered remote memory region.
These mechanisms work together to provide low-latency, high-throughput communication while minimizing CPU involvement.
As AI training clusters, HPC systems, and distributed storage platforms continue to scale, RDMA will remain an important technology for overcoming communication bottlenecks and improving overall system efficiency.