Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 ===
0004 RDS
0005 ===
0006 
0007 Overview
0008 ========
0009 
0010 This readme tries to provide some background on the hows and whys of RDS,
0011 and will hopefully help you find your way around the code.
0012 
0013 In addition, please see this email about RDS origins:
0014 http://oss.oracle.com/pipermail/rds-devel/2007-November/000228.html
0015 
0016 RDS Architecture
0017 ================
0018 
0019 RDS provides reliable, ordered datagram delivery by using a single
0020 reliable connection between any two nodes in the cluster. This allows
0021 applications to use a single socket to talk to any other process in the
0022 cluster - so in a cluster with N processes you need N sockets, in contrast
0023 to N*N if you use a connection-oriented socket transport like TCP.
0024 
0025 RDS is not Infiniband-specific; it was designed to support different
0026 transports.  The current implementation used to support RDS over TCP as well
0027 as IB.
0028 
0029 The high-level semantics of RDS from the application's point of view are
0030 
0031  *      Addressing
0032 
0033         RDS uses IPv4 addresses and 16bit port numbers to identify
0034         the end point of a connection. All socket operations that involve
0035         passing addresses between kernel and user space generally
0036         use a struct sockaddr_in.
0037 
0038         The fact that IPv4 addresses are used does not mean the underlying
0039         transport has to be IP-based. In fact, RDS over IB uses a
0040         reliable IB connection; the IP address is used exclusively to
0041         locate the remote node's GID (by ARPing for the given IP).
0042 
0043         The port space is entirely independent of UDP, TCP or any other
0044         protocol.
0045 
0046  *      Socket interface
0047 
0048         RDS sockets work *mostly* as you would expect from a BSD
0049         socket. The next section will cover the details. At any rate,
0050         all I/O is performed through the standard BSD socket API.
0051         Some additions like zerocopy support are implemented through
0052         control messages, while other extensions use the getsockopt/
0053         setsockopt calls.
0054 
0055         Sockets must be bound before you can send or receive data.
0056         This is needed because binding also selects a transport and
0057         attaches it to the socket. Once bound, the transport assignment
0058         does not change. RDS will tolerate IPs moving around (eg in
0059         a active-active HA scenario), but only as long as the address
0060         doesn't move to a different transport.
0061 
0062  *      sysctls
0063 
0064         RDS supports a number of sysctls in /proc/sys/net/rds
0065 
0066 
0067 Socket Interface
0068 ================
0069 
0070   AF_RDS, PF_RDS, SOL_RDS
0071         AF_RDS and PF_RDS are the domain type to be used with socket(2)
0072         to create RDS sockets. SOL_RDS is the socket-level to be used
0073         with setsockopt(2) and getsockopt(2) for RDS specific socket
0074         options.
0075 
0076   fd = socket(PF_RDS, SOCK_SEQPACKET, 0);
0077         This creates a new, unbound RDS socket.
0078 
0079   setsockopt(SOL_SOCKET): send and receive buffer size
0080         RDS honors the send and receive buffer size socket options.
0081         You are not allowed to queue more than SO_SNDSIZE bytes to
0082         a socket. A message is queued when sendmsg is called, and
0083         it leaves the queue when the remote system acknowledges
0084         its arrival.
0085 
0086         The SO_RCVSIZE option controls the maximum receive queue length.
0087         This is a soft limit rather than a hard limit - RDS will
0088         continue to accept and queue incoming messages, even if that
0089         takes the queue length over the limit. However, it will also
0090         mark the port as "congested" and send a congestion update to
0091         the source node. The source node is supposed to throttle any
0092         processes sending to this congested port.
0093 
0094   bind(fd, &sockaddr_in, ...)
0095         This binds the socket to a local IP address and port, and a
0096         transport, if one has not already been selected via the
0097         SO_RDS_TRANSPORT socket option
0098 
0099   sendmsg(fd, ...)
0100         Sends a message to the indicated recipient. The kernel will
0101         transparently establish the underlying reliable connection
0102         if it isn't up yet.
0103 
0104         An attempt to send a message that exceeds SO_SNDSIZE will
0105         return with -EMSGSIZE
0106 
0107         An attempt to send a message that would take the total number
0108         of queued bytes over the SO_SNDSIZE threshold will return
0109         EAGAIN.
0110 
0111         An attempt to send a message to a destination that is marked
0112         as "congested" will return ENOBUFS.
0113 
0114   recvmsg(fd, ...)
0115         Receives a message that was queued to this socket. The sockets
0116         recv queue accounting is adjusted, and if the queue length
0117         drops below SO_SNDSIZE, the port is marked uncongested, and
0118         a congestion update is sent to all peers.
0119 
0120         Applications can ask the RDS kernel module to receive
0121         notifications via control messages (for instance, there is a
0122         notification when a congestion update arrived, or when a RDMA
0123         operation completes). These notifications are received through
0124         the msg.msg_control buffer of struct msghdr. The format of the
0125         messages is described in manpages.
0126 
0127   poll(fd)
0128         RDS supports the poll interface to allow the application
0129         to implement async I/O.
0130 
0131         POLLIN handling is pretty straightforward. When there's an
0132         incoming message queued to the socket, or a pending notification,
0133         we signal POLLIN.
0134 
0135         POLLOUT is a little harder. Since you can essentially send
0136         to any destination, RDS will always signal POLLOUT as long as
0137         there's room on the send queue (ie the number of bytes queued
0138         is less than the sendbuf size).
0139 
0140         However, the kernel will refuse to accept messages to
0141         a destination marked congested - in this case you will loop
0142         forever if you rely on poll to tell you what to do.
0143         This isn't a trivial problem, but applications can deal with
0144         this - by using congestion notifications, and by checking for
0145         ENOBUFS errors returned by sendmsg.
0146 
0147   setsockopt(SOL_RDS, RDS_CANCEL_SENT_TO, &sockaddr_in)
0148         This allows the application to discard all messages queued to a
0149         specific destination on this particular socket.
0150 
0151         This allows the application to cancel outstanding messages if
0152         it detects a timeout. For instance, if it tried to send a message,
0153         and the remote host is unreachable, RDS will keep trying forever.
0154         The application may decide it's not worth it, and cancel the
0155         operation. In this case, it would use RDS_CANCEL_SENT_TO to
0156         nuke any pending messages.
0157 
0158   ``setsockopt(fd, SOL_RDS, SO_RDS_TRANSPORT, (int *)&transport ..), getsockopt(fd, SOL_RDS, SO_RDS_TRANSPORT, (int *)&transport ..)``
0159         Set or read an integer defining  the underlying
0160         encapsulating transport to be used for RDS packets on the
0161         socket. When setting the option, integer argument may be
0162         one of RDS_TRANS_TCP or RDS_TRANS_IB. When retrieving the
0163         value, RDS_TRANS_NONE will be returned on an unbound socket.
0164         This socket option may only be set exactly once on the socket,
0165         prior to binding it via the bind(2) system call. Attempts to
0166         set SO_RDS_TRANSPORT on a socket for which the transport has
0167         been previously attached explicitly (by SO_RDS_TRANSPORT) or
0168         implicitly (via bind(2)) will return an error of EOPNOTSUPP.
0169         An attempt to set SO_RDS_TRANSPORT to RDS_TRANS_NONE will
0170         always return EINVAL.
0171 
0172 RDMA for RDS
0173 ============
0174 
0175   see rds-rdma(7) manpage (available in rds-tools)
0176 
0177 
0178 Congestion Notifications
0179 ========================
0180 
0181   see rds(7) manpage
0182 
0183 
0184 RDS Protocol
0185 ============
0186 
0187   Message header
0188 
0189     The message header is a 'struct rds_header' (see rds.h):
0190 
0191     Fields:
0192 
0193       h_sequence:
0194           per-packet sequence number
0195       h_ack:
0196           piggybacked acknowledgment of last packet received
0197       h_len:
0198           length of data, not including header
0199       h_sport:
0200           source port
0201       h_dport:
0202           destination port
0203       h_flags:
0204           Can be:
0205 
0206           =============  ==================================
0207           CONG_BITMAP    this is a congestion update bitmap
0208           ACK_REQUIRED   receiver must ack this packet
0209           RETRANSMITTED  packet has previously been sent
0210           =============  ==================================
0211 
0212       h_credit:
0213           indicate to other end of connection that
0214           it has more credits available (i.e. there is
0215           more send room)
0216       h_padding[4]:
0217           unused, for future use
0218       h_csum:
0219           header checksum
0220       h_exthdr:
0221           optional data can be passed here. This is currently used for
0222           passing RDMA-related information.
0223 
0224   ACK and retransmit handling
0225 
0226       One might think that with reliable IB connections you wouldn't need
0227       to ack messages that have been received.  The problem is that IB
0228       hardware generates an ack message before it has DMAed the message
0229       into memory.  This creates a potential message loss if the HCA is
0230       disabled for any reason between when it sends the ack and before
0231       the message is DMAed and processed.  This is only a potential issue
0232       if another HCA is available for fail-over.
0233 
0234       Sending an ack immediately would allow the sender to free the sent
0235       message from their send queue quickly, but could cause excessive
0236       traffic to be used for acks. RDS piggybacks acks on sent data
0237       packets.  Ack-only packets are reduced by only allowing one to be
0238       in flight at a time, and by the sender only asking for acks when
0239       its send buffers start to fill up. All retransmissions are also
0240       acked.
0241 
0242   Flow Control
0243 
0244       RDS's IB transport uses a credit-based mechanism to verify that
0245       there is space in the peer's receive buffers for more data. This
0246       eliminates the need for hardware retries on the connection.
0247 
0248   Congestion
0249 
0250       Messages waiting in the receive queue on the receiving socket
0251       are accounted against the sockets SO_RCVBUF option value.  Only
0252       the payload bytes in the message are accounted for.  If the
0253       number of bytes queued equals or exceeds rcvbuf then the socket
0254       is congested.  All sends attempted to this socket's address
0255       should return block or return -EWOULDBLOCK.
0256 
0257       Applications are expected to be reasonably tuned such that this
0258       situation very rarely occurs.  An application encountering this
0259       "back-pressure" is considered a bug.
0260 
0261       This is implemented by having each node maintain bitmaps which
0262       indicate which ports on bound addresses are congested.  As the
0263       bitmap changes it is sent through all the connections which
0264       terminate in the local address of the bitmap which changed.
0265 
0266       The bitmaps are allocated as connections are brought up.  This
0267       avoids allocation in the interrupt handling path which queues
0268       sages on sockets.  The dense bitmaps let transports send the
0269       entire bitmap on any bitmap change reasonably efficiently.  This
0270       is much easier to implement than some finer-grained
0271       communication of per-port congestion.  The sender does a very
0272       inexpensive bit test to test if the port it's about to send to
0273       is congested or not.
0274 
0275 
0276 RDS Transport Layer
0277 ===================
0278 
0279   As mentioned above, RDS is not IB-specific. Its code is divided
0280   into a general RDS layer and a transport layer.
0281 
0282   The general layer handles the socket API, congestion handling,
0283   loopback, stats, usermem pinning, and the connection state machine.
0284 
0285   The transport layer handles the details of the transport. The IB
0286   transport, for example, handles all the queue pairs, work requests,
0287   CM event handlers, and other Infiniband details.
0288 
0289 
0290 RDS Kernel Structures
0291 =====================
0292 
0293   struct rds_message
0294     aka possibly "rds_outgoing", the generic RDS layer copies data to
0295     be sent and sets header fields as needed, based on the socket API.
0296     This is then queued for the individual connection and sent by the
0297     connection's transport.
0298 
0299   struct rds_incoming
0300     a generic struct referring to incoming data that can be handed from
0301     the transport to the general code and queued by the general code
0302     while the socket is awoken. It is then passed back to the transport
0303     code to handle the actual copy-to-user.
0304 
0305   struct rds_socket
0306     per-socket information
0307 
0308   struct rds_connection
0309     per-connection information
0310 
0311   struct rds_transport
0312     pointers to transport-specific functions
0313 
0314   struct rds_statistics
0315     non-transport-specific statistics
0316 
0317   struct rds_cong_map
0318     wraps the raw congestion bitmap, contains rbnode, waitq, etc.
0319 
0320 Connection management
0321 =====================
0322 
0323   Connections may be in UP, DOWN, CONNECTING, DISCONNECTING, and
0324   ERROR states.
0325 
0326   The first time an attempt is made by an RDS socket to send data to
0327   a node, a connection is allocated and connected. That connection is
0328   then maintained forever -- if there are transport errors, the
0329   connection will be dropped and re-established.
0330 
0331   Dropping a connection while packets are queued will cause queued or
0332   partially-sent datagrams to be retransmitted when the connection is
0333   re-established.
0334 
0335 
0336 The send path
0337 =============
0338 
0339   rds_sendmsg()
0340     - struct rds_message built from incoming data
0341     - CMSGs parsed (e.g. RDMA ops)
0342     - transport connection alloced and connected if not already
0343     - rds_message placed on send queue
0344     - send worker awoken
0345 
0346   rds_send_worker()
0347     - calls rds_send_xmit() until queue is empty
0348 
0349   rds_send_xmit()
0350     - transmits congestion map if one is pending
0351     - may set ACK_REQUIRED
0352     - calls transport to send either non-RDMA or RDMA message
0353       (RDMA ops never retransmitted)
0354 
0355   rds_ib_xmit()
0356     - allocs work requests from send ring
0357     - adds any new send credits available to peer (h_credits)
0358     - maps the rds_message's sg list
0359     - piggybacks ack
0360     - populates work requests
0361     - post send to connection's queue pair
0362 
0363 The recv path
0364 =============
0365 
0366   rds_ib_recv_cq_comp_handler()
0367     - looks at write completions
0368     - unmaps recv buffer from device
0369     - no errors, call rds_ib_process_recv()
0370     - refill recv ring
0371 
0372   rds_ib_process_recv()
0373     - validate header checksum
0374     - copy header to rds_ib_incoming struct if start of a new datagram
0375     - add to ibinc's fraglist
0376     - if competed datagram:
0377          - update cong map if datagram was cong update
0378          - call rds_recv_incoming() otherwise
0379          - note if ack is required
0380 
0381   rds_recv_incoming()
0382     - drop duplicate packets
0383     - respond to pings
0384     - find the sock associated with this datagram
0385     - add to sock queue
0386     - wake up sock
0387     - do some congestion calculations
0388   rds_recvmsg
0389     - copy data into user iovec
0390     - handle CMSGs
0391     - return to application
0392 
0393 Multipath RDS (mprds)
0394 =====================
0395   Mprds is multipathed-RDS, primarily intended for RDS-over-TCP
0396   (though the concept can be extended to other transports). The classical
0397   implementation of RDS-over-TCP is implemented by demultiplexing multiple
0398   PF_RDS sockets between any 2 endpoints (where endpoint == [IP address,
0399   port]) over a single TCP socket between the 2 IP addresses involved. This
0400   has the limitation that it ends up funneling multiple RDS flows over a
0401   single TCP flow, thus it is
0402   (a) upper-bounded to the single-flow bandwidth,
0403   (b) suffers from head-of-line blocking for all the RDS sockets.
0404 
0405   Better throughput (for a fixed small packet size, MTU) can be achieved
0406   by having multiple TCP/IP flows per rds/tcp connection, i.e., multipathed
0407   RDS (mprds).  Each such TCP/IP flow constitutes a path for the rds/tcp
0408   connection. RDS sockets will be attached to a path based on some hash
0409   (e.g., of local address and RDS port number) and packets for that RDS
0410   socket will be sent over the attached path using TCP to segment/reassemble
0411   RDS datagrams on that path.
0412 
0413   Multipathed RDS is implemented by splitting the struct rds_connection into
0414   a common (to all paths) part, and a per-path struct rds_conn_path. All
0415   I/O workqs and reconnect threads are driven from the rds_conn_path.
0416   Transports such as TCP that are multipath capable may then set up a
0417   TCP socket per rds_conn_path, and this is managed by the transport via
0418   the transport privatee cp_transport_data pointer.
0419 
0420   Transports announce themselves as multipath capable by setting the
0421   t_mp_capable bit during registration with the rds core module. When the
0422   transport is multipath-capable, rds_sendmsg() hashes outgoing traffic
0423   across multiple paths. The outgoing hash is computed based on the
0424   local address and port that the PF_RDS socket is bound to.
0425 
0426   Additionally, even if the transport is MP capable, we may be
0427   peering with some node that does not support mprds, or supports
0428   a different number of paths. As a result, the peering nodes need
0429   to agree on the number of paths to be used for the connection.
0430   This is done by sending out a control packet exchange before the
0431   first data packet. The control packet exchange must have completed
0432   prior to outgoing hash completion in rds_sendmsg() when the transport
0433   is mutlipath capable.
0434 
0435   The control packet is an RDS ping packet (i.e., packet to rds dest
0436   port 0) with the ping packet having a rds extension header option  of
0437   type RDS_EXTHDR_NPATHS, length 2 bytes, and the value is the
0438   number of paths supported by the sender. The "probe" ping packet will
0439   get sent from some reserved port, RDS_FLAG_PROBE_PORT (in <linux/rds.h>)
0440   The receiver of a ping from RDS_FLAG_PROBE_PORT will thus immediately
0441   be able to compute the min(sender_paths, rcvr_paths). The pong
0442   sent in response to a probe-ping should contain the rcvr's npaths
0443   when the rcvr is mprds-capable.
0444 
0445   If the rcvr is not mprds-capable, the exthdr in the ping will be
0446   ignored.  In this case the pong will not have any exthdrs, so the sender
0447   of the probe-ping can default to single-path mprds.
0448