receive window (rwnd)

term

networking

Kept in this browser · My desk

The number of bytes a Transmission Control Protocol (TCP) receiver says it will accept beyond the last byte it has acknowledged, carried in the 16-bit Window field of every segment and scaled after the handshake when both ends agree: TCP's flow control.

It protects the receiver, not the network. Each acknowledgement from a Transmission Control Protocol (TCP) endpoint carries a window, the free room in its receive buffer, and the sender may not have more unacknowledged data outstanding than that window, nor than its own congestion window. When an application stops reading, the window shrinks to zero and the sender stops and probes; when the window is smaller than the bandwidth-delay product, the connection runs at window divided by round-trip time however fast the path is. Captures show both: a zero window from a slow consumer, and a steady, unexplained ceiling from a small or unscaled window.

What it is. Request for Comments (RFC) 9293 (August 2022), the Transmission Control Protocol (TCP) standard, defines the 16-bit Window field as the number of data octets, beginning with the one indicated in the acknowledgement field, that the sender of the segment is willing to accept; the value is shifted when the window scaling extension is used. RFC 5681 calls the latest value the receiver window, rwnd, and limits a sender to the minimum of rwnd and its own congestion window. That makes the receive window TCP's flow control: the receiver tells, the sender obeys. The congestion window, by contrast, is guessed by the sender to protect the path.

How it moves. RFC 9293 says the window indicates the range of sequence numbers the receiver is currently prepared to accept and is assumed to be related to the free buffer space for the connection. Advertising a large window encourages transmission, and data that arrives beyond what can be accepted is discarded; advertising a small one may introduce a round-trip delay between segments. A receiver SHOULD NOT shrink the window, that is, move its right edge to the left, but a sender MUST be robust against it.

Zero windows. When an application stops reading, its buffer fills and the receiver advertises a window of zero. The sender must then probe: it regularly sends at least one octet of new data, or retransmits, so that the reopening of the window is reliably reported. RFC 9293 says it SHOULD send the first zero-window probe when the zero window has lasted for the retransmission timeout and SHOULD increase the interval between probes exponentially; a receiver MAY keep its window closed indefinitely, and as long as it keeps acknowledging the probes the sender MUST keep the connection open. RFC 1122 (October 1989) already required zero-window probing and gave the example of a printer out of paper.

Silly window syndrome. David D. Clark of the MIT Laboratory for Computer Science named the classic pathology in RFC 813 (July 1982): a bad window algorithm can degrade throughput and processor use by several factors of ten, a stable pattern of tiny segments that RFC 9293 calls the Silly Window Syndrome (SWS). Both ends MUST avoid it. The receiver keeps its right window edge fixed until the space it could offer reaches min(Fr x RCV.BUFF, Eff.snd.MSS), Eff.snd.MSS being the effective send maximum segment size (MSS) and Fr recommended at 1/2, so the window opens in steps of about one maximum segment size. The sender computes the usable window U = SND.UNA + SND.WND - SND.NXT and prefers to send full-sized segments, a rule that works alongside the Nagle algorithm.

Window scaling. Sixteen bits allow at most 65,535 bytes, too little for paths with a large bandwidth-delay product. RFC 7323 (September 2014) adds the three-byte Window Scale option, kind 3, carrying a shift count. It is an offer, not a promise: both sides MUST send it in their SYN (synchronize) segments for scaling to be used in either direction, a shift of zero is a valid offer, the exponent is limited to 14, for a maximum window of 2^30 bytes or 1 GiB, and the window field in a SYN or SYN/ACK is never scaled. Worked: a receiver that wants to advertise 1,875,000 bytes, the bandwidth-delay product of a 100 Mbit/s path at 150 ms, needs a shift of 5, since 65,535 x 32 = 2,097,120; the receiver right-shifts its window by 5 bits, so the field reads 58,593, which the sender multiplies by 32 to get 1,874,976 bytes.

In practice. Linux sizes the receive buffer within net.ipv4.tcp_rmem: a minimum of 4K, a default of 131,072 bytes, which the kernel documentation says results in an initial window of 65,535, and a maximum between 131,072 bytes and 32 MB depending on memory. With tcp_moderate_rcvbuf enabled the kernel auto-tunes the buffer up to that maximum to match the path; an application that sets SO_RCVBUF disables auto-tuning for its socket. tcp_window_scaling is enabled by default. ss -ti shows the negotiated wscale for each connection as send and receive factors. In a capture, the window field of each acknowledgement is the receiver's current offer, to be multiplied by the factor agreed in the handshake.

What goes wrong. A capture taken after the handshake cannot know the scale factor and will misread every window. A zero window is a receiver problem, a slow consumer or a full buffer, not a network problem, although the stall looks the same from the user's side. A small fixed buffer caps a long path at window divided by round-trip time. And a receiver that shrinks its window, which the standard discourages, can leave a sender with a negative usable window.

Neighbours. The congestion window is the sender's own limit beside it; the bandwidth-delay product says how large it must be; the maximum segment size sets its steps; the socket is where the application drains it.

Also known as: rwnd, receiver window, advertised window, flow control window, tcp window, janela de recepção

Sources

← Back to R Back to the glossary