HSC welcomes all external visitors to this site, especially students and members of the academic community. Please use the comments box at the bottom of each page to record any comments or suggestions for improvement.
TCP acking mechanism
TCP protocol is ack clocked; the reception of an ack for the transmitted data is the basis for the transmitter to estimate its furture data transmission capabilities.
The Acking mechanism in TCP gets linked to transmission capabilities in following ways:
- The time taken for the ack to reach the transmitter indicates round trip time
- The ack carries the advertised window of the receiver, hence indicating maximum amount of data that the receiver can accept from peer at any point of time, after transmission of receive window worth of data an ack is required to trigger the transmission of next data packet.
- TCP transmits restricted amount of data to peer to avoid causing congestion in network, this is governed by congestion window . The reception of ack indicates the current state of congestion in the network and is used for adjusting the congestion window accordingly.
Acking modes
TCP uses two modes for acking the data received viz. Quick ack and delayed ack.
Quick ack mode is used at the start of TCP connection to enable congestion window to grow fast. Subsequently TCP moves to delayed ack mode wherein ack is generated for multiple (usually two) packets.
TCP moves between quick ack and delayed ack modes based on congestion experienced.
Detailed functionality
For entering the quick ack mode following parameters are initialized:
- pingpong flag is reset
- Ack timeout interval( ato ) is set to minimum
- ( tcp_incr_quickack ) Number of acks to be sent quickly is determined on the basis of receive window and packet size. The policy is to quick acknowledge half the receive window worth of packets. (This computed parameter is stored by the name quick ).
The mss value is constantly refined as per the packet size being received.
TCP is in quick mode if
- pingpong is set to 0
- number of quick acks ( quick ) to be sent is non zero
Scheduling an Ack
Ack is scheduled by setting the TCP_SCK_SCHED bit in the ack pending flag.
Processing data received
On receiving the packets from peer in established state (tcp_rcv_established) the following tasks are executed:
- Processing of data reception event
(tcp_event_data_recv)
- If the packet contains data, an ack is scheduled for received data.
- MSS processing (tcp_measure_rcv_mss)
- Check the size of the packet received The packet size received is used to refine the mss value being used for determining number of quick acks to be sent.
- If the received packet is smaller than the mss for this TCP connection, Ack is immediately pushed by calling . (Smaller data packets are most commonly sent when there is no more data to be sent.)
If this is the first data packet received ato (ack timeout) will not be set by now. Using the value of ato as an indication for first packet, TCP .
On subsequent data packets; interval between arrival for data packets, m is used for fine tuning the ato value. TCP_ATO_MIN is the minimum bound for ato . If m is more than ato , it would mean that ack timeout can be relaxed a little. Care is taken to not let ato be larger than rto (retransmission timeout).
In case inter packet arrival time has exceeded retransmission timeout, that would indicate a probable congestion in network. TCP is moved to quickack mode in this case by calling tcp_incr_quickack.
Sending the ack when data is copied to user queues on device interrupt
Depending on the current mode a quick ack or delayed ack
transmission is invoked:
Processing the data segment received
Call Processing of data reception event
Receiving out of order data
Ack is scheduled
Sack information is appended in the ack
If the received data segment filled a hole in out of order queue pingpong is reset to cause an ack to be sent immediately.
Receiving out of window data
Switch is made to quick ack mode
Ack is scheduled
Sending the ack
- Sending Ack for processed data segment
(tcp_ack_snd_check)
- After processing the segment received in established state, a check is made to see if an ack is scheduled
- If any of the following conditions are met, send ack immediately. Else send delayed ack
- full frame was received (packet size greater than mss) and receive buffer has space for accepting advertised window worth of data
- Quick ack mode is active and quick is not zero and pingpong is not set.
- Data received is out of order and we have outstanding out of order data
__Sending quick ack__ (tcp_send_ack)
preparing the ack packet
in case memory allocation fails, Ack is scheduled and delayed ack timer is started for max duration.
transmit the packet
After the ack is transmitted to peer, quick is decremented. Ack pending and blocked are reset and delayed ack timer is deleted.
Reduction of value of "quick" to 0 marks the start of delayed ack mode. At this point ato is set to minimum value of TCP_ATO_MIN.
__Sending delayed ack__ (tcp_send_delayed_ack)
Tuning ato
MAX bound: If pingpong is set and ack is to be pushed max_ato is set to TCP_DELACK_MAX (20U) else it is set to 50U.
MIN bound: Minimum value for ato is TCP_DELACK_MIN (4U)
if the round trip time measured for the TCP connection ( srtt ) lies in range {TCP_DELACK_MIN,TCP_DELACK_MAX} then ato is set to the minimum of srtt or the ato computed in step MSS processing (tcp_measure_rcv_mss).
In case the delayed ack timer was already running
if the ack is marked blocked send the ack
if the delack timer is about to expire send the ack
if the new computed timeout value is less than the timeout for which timer is already running leave the timer duration unaltered.
If none of the above steps are true, start a delayed ack timer of computed interval
Delayed ack timer expiry
- Delayed ack timer expiry
(tcp_delack_timer)
- In the following scenarios the delayed ack is not transmitted:
- Processing on the common data structures by data arrival event and timer expiry event has to be made mutually exclusive. In case the timer expires and fails to acquire the spin lock, ack is marked as blocked. Delayed ack timer is restarted for TCP_DELACK_MIN duration.
- In case the timeout recomputed as per the rtt calculations is higher than the timeout period which the timer served, the timer is restarted for the residual duration.
- The TCP connection has moved to close state.
- The TCP_ACK_TIMER is not set.
In the following scenarios the delayed ack is transmitted:
If the ack was marked scheduled and pingpong is set to 0, it would mean that value ato is set too low. Value of ato is doubled and upper bound by rto.
If the ack was marked scheduled and pingpong is set to 1, it would mean delayed ack timer was longer than required. Value of ato is deflated to min bound, TCP_ATO_MIN.
Data delivery to Application layer
When the data received from peer is passed on to the application layer, ack will be immediately sent in following scenarios:
- Previously blocked ack is transmitted
- A segment smaller than 1 mss is cleared by application from the queue
- Recovery from zero window condition
Maintainer: seema.garg@hsc.com
Categories: Inside_Linux_TCP Software
Comments