Large Windows and Buffers: Bandwidth-Delay Product, Auto-Tuning and Urgent Data
Why a TCP connection needs a window as large as its bandwidth-delay product, how fixed socket buffers cap throughput and how Linux auto-tunes them instead, measured on a 100 Mbit/s, 60 ms lab path, plus TCP's urgent mechanism and attacks that abuse windows.
kvi5hnuCode Sprout team member11 min readOn this page
Article 69 showed the window protecting a slow receiver. On a fast, long path, the window has the opposite problem: if it's too small, it limits throughput even when both ends and the network could go faster. This article measures that limit, shows how Linux sizes its buffers automatically to avoid it, and then covers TCP's little-used urgent mechanism and the attacks that abuse windows.
The bandwidth-delay product
A sender can have at most one window of unacknowledged data in flight, and it takes one RTT to get the ACKs that let it send more. So a connection's throughput is at most:
throughput ≤ window ÷ RTT
To keep a path busy, the window must be at least the bandwidth-delay product (BDP), the amount of data "in the pipe" during one RTT. The lab path had a 100 Mbit/s bottleneck and about 60 ms of RTT:
rtt min/avg/max/mdev = 54.192/56.692/58.705/1.874 ms
BDP = 100 Mbit/s × 0.06 s = 6 Mbit, or 750 KB. Any window below that leaves the link idle part of each round trip. Paths with a large BDP are called long fat networks (RFC 7323): a 10 Gbit/s link across a continent with 80 ms of RTT has a BDP of 100 MB. Without the window scale option (article 60), the window would be capped at 64 KB, which on the lab path would allow only about 65,535 × 8 bits ÷ 0.06 s ≈ 8.7 Mbit/s. With scaling, the maximum is about 1 GB.
Fixed buffers cap throughput
The window a receiver can offer is limited by its receive buffer. The lab downloaded data with the client's buffer fixed by SO_RCVBUF, and then with no SO_RCVBUF at all. Each line shows the size asked for, the buffer the kernel actually gave, the download time and the throughput (the starred line used SO_RCVBUFFORCE, explained below):
requested effective time throughput
16KB 32 KB 13.04 s 3.1 Mbit/s
64KB 128 KB 3.21 s 12.5 Mbit/s
256KB 416 KB 13.88 s 34.6 Mbit/s
1024KB 416 KB 13.51 s 35.5 Mbit/s
net.core.rmem_max = 212992
1024KB* 2048 KB 5.66 s 84.8 Mbit/s
auto-tuned - 5.67 s 84.6 Mbit/s
The chart below plots the throughput column.

Three things show up here:
- Throughput followed the buffer. Each fixed buffer gave roughly what window ÷ RTT predicts. Linux offers only part of the buffer as window, about two-thirds here, because each received segment costs more memory than its payload. A 32 KB buffer means about 22 KB of window, or 3 Mbit/s at 60 ms.
- Asking for 1 MB gave the same as 256 KB. Linux doubles the requested
SO_RCVBUF(socket(7)), but caps the request atnet.core.rmem_max, 208 KB here, so both requests ended at 416 KB. A privileged process can exceed the cap withSO_RCVBUFFORCE, which gave 2 MB and nearly full speed. - Doing nothing was as good as the best fixed buffer. With no
SO_RCVBUF, Linux auto-tuned the buffer and reached about 85 Mbit/s. That's close to the link rate, once you account for headers (about 3.5% of each packet) and the slow-start ramp at the beginning.
Setting SO_RCVBUF turns off auto-tuning for that socket. Programs that set it "for performance" often end up slower, as the lab showed.
Receive buffer auto-tuning
Linux grows each connection's receive buffer as needed (net.ipv4.tcp_moderate_rcvbuf = 1), within the limits of net.ipv4.tcp_rmem:
net.ipv4.tcp_rmem = 4096 131072 6291456
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.rmem_max = 212992
net.ipv4.tcp_moderate_rcvbuf = 1
net.ipv4.tcp_adv_win_scale = 1
net.ipv4.tcp_shrink_window = 0
Older kernels used tcp_adv_win_scale to fix the share of the buffer offered as window; current ones measure the real per-packet overhead instead. The three tcp_rmem values are the minimum, the starting size (128 KB), and the maximum auto-tuning may reach (6 MB on the lab's 6.12 kernel; since Linux 6.16 the default maximum is up to 32 MB, depending on RAM). Once per RTT, the receiver measures how much data the application actually read, rcv_space in ss. If that grew, it enlarges the buffer, to about twice the measurement plus overhead, so the window can keep ahead of a sender in slow start. rcv_space during one download:
auto-tuned - 5.33 s 90.1 Mbit/s
client rcv_space samples (bytes): 14480 43440 60816 117288 233128 474944 949888 1614520 2027200 2180688 2279152 2387752 2522416 2632512 2732376 2806840
The plot below draws these samples over time, next to the bytes received.

The estimate passed the BDP within half a second and kept growing. It overshot the 750 KB BDP several times: the router's queue filled during the download and raised the RTT, so more data fit in each round trip, and the buffer only ever grows. The send side is tuned too: tcp_wmem sets the limits for the send buffer, which Linux grows with the congestion window. For a host with very long paths, the usual tuning is to raise the maximums (tcp_rmem and tcp_wmem), not to set per-socket buffers.
Urgent data
TCP has a mechanism for marking data as urgent: the URG flag and the 16-bit urgent pointer in the header (article 58). The sender's application sends urgent data with send(..., MSG_OOB), and the receiver is told that urgent data is coming even if the normal data ahead of it hasn't been read. Telnet and the control connection of FTP (File Transfer Protocol) used it so an interrupt keystroke could get past a full buffer.
The lab client sent abc, then one byte ! with MSG_OOB, then xyz:
seq=1 len=3 flags=·······AP··· urgent_pointer=0 payload=616263
seq=4 len=1 flags=······UAP··· urgent_pointer=1 payload=21
seq=5 len=3 flags=·······AP··· urgent_pointer=0 payload=78797a
server: recv() returns b'abc'
server: recv(MSG_OOB) returns b'!'
server: recv() returns b'xyz'
The payloads are shown in hex: 616263 is abc, 21 is ! and 78797a is xyz. The segment carrying ! had the URG flag set and an urgent pointer of 1, pointing to the byte after the urgent byte. On Linux, the last urgent byte is pulled out of the stream: a normal recv() skipped it, and recv(MSG_OOB) returned it separately. That's why it's often called "out-of-band" data, although it travels in the same stream.
In practice, the mechanism is a minefield:
- Only one byte is "out of band." Despite the pointer, the socket API inherited from BSD Unix delivers only the last urgent byte separately, and a second urgent byte overwrites the first if it hasn't been read.
- Implementations disagreed about whether the pointer marks the last urgent byte or the one after it. RFC 6093 settled it (the byte after, as observed here) and recommends that new applications not use urgent data at all. RFC 9293 carries the same advice.
- Middleboxes interfere. Some clear the URG flag or treat urgent data inline (
SO_OOBINLINEdoes that on purpose), so behavior isn't reliable end to end.
Modern protocols send their control messages in-band, with their own framing, or over a separate connection.
Window attacks
Windows also give attackers something to abuse:
- Zero-window exhaustion. A client opens connections, requests large responses, and advertises a zero window. The server keeps the data in its send buffers and probes forever (article 69). Tools like Sockstress (2008) automated this. Defenses are per-connection timeouts (
TCP_USER_TIMEOUT, application deadlines) and limits on resources per client. - Tiny windows. A receiver that advertises a few bytes makes the server send many small segments, costing CPU per byte. Sender-side SWS avoidance (article 69) blunts this.
- Inflated windows and optimistic ACKs. A receiver claiming a huge window and acknowledging data early can push a sender to transmit far faster than the path allows, congesting the network for others (article 67).
Common questions
How do I compute the window my path needs?
Multiply the bottleneck bandwidth by the RTT. For 1 Gbit/s and 20 ms, that's 1e9 × 0.02 / 8 = 2.5 MB. Make sure the maximums in tcp_rmem and tcp_wmem are at least that, plus overhead, and let auto-tuning do the rest.
Should I set SO_RCVBUF for a high-throughput application?
Usually not on Linux. It disables auto-tuning, is capped by rmem_max, and is hard to get right for every path. The lab's 1 MB request silently became 416 KB and ran at 36 Mbit/s, while the untouched socket reached 85 Mbit/s.
Why does Linux report double the buffer size I set?
It reserves room for bookkeeping. getsockopt(SO_RCVBUF) returns the doubled value, and the window offered is only part of it.
Is the window ever the bottleneck on short paths?
Rarely. At 1 ms RTT, even a 128 KB window allows about 1 Gbit/s. Window limits matter most on long, fast paths: intercontinental transfers, satellite links, and data center replication across regions.
Can a buffer be too big?
On the receive side, a large maximum mostly costs memory, which is allocated only as data arrives. On the send side, a large buffer lets an application queue much more than is in flight. That data waits in the kernel (notsent in ss), so anything urgent written later waits behind it. Latency-sensitive servers, for example HTTP/2 servers that interleave streams, set TCP_NOTSENT_LOWAT (or net.ipv4.tcp_notsent_lowat) to keep only a little unsent data queued and decide at the last moment what to send next.
What does MSG_OOB do on a modern system?
It sets the URG flag and urgent pointer, and the receiver can read the last urgent byte separately with MSG_OOB, or inline with SO_OOBINLINE. It works, but it carries one byte, behaves differently across stacks, and is discouraged for new protocols.
Summary
- Throughput is at most window ÷ RTT, so a connection needs a window of at least the bandwidth-delay product. The lab path's BDP was 750 KB.
- Fixed
SO_RCVBUFvalues capped throughput at 3, 12 and 35 Mbit/s. Requests abovenet.core.rmem_maxwere silently capped, and setting the option disables auto-tuning. - Linux auto-tunes receive buffers from the data the application reads per RTT, within
tcp_rmem. With noSO_RCVBUF, the lab reached about 85 Mbit/s on a 100 Mbit/s link. - The urgent mechanism (URG flag, urgent pointer,
MSG_OOB) delivers one byte separately on Linux. It's inconsistent across stacks and discouraged for new applications. - Windows can be abused: zero windows to exhaust server memory, tiny windows to waste CPU, and inflated windows to make senders overload the network.
Practice questions
1. A path has 500 Mbit/s of bandwidth and a 40 ms RTT. What window does a connection need to fill it, and what's the best it can do with a 64 KB window?
Answer
BDP = 500e6 × 0.04 / 8 = 2.5 MB. With a 64 KB window, throughput is at most 65,536 × 8 / 0.04 ≈ 13 Mbit/s, about 2.6% of the link.
2. A program sets SO_RCVBUF to 4 MB on a Linux host with rmem_max at 208 KB. What does getsockopt(SO_RCVBUF) return, and what happened to auto-tuning?
Answer
It returns 416 KB: the request was capped at rmem_max (212,992 bytes) and then doubled. Auto-tuning is disabled for the socket because the program set a buffer size, so the window stays at roughly two-thirds of 416 KB.
3. In the lab, rcv_space grew past 2.5 MB although the BDP was 750 KB. Is that a problem?
Answer
Not usually. The queue at the router raised the RTT during the transfer, so more data fit in each round trip, and Linux only grows the buffer. Memory is allocated as data actually arrives, and the total is limited by tcp_rmem and the system-wide tcp_mem.
4. A client sends "12", then "3" with MSG_OOB, then "45", and the Linux receiver doesn't set SO_OOBINLINE. What does it read with normal recv() calls, and with recv(MSG_OOB)?
Answer
Normal reads return 12 and then 45. The urgent byte 3 is removed from the stream and is returned only by recv(MSG_OOB). With SO_OOBINLINE, it would stay in the stream and 12345 would be read normally.
5. A web server's memory fills with connections that have large send queues and zero windows, all from a few addresses. What's happening, and what limits would help?
Answer
A zero-window exhaustion attack: the clients request data and never read it, so the server holds the data and probes indefinitely. Per-connection deadlines (TCP_USER_TIMEOUT or application timeouts), limits on connections and memory per client address, and smaller maximum send buffers all reduce the damage.
Previous: TCP Flow Control: The Sliding Window, Zero Windows and Silly Window Syndrome
Next: TCP Keepalive: Detecting Dead Peers and Keeping NAT Mappings Alive

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.