Share via


TCP Receive Window Size Calculation and Window Scaling

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The TCP receive window size is the amount of receive data (in bytes) that can be buffered at one time on a connection. The sending host can send only that amount of data before waiting for an acknowledgment and window update from the receiving host. The Windows Embedded CE TCP/IP stack was designed to tune itself in most environments, and uses larger default window sizes than earlier versions. Instead of using a hard-coded default receive window size, TCP adjusts to even increments of the maximum segment size (MSS) negotiated during connection setup. Matching the receive window to even increments of the MSS increases the percentage of full-sized TCP segments used during bulk data transmission.

The receive window size defaults to a value calculated as follows:

  1. The starting value of the receive window size is determined from the registry settings for GlobalMaxTcpWindowSize, the global TcpWindowSize, and the adapter specific TcpWindowSize, according to the following logic:
    TcpWindowSize is set to HKLM\Comm\<AdapterName>\Parms\Tcpip\TcpWindowSize if the registry key value exists.
  2. Upon establishing the connection, the receive window size is rounded up to an increment of the maximum TCP segment size (MSS) which was negotiated during connection setup.
  3. If that is not at least four times the value of MSS, then it is adjusted to four times the value of MSS, with a maximum size of 64 KB, unless a window scaling option (RFC 1323) is in effect.

You can set the receive window size to a specific value by setting the TcpWindowSizeregistry entry described in TCP/IPv4 Configurable Registry Settings.

To improve performance on high-bandwidth, high-delay networks, RFC 1323 is supported. This RFC details a method for supporting scalable windows by allowing TCP to negotiate a scaling factor for the window size at connection establishment. This allows for an actual receive window of up to 1 gigabyte (GB). RFC 1323 Section 2.2 provides the following description of window scaling:

2.2 Window Scale Option

The three-byte Window Scale option may be sent in a SYN segment by a TCP. It has two purposes: (1) indicate that the TCP is prepared to do both send and receive window scaling, and (2) communicate a scale factor to be applied to its receive window. Thus, a TCP that is prepared to scale windows should send the option, even if its own scale factor is 1. The scale factor is limited to a power of two and encoded logarithmically, so it may be implemented by binary shift operations.

   TCP Window Scale Option (WSopt):

      Kind: 3 Length: 3 bytes

             +---------+---------+---------+
             | Kind=3  |Length=3 |shift.cnt|
             +---------+---------+---------+

This option is an offer, not a promise; both sides must send Window Scale options in their SYN segments to enable window scaling in either direction. If window scaling is enabled, then the TCP that sent this option will right-shift its true receive-window values by Shift.cnt bits for transmission in SEG.WND. The value Shift.cnt can be zero (offering to scale, while applying a scale factor of 1 to the receive window).

This option may be sent in an initial <SYN> segment (for example, a segment with the SYN bit on and the ACK bit off). It may also be sent in a <SYN,ACK> segment, but only if a Window Scale option was received in the initial <SYN> segment. A Window Scale option in a segment without a SYN bit should be ignored.

The Window field in a SYN (for example, a <SYN> or <SYN,ACK>) segment itself is never scaled.

When you read network traces of a connection that was established by two computers that support scalable windows, keep in mind that the window sizes advertised in the trace must be scaled by the negotiated scale factor. The scale factor can be observed in the connection establishment (3-way handshake) packets.

Windows Embedded CE uses window scaling automatically if the TcpWindowSize registry entry is set to a value greater than 64 KB. Window scaling can be disabled with the Tcp1323Opts registry entry.

See Also

Concepts

Transmission Control Protocol (TCP)