1 .. SPDX-License-Identifier: GPL-2.0
10 This readme tries to provide some background on the hows and whys of RDS,
11 and will hopefully help you find your way around the code.
13 In addition, please see this email about RDS origins:
14 http://oss.oracle.com/pipermail/rds-devel/2007-November/000228.html
19 RDS provides reliable, ordered datagram delivery by using a single
20 reliable connection between any two nodes in the cluster. This allows
21 applications to use a single socket to talk to any other process in the
22 cluster - so in a cluster with N processes you need N sockets, in contrast
23 to N*N if you use a connection-oriented socket transport like TCP.
25 RDS is not Infiniband-specific; it was designed to support different
26 transports. The current implementation used to support RDS over TCP as well
29 The high-level semantics of RDS from the application's point of view are
33 RDS uses IPv4 addresses and 16bit port numbers to identify
34 the end point of a connection. All socket operations that involve
35 passing addresses between kernel and user space generally
36 use a struct sockaddr_in.
38 The fact that IPv4 addresses are used does not mean the underlying
39 transport has to be IP-based. In fact, RDS over IB uses a
40 reliable IB connection; the IP address is used exclusively to
41 locate the remote node's GID (by ARPing for the given IP).
43 The port space is entirely independent of UDP, TCP or any other
48 RDS sockets work *mostly* as you would expect from a BSD
49 socket. The next section will cover the details. At any rate,
50 all I/O is performed through the standard BSD socket API.
51 Some additions like zerocopy support are implemented through
52 control messages, while other extensions use the getsockopt/
55 Sockets must be bound before you can send or receive data.
56 This is needed because binding also selects a transport and
57 attaches it to the socket. Once bound, the transport assignment
58 does not change. RDS will tolerate IPs moving around (eg in
59 a active-active HA scenario), but only as long as the address
60 doesn't move to a different transport.
64 RDS supports a number of sysctls in /proc/sys/net/rds
70 AF_RDS, PF_RDS, SOL_RDS
71 AF_RDS and PF_RDS are the domain type to be used with socket(2)
72 to create RDS sockets. SOL_RDS is the socket-level to be used
73 with setsockopt(2) and getsockopt(2) for RDS specific socket
76 fd = socket(PF_RDS, SOCK_SEQPACKET, 0);
77 This creates a new, unbound RDS socket.
79 setsockopt(SOL_SOCKET): send and receive buffer size
80 RDS honors the send and receive buffer size socket options.
81 You are not allowed to queue more than SO_SNDSIZE bytes to
82 a socket. A message is queued when sendmsg is called, and
83 it leaves the queue when the remote system acknowledges
86 The SO_RCVSIZE option controls the maximum receive queue length.
87 This is a soft limit rather than a hard limit - RDS will
88 continue to accept and queue incoming messages, even if that
89 takes the queue length over the limit. However, it will also
90 mark the port as "congested" and send a congestion update to
91 the source node. The source node is supposed to throttle any
92 processes sending to this congested port.
94 bind(fd, &sockaddr_in, ...)
95 This binds the socket to a local IP address and port, and a
96 transport, if one has not already been selected via the
97 SO_RDS_TRANSPORT socket option
100 Sends a message to the indicated recipient. The kernel will
101 transparently establish the underlying reliable connection
104 An attempt to send a message that exceeds SO_SNDSIZE will
105 return with -EMSGSIZE
107 An attempt to send a message that would take the total number
108 of queued bytes over the SO_SNDSIZE threshold will return
111 An attempt to send a message to a destination that is marked
112 as "congested" will return ENOBUFS.
115 Receives a message that was queued to this socket. The sockets
116 recv queue accounting is adjusted, and if the queue length
117 drops below SO_SNDSIZE, the port is marked uncongested, and
118 a congestion update is sent to all peers.
120 Applications can ask the RDS kernel module to receive
121 notifications via control messages (for instance, there is a
122 notification when a congestion update arrived, or when a RDMA
123 operation completes). These notifications are received through
124 the msg.msg_control buffer of struct msghdr. The format of the
125 messages is described in manpages.
128 RDS supports the poll interface to allow the application
129 to implement async I/O.
131 POLLIN handling is pretty straightforward. When there's an
132 incoming message queued to the socket, or a pending notification,
135 POLLOUT is a little harder. Since you can essentially send
136 to any destination, RDS will always signal POLLOUT as long as
137 there's room on the send queue (ie the number of bytes queued
138 is less than the sendbuf size).
140 However, the kernel will refuse to accept messages to
141 a destination marked congested - in this case you will loop
142 forever if you rely on poll to tell you what to do.
143 This isn't a trivial problem, but applications can deal with
144 this - by using congestion notifications, and by checking for
145 ENOBUFS errors returned by sendmsg.
147 setsockopt(SOL_RDS, RDS_CANCEL_SENT_TO, &sockaddr_in)
148 This allows the application to discard all messages queued to a
149 specific destination on this particular socket.
151 This allows the application to cancel outstanding messages if
152 it detects a timeout. For instance, if it tried to send a message,
153 and the remote host is unreachable, RDS will keep trying forever.
154 The application may decide it's not worth it, and cancel the
155 operation. In this case, it would use RDS_CANCEL_SENT_TO to
156 nuke any pending messages.
158 ``setsockopt(fd, SOL_RDS, SO_RDS_TRANSPORT, (int *)&transport ..), getsockopt(fd, SOL_RDS, SO_RDS_TRANSPORT, (int *)&transport ..)``
159 Set or read an integer defining the underlying
160 encapsulating transport to be used for RDS packets on the
161 socket. When setting the option, integer argument may be
162 one of RDS_TRANS_TCP or RDS_TRANS_IB. When retrieving the
163 value, RDS_TRANS_NONE will be returned on an unbound socket.
164 This socket option may only be set exactly once on the socket,
165 prior to binding it via the bind(2) system call. Attempts to
166 set SO_RDS_TRANSPORT on a socket for which the transport has
167 been previously attached explicitly (by SO_RDS_TRANSPORT) or
168 implicitly (via bind(2)) will return an error of EOPNOTSUPP.
169 An attempt to set SO_RDS_TRANSPORT to RDS_TRANS_NONE will
170 always return EINVAL.
175 see rds-rdma(7) manpage (available in rds-tools)
178 Congestion Notifications
179 ========================
189 The message header is a 'struct rds_header' (see rds.h):
194 per-packet sequence number
196 piggybacked acknowledgment of last packet received
198 length of data, not including header
206 ============= ==================================
207 CONG_BITMAP this is a congestion update bitmap
208 ACK_REQUIRED receiver must ack this packet
209 RETRANSMITTED packet has previously been sent
210 ============= ==================================
213 indicate to other end of connection that
214 it has more credits available (i.e. there is
217 unused, for future use
221 optional data can be passed here. This is currently used for
222 passing RDMA-related information.
224 ACK and retransmit handling
226 One might think that with reliable IB connections you wouldn't need
227 to ack messages that have been received. The problem is that IB
228 hardware generates an ack message before it has DMAed the message
229 into memory. This creates a potential message loss if the HCA is
230 disabled for any reason between when it sends the ack and before
231 the message is DMAed and processed. This is only a potential issue
232 if another HCA is available for fail-over.
234 Sending an ack immediately would allow the sender to free the sent
235 message from their send queue quickly, but could cause excessive
236 traffic to be used for acks. RDS piggybacks acks on sent data
237 packets. Ack-only packets are reduced by only allowing one to be
238 in flight at a time, and by the sender only asking for acks when
239 its send buffers start to fill up. All retransmissions are also
244 RDS's IB transport uses a credit-based mechanism to verify that
245 there is space in the peer's receive buffers for more data. This
246 eliminates the need for hardware retries on the connection.
250 Messages waiting in the receive queue on the receiving socket
251 are accounted against the sockets SO_RCVBUF option value. Only
252 the payload bytes in the message are accounted for. If the
253 number of bytes queued equals or exceeds rcvbuf then the socket
254 is congested. All sends attempted to this socket's address
255 should return block or return -EWOULDBLOCK.
257 Applications are expected to be reasonably tuned such that this
258 situation very rarely occurs. An application encountering this
259 "back-pressure" is considered a bug.
261 This is implemented by having each node maintain bitmaps which
262 indicate which ports on bound addresses are congested. As the
263 bitmap changes it is sent through all the connections which
264 terminate in the local address of the bitmap which changed.
266 The bitmaps are allocated as connections are brought up. This
267 avoids allocation in the interrupt handling path which queues
268 sages on sockets. The dense bitmaps let transports send the
269 entire bitmap on any bitmap change reasonably efficiently. This
270 is much easier to implement than some finer-grained
271 communication of per-port congestion. The sender does a very
272 inexpensive bit test to test if the port it's about to send to
279 As mentioned above, RDS is not IB-specific. Its code is divided
280 into a general RDS layer and a transport layer.
282 The general layer handles the socket API, congestion handling,
283 loopback, stats, usermem pinning, and the connection state machine.
285 The transport layer handles the details of the transport. The IB
286 transport, for example, handles all the queue pairs, work requests,
287 CM event handlers, and other Infiniband details.
290 RDS Kernel Structures
291 =====================
294 aka possibly "rds_outgoing", the generic RDS layer copies data to
295 be sent and sets header fields as needed, based on the socket API.
296 This is then queued for the individual connection and sent by the
297 connection's transport.
300 a generic struct referring to incoming data that can be handed from
301 the transport to the general code and queued by the general code
302 while the socket is awoken. It is then passed back to the transport
303 code to handle the actual copy-to-user.
306 per-socket information
308 struct rds_connection
309 per-connection information
312 pointers to transport-specific functions
314 struct rds_statistics
315 non-transport-specific statistics
318 wraps the raw congestion bitmap, contains rbnode, waitq, etc.
320 Connection management
321 =====================
323 Connections may be in UP, DOWN, CONNECTING, DISCONNECTING, and
326 The first time an attempt is made by an RDS socket to send data to
327 a node, a connection is allocated and connected. That connection is
328 then maintained forever -- if there are transport errors, the
329 connection will be dropped and re-established.
331 Dropping a connection while packets are queued will cause queued or
332 partially-sent datagrams to be retransmitted when the connection is
340 - struct rds_message built from incoming data
341 - CMSGs parsed (e.g. RDMA ops)
342 - transport connection alloced and connected if not already
343 - rds_message placed on send queue
347 - calls rds_send_xmit() until queue is empty
350 - transmits congestion map if one is pending
351 - may set ACK_REQUIRED
352 - calls transport to send either non-RDMA or RDMA message
353 (RDMA ops never retransmitted)
356 - allocs work requests from send ring
357 - adds any new send credits available to peer (h_credits)
358 - maps the rds_message's sg list
360 - populates work requests
361 - post send to connection's queue pair
366 rds_ib_recv_cq_comp_handler()
367 - looks at write completions
368 - unmaps recv buffer from device
369 - no errors, call rds_ib_process_recv()
372 rds_ib_process_recv()
373 - validate header checksum
374 - copy header to rds_ib_incoming struct if start of a new datagram
375 - add to ibinc's fraglist
376 - if competed datagram:
377 - update cong map if datagram was cong update
378 - call rds_recv_incoming() otherwise
379 - note if ack is required
382 - drop duplicate packets
384 - find the sock associated with this datagram
387 - do some congestion calculations
389 - copy data into user iovec
391 - return to application
393 Multipath RDS (mprds)
394 =====================
395 Mprds is multipathed-RDS, primarily intended for RDS-over-TCP
396 (though the concept can be extended to other transports). The classical
397 implementation of RDS-over-TCP is implemented by demultiplexing multiple
398 PF_RDS sockets between any 2 endpoints (where endpoint == [IP address,
399 port]) over a single TCP socket between the 2 IP addresses involved. This
400 has the limitation that it ends up funneling multiple RDS flows over a
401 single TCP flow, thus it is
402 (a) upper-bounded to the single-flow bandwidth,
403 (b) suffers from head-of-line blocking for all the RDS sockets.
405 Better throughput (for a fixed small packet size, MTU) can be achieved
406 by having multiple TCP/IP flows per rds/tcp connection, i.e., multipathed
407 RDS (mprds). Each such TCP/IP flow constitutes a path for the rds/tcp
408 connection. RDS sockets will be attached to a path based on some hash
409 (e.g., of local address and RDS port number) and packets for that RDS
410 socket will be sent over the attached path using TCP to segment/reassemble
411 RDS datagrams on that path.
413 Multipathed RDS is implemented by splitting the struct rds_connection into
414 a common (to all paths) part, and a per-path struct rds_conn_path. All
415 I/O workqs and reconnect threads are driven from the rds_conn_path.
416 Transports such as TCP that are multipath capable may then set up a
417 TCP socket per rds_conn_path, and this is managed by the transport via
418 the transport privatee cp_transport_data pointer.
420 Transports announce themselves as multipath capable by setting the
421 t_mp_capable bit during registration with the rds core module. When the
422 transport is multipath-capable, rds_sendmsg() hashes outgoing traffic
423 across multiple paths. The outgoing hash is computed based on the
424 local address and port that the PF_RDS socket is bound to.
426 Additionally, even if the transport is MP capable, we may be
427 peering with some node that does not support mprds, or supports
428 a different number of paths. As a result, the peering nodes need
429 to agree on the number of paths to be used for the connection.
430 This is done by sending out a control packet exchange before the
431 first data packet. The control packet exchange must have completed
432 prior to outgoing hash completion in rds_sendmsg() when the transport
433 is mutlipath capable.
435 The control packet is an RDS ping packet (i.e., packet to rds dest
436 port 0) with the ping packet having a rds extension header option of
437 type RDS_EXTHDR_NPATHS, length 2 bytes, and the value is the
438 number of paths supported by the sender. The "probe" ping packet will
439 get sent from some reserved port, RDS_FLAG_PROBE_PORT (in <linux/rds.h>)
440 The receiver of a ping from RDS_FLAG_PROBE_PORT will thus immediately
441 be able to compute the min(sender_paths, rcvr_paths). The pong
442 sent in response to a probe-ping should contain the rcvr's npaths
443 when the rcvr is mprds-capable.
445 If the rcvr is not mprds-capable, the exthdr in the ping will be
446 ignored. In this case the pong will not have any exthdrs, so the sender
447 of the probe-ping can default to single-path mprds.