Is net.ipv4.tcp_probe_interval for zero window detection?
Assistant
No, net.ipv4.tcp_probe_interval is not specifically related to zero window detection. It's related to the probing of a TCP connection when TCP detects a loss or long periods of inactivity, which can sometimes coincide with the situation where the receive window size is indeed zero (a "zero window"), but its primary purpose is broader. When the TCP stack has data to send but cannot because the window is closed, it will keep sending zero window probes periodically to determine when the window opens up again.
The zero window condition happens when the receive window advertised by the receiver is zero, indicating that the receiver's buffer is full and it cannot accept any more data at that time. The sender must wait until the receiver announces a non-zero window size before it can resume sending data.
User
I known about keepalive probes and zero window probes. What orher tcp probes this parapets can reflect?
Assistant
The net.ipv4.tcp_probe_interval and net.ipv4.tcp_probe_threshold parameters relate primarily to another, less commonly discussed TCP probing mechanism known as TCP Persist Timers or Persistence Probes. This mechanism handles a specific condition where the send buffer on the transmitting side cannot be emptied because the receiving side's window is full (but not necessarily zero) or receives no window updates.
What's a better value for net.ipv4.tcp_pacing_ss_ratio, net.ipv4.tcp_pacing_ca_ratio and net.ipv4.tcp_limit_output_bytes to maintain connection with RTT of 1ms and throughput of 1 gigabyte per second? Why net.ipv4.tcp_min_snd_mss and net.ipv4.tcp_mtu_probe_floor are both 48? Cannot a packet be less than the value? Why not less or not more?
Assistant
User
What if I set net.ipv4.tcp_limit_output_bytes to 0? Is there a reason to set it to a value higher than a writing buffer size or less then its size?
Assistant
User
Setting net.ipv4.tcp_limit_output_bytes I set additional buffer size relating to existing writing buffer? Why writing buffer is subjected to auto-tunning but net.ipv4.tcp_limit_output_bytes is a fixed value?
Assistant
User
Does the value represent another buffer size that is for holding a packets waiting to be transmitted?
Assistant
No, the net.ipv4.tcp_limit_output_bytes parameter does not represent another buffer size for holding packets waiting to be transmitted. Instead, it represents a limit on the number of bytes that TCP is allowed to have "unacknowledged" or "in-flight" in the network at any given time.
Here's how it works:
The socket write buffer is part of the kernel's memory that holds data which an application has written to the TCP socket but has not yet been sent out or has been sent but not yet acknowledged by the receiver. The size of this buffer can be set per-socket and can vary during the lifetime of the socket due to auto-tuning mechanisms.
User
Is it per connection limit? If I set is to maximum allowed value, can congestion control algorithm send data more than the receiver's tcp window can accept? If not, than the congestion control algorithm cannot make a congestion if it is not limited with net.ipv4.tcp_limit_output_bytes and because it respect the wirework bandwidth. Is it correct?
Assistant
Yes, is a per-connection limit. It acts as a cap for each individual TCP connection on the number of bytes that can be in-flight, i.e., sent but not yet acknowledged.
User
So, if I don't need any cap, it is safe to set net.ipv4.tcp_limit_output_bytes to the maximum value? What's the maximum?
Assistant
User
What does the value net.ipv4.tcp_notsent_lowat = 4294967295 means ? Give me an easy example with different values.
Assistant
User
Is the parameter for epoll or for unblocked socket too?
Assistant
The net.ipv4.tcp_notsent_lowat parameter is primarily relevant for applications that use non-blocking sockets along with I/O multiplexing calls such as epoll, poll, or select. The value of the parameter specifies the number of bytes below which the TCP socket layer will notify the application (via epoll or similar mechanisms) that it is writable again, after previously reporting that it was not writable due to a full send buffer.
What most common network features relyes on delayed demultiplexing? In what cases it is better to use 0, 1, 2, and 3 values of net.ipv4.tcp_early_retrans? How does Explicit Congestion Notification work, when it is better not to enable it? What's l3mdev, is there a reason for packets to be routed through it or not?
When I need to enable net.ipv4.tcp_reflect_tos? Is it efficient to set net.ipv4.tcp_no_ssthresh_metrics_save to 0? What's TCP receive path and how skbs may improve performance and what's the reason to disable it? What's the reason to disable net.ipv4.tcp_thin_linear_timeouts, does frto better and frto acts instead of it? Give me example of working net.ipv4.tcp_tso_win_divisor please.
Assistant
User
TCP Receive Path and SKB Caching is beneficial on new connections or during connection? Does it allocate a fixed memory per connection?
Assistant
TCP Receive Path and SKB Caching:
SKB (socket buffer) caching is a mechanism aimed at improving network performance by reducing the overhead associated with frequently allocating and deallocating socket buffers, which are the basic data structures used to hold packet data in the network stack.
SKB caching can be beneficial during the lifetime of a connection, not just for new connections. Whenever a packet is received, the system needs to allocate an SKB to hold that packet's data. On a busy network, where lots of packets are received, this can mean a lot of allocation and deallocation of memory, which can be CPU-intensive. By caching these SKBs, the network stack can reuse them instead of constantly asking for new memory allocations from the kernel, thereby reducing this overhead.
net.ipv4.tcp_allowed_congestion_control is a sysctl setting in Linux that specifies a list of TCP congestion control algorithms that are permitted for use on the system. This setting enables system administrators to restrict which congestion control algorithms can be selected via the sysctl interface or through socket options by applications running on the system.
User
What are algorithms relating to net.ipv4.tcp_recovery?
Assistant
The net.ipv4.tcp_recovery sysctl setting in Linux is not tied to a specific list of congestion control algorithms but rather to TCP loss recovery mechanisms as detailed in RFC 3782 and later updated by RFC 6675. This setting pertains to a set of behaviors that TCP uses during the recovery phase after detecting packet loss.
When net.ipv4.tcp_recovery is enabled, the following mechanisms come into play:
Fast Retransmit: When multiple duplicate acknowledgments (ACKs) for the same data segment are received, the TCP sender can infer that a segment was lost and retransmit the segment before its timeout would traditionally expire.
User
Can I disable fast retransmit if I set net.ipv4.tcp_recovery to 0? answer shortly
Assistant
No, setting net.ipv4.tcp_recovery to 0 will not disable the fast retransmit mechanism in the Linux TCP stack. The fast retransmit mechanism is a fundamental part of TCP congestion control and loss recovery and is not directly controlled by the tcp_recovery sysctl setting. The tcp_recovery flag controls additional features and optimizations on top of the basic fast retransmit and recovery mechanisms.
User
Whit mechanisms can be disabled by net.ipv4.tcp_recovery? Is there a reason to do so?
Assistant
Disabling net.ipv4.tcp_recovery (net.ipv4.tcp_recovery = 0) can affect advanced TCP loss recovery features that optimize the recovery process after detecting packet loss. The specific mechanisms that could be disabled or altered include:
Reduced Recovery Penalty: Optimizations that allow better estimation and handling of lost packets during recovery, possibly enabling the sender to recover without reducing the congestion window as drastically as the traditional approach would dictate.
Selective Acknowledgment (SACK) Based Recovery: SACK-based loss recovery mechanisms, such as FACK (Forward Acknowledgment) and SACK Reneging protection, which help the sender to more accurately determine which packets have been lost and need to be retransmitted.
User
Do I need to use net.ipv4.tcp_tso_win_divisor for hardware offloading only? Is the divisor for more even offloading of multiple connections?
Assistant
net.ipv4.tcp_tso_win_divisor is a sysctl parameter that specifically relates to TCP Segment Offload (TSO), a form of hardware offloading where the segmentation of large TCP packets into smaller ones is offloaded from the CPU to the network interface card (NIC). This offloading is beneficial because it reduces the CPU overhead involved in packet processing, thereby improving network performance, especially on high-speed connections.
User
Is net.ipv4.tcp_reflect_tos usually not respected by internet routers? What's toss and qos?
Assistant
Regarding net.ipv4.tcp_reflect_tos: The handling of the Type of Service (ToS) field (also known as the Differentiated Services Code Point (DSCP) field in the IPv4 and IPv6 headers) by internet routers can vary. Historically, the ToS field was often ignored by many routers, particularly on the public internet, because the end-to-end principle of the internet architecture does not guarantee the handling of such fields. Modern networks may have more sophisticated traffic management policies, including support for DSCP, but treatment still varies by provider and network.
User
net.ipv4.tcp_rx_skb_cache vs net.ipv4.tcp_tx_skb_cache? Do I need them both to improve cpu performance?
Assistant
net.ipv4.tcp_rx_skb_cache and net.ipv4.tcp_tx_skb_cache are settings related to the caching of socket buffer structures (SKBs) for the TCP receive path (rx) and transmit path (tx) respectively.
User
What percentage of increased memory usage with these options enabled?
Assistant
The exact percentage of increased memory usage associated with enabling net.ipv4.tcp_rx_skb_cache and net.ipv4.tcp_tx_skb_cache depends on several factors and can vary significantly between systems and workloads. There isn't a fixed percentage increase that can be universally applied because the impact on memory usage is influenced by:
User
Can you give me an approximate percentage range? Answer shortly
Assistant
It is not possible to provide an approximate percentage range for the increase in memory usage when enabling net.ipv4.tcp_rx_skb_cache and net.ipv4.tcp_tx_skb_cache without specific information about the system's hardware, the volume of network traffic, and system optimization. The impact can vary widely, from negligible on a system with light traffic and ample memory to potentially more significant on a system with high network traffic or limited memory. If memory usage is a concern, empirical testing and monitoring on the specific system in question is necessary to determine the actual impact.
User
When it is beneficial to use net.ipv4.tcp_no_ssthresh_metrics_save and when it is not?
Assistant
The net.ipv4.tcp_no_ssthresh_metrics_save setting controls whether the Linux TCP/IP stack should save the slow start threshold (ssthresh) between TCP connections to the same destination. This value influences the congestion window size during the start of the TCP slow start phase after the initial handshake.
Beneficial to use (net.ipv4.tcp_no_ssthresh_metrics_save = 0):
When it is set to (metrics save enabled), the advantage is that it can improve the performance of subsequent TCP connections to the same destination by starting with a previously learned value, potentially avoiding overly cautious slow-start behavior. This can be especially beneficial in network environments where conditions are relatively stable over time, and where recurring connections to the same destination are frequent. An example might be a web server that regularly communicates with a set of backend services over a stable network.
User
If net.ipv4.tcp_early_retrans is 1, does it mean that early retransmission works on 3 duplicate ack but doesn't work on ack reordering condition? Why if net.ipv4.tcp_early_retrans is 3 it is better for latency reduction compated to 2 value?
Assistant
Let's explore what the sysctl setting does in Linux when it's set to certain values:
User
I need to known what conditions and algorithms change the mechanism from 1 to 2 and from 2 to 3 values. Please give me a good comparison in context of exact mechanisms triggering these retransmissions.
Assistant
User
You said "whereas 2 does not require such an acknowledgment" so what's the trigger for retransmission then?
Assistant
Apologies for the confusion in my previous response. Let me clarify the triggers for retransmission with net.ipv4.tcp_early_retrans set to 2:
The trigger for retransmission when net.ipv4.tcp_early_retrans is set to 2 is the receipt of a certain number of duplicate acknowledgments (DUPACKs) that suggest a packet has been lost, but the key difference compared to the other settings is that the sender will not retransmit early based solely on DUPACKs unless there is data outstanding to send.
In other words, while the trigger still involves detecting potential packet loss via DUPACKs, the setting 2 takes into account whether there is additional unsent data in the queue. If more data is waiting to be sent, the algorithm is more inclined to perform an early retransmission, potentially reducing delay in situations where, due to a high amount of data being transferred, it's less likely that the DUPACKs are due to reordering and more likely they signify true loss.
User
Can you better describe differences in the triggers for 1, 2 and 3 values?
Assistant
User
Short comparison once again please. Write triggers only for each value please.
Assistant
Here's a short comparison of the triggers for early retransmission based on the net.ipv4.tcp_early_retrans setting values:
net.ipv4.tcp_early_retrans = 1:
Trigger: Reception of an acknowledgment for data sent after the lost segment.
net.ipv4.tcp_early_retrans = 2:
Trigger: Reception of a certain number of duplicate acknowledgments (DUPACKs) when there is outstanding unacknowledged data.
net.ipv4.tcp_early_retrans = 3:
Trigger: Immediate receipt of duplicate acknowledgments (DUPACKs) without additional conditions.
User
Are they all triggered on 3 duplicate ack as condition for fast retransmit mechanism?
Assistant
In traditional TCP, the fast retransmit mechanism is typically triggered upon receiving three duplicate acknowledgments (DUPACKs). However, the net.ipv4.tcp_early_retrans setting relates to the early retransmission optimization that provides a way to potentially retransmit lost segments before the traditional fast retransmit threshold of three DUPACKs is reached.
Here is how the different net.ipv4.tcp_early_retrans setting values relate to receiving DUPACKs:
net.ipv4.tcp_early_retrans = 1:
Early retransmit can trigger after receiving fewer than three DUPACKs if there is an acknowledgment for a segment sent after the one suspected as lost. If a partial ACK is not received, traditional fast retransmit (after three DUPACKs) still applies.
User
Can net.ipv4.tcp_early_retrans trigger on a single dupack?
Assistant
No, net.ipv4.tcp_early_retrans does not trigger on a single duplicate acknowledgment (DUPACK). The mechanism typically requires more than one DUPACK to infer potential packet loss.
The early retransmission optimization is designed to improve the responsiveness of TCP to packet loss conditions without waiting for the standard number of DUPACKs usually required by the traditional fast retransmit algorithm, which is generally three DUPACKs. However, this does not go as far as triggering on just one DUPACK, as that would be overly aggressive and could lead to unnecessary retransmissions in many situations where packets are merely out-of-order, not lost.
The configuration value of net.ipv4.tcp_early_retrans determines how aggressively TCP performs early retransmissions, but it does not alter the fundamental requirement for having multiple indicators of packet loss to avoid misinterpreting out-of-order delivery as packet loss. Receiving a single DUPACK is not commonly considered sufficient evidence of packet loss to justify retransmission.
User
Is net.ipv4.tcp_early_retrans triggers on 2 dupack for setting 1,2 and 3? additional trigger is a data pending to be transmitted ot its absence. Are any other particular triggers for each mode of 3?
Assistant
The net.ipv4.tcp_early_retrans setting allows for the possibility of triggering an early retransmit with fewer than three duplicate acknowledgments under certain conditions. The details vary slightly for each setting:
net.ipv4.tcp_early_retrans = 1:
Early retransmission can trigger with potentially fewer than three DUPACKs, but it requires an additional ACK for a segment being transmitted after the segment that is considered lost. If a partial ACK is not received, then the traditional fast retransmit behavior requiring three DUPACKs is used.
User
"if a partial ACK is not received" What does it mean?
Assistant
A "partial ACK" refers to an acknowledgment (ACK) in TCP that acknowledges some but not all of the data that has been sent but not yet acknowledged. It indicates that the receiver has received some of the data beyond the lost packet that triggered the retransmission, but there is still some data outstanding (i.e., segments between the lost segment and the latest acknowledged segment have not yet been acknowledged).
In the context of TCP and the net.ipv4.tcp_early_retrans setting, a partial ACK has specific significance during the loss recovery process. Here's how it works:
The parameters you've mentioned are related to the TCP (Transmission Control Protocol) configuration on Linux systems. They are used to control various aspects of TCP behavior, including sack compression, probe intervals, and TCP Fast Open features. I will explain each parameter:
net.ipv4.tcp_comp_sack_delay_ns = 1000000
This parameter sets the delay, in nanoseconds, before TCP attempts to compress SACK (Selective Acknowledgement) blocks. A lower value might improve performance in scenarios with heavy reordering or packet loss.
net.ipv4.tcp_comp_sack_nr = 44
This sets the maximum number of SACK blocks that can be compressed together. It can help in reducing the options size in TCP headers for connections experiencing high amounts of packet reordering or loss.
net.ipv4.tcp_comp_sack_slack_ns = 100000
This defines the allowance in nanoseconds when compressing multiple SACK blocks. It provides flexibility in deciding which SACK blocks can be compressed together based on their close proximity in time.
net.ipv4.tcp_probe_interval = 600
Defines the interval, in seconds, for TCP to send out probes when a connection is considered to be lossy or experiencing long periods of inactivity. It's used to check if the session is still alive and can help in maintaining connections over unreliable networks.
net.ipv4.tcp_probe_threshold = 8
Sets the threshold for when TCP should start sending out probes once it detects a certain number of unacknowledged packets. A higher number can potentially delay the detection of a failed connection, while a lower number may result in unnecessary probes.
net.ipv4.tcp_fastopen_blackhole_timeout_sec = 0
This is related to the TCP Fast Open feature, which allows data to be sent and received within the initial SYN packet of the TCP handshake, thus reducing latency. If the feature is suspected to be causing issues, this parameter can be set to disable the feature after a connection fails (with a non-zero value indicating the timeout in seconds).
net.ipv4.tcp_fastopen_key
This is not a variable to be set like the others but rather a representation of the cryptographic key used by the TCP Fast Open feature. The operating system uses this key to protect against spoofing attacks and should be a securely generated, random value. You typically don't set this key manually; instead, it can be automatically generated by the system depending on its configuration.
To modify these settings, one must have root privileges on a Linux system. These parameters can be set temporarily using the sysctl command or permanently by adding them to the /etc/sysctl.conf file and then reloading the settings. Adjusting these parameters should be done with caution and ideally after a thorough understanding of their impact on the system's network performance and stability.
The parameters net.ipv4.tcp_probe_interval and net.ipv4.tcp_probe_threshold control the behavior of persist timers that kick in when there is a potential send or receive stall, which can include but is not limited to zero window conditions. They dictate how and when the system will send out probes to test if the path to the destination can again accept data, and are more broadly applicable to maintaining connection liveness and overcoming potential stalls due to various network issues.
For zero window probes, there's not a specific sysctl setting that's used to tweak this behavior, as it is managed by the internal mechanisms of the TCP stack, which will automatically send zero window probes according to the exponential backoff strategy (doubling the probe interval after each unsuccessful probe) until the window opens again or the connection times out.
In detail:
TCP Persist Timer (Persistence Probes):
This timer is designed to handle a scenario where the TCP receiver advertises a small receive window, and the sender has partially or fully filled that window but cannot send any more data because it would exceed the window size. If the sender has data to send and the receive window is full, it needs to know when space in the receive buffer becomes available. Since it cannot send a full-sized segment, it sends a probe to "persist" and to trigger the receiver into sending another ACK with an updated window size. This is where net.ipv4.tcp_probe_interval and net.ipv4.tcp_probe_threshold come into play:
net.ipv4.tcp_probe_interval specifies the interval at which these persist probes are sent.
net.ipv4.tcp_probe_threshold defines the number of unacknowledged bytes that trigger these probes.
This is particularly important in long-lived, mostly-idle connections, where the receive window can be temporarily full, but regular application processing at the receiving end will eventually free up space.
The TCP Persist Timer probes are different from Zero Window Probes (which are sent when the receive window is explicitly zero) and TCP Keepalive Probes (which are idle connection probes sent to check if the peer is still active).
It's important to note that the behavior of Persistence Probes is subject to the congestion status of a TCP connection and the internal algorithm of the TCP stack, and persist timer configuration is not usually exposed via sysctl parameters. The primary reason is that the default handling of these situations by the TCP stack is appropriate for most circumstances, and manual tweaking is rarely required.
The parameters you listed are related to various aspects of TCP performance tuning, congestion control, and MTU handling in Linux. Here's an explanation for each of the sysctl settings:
net.ipv4.tcp_base_mss = 1024
This parameter sets the base Maximum Segment Size (MSS) used for calculating the initial congestion window, which is typically based on the MSS of the path. The congestion window determines how many bytes can be in flight before receiving an acknowledgement.
net.ipv4.tcp_min_snd_mss = 48
This sets the minimum sending Maximum Segment Size (MSS) for TCP connections. This is the smallest size of a segment that TCP will send out, which should ideally be large enough to avoid excessive header overhead.
net.ipv4.tcp_notsent_lowat = 4294967295
This parameter sets a threshold in bytes below which the write function will not be marked as writable, to prevent sending very small segments. A high value like 4294967295 effectively disables this feature because it's unlikely for the not-sent bytes to be below such a high threshold.
net.ipv4.tcp_limit_output_bytes = 1048576
This parameter sets the maximum number of bytes that can be queued on a TCP socket's send queue. It helps in preventing large bursts of data from being sent out in one go, smoothing out the transmission and potentially helping with congestion.
net.ipv4.tcp_min_rtt_wlen = 300
Defines the minimum time window length in seconds over which the smoothed round-trip time (RTT) is calculated. Keeping a minimum window ensures that short-term variations do not cause unnecessary fluctuations in the smoothed RTT value.
net.ipv4.tcp_invalid_ratelimit = 500
This seems to specify the rate limit for TCP invalid request response generation. It may control how quickly the system reacts to certain types of invalid or malformed packets, effectively throttling the response rate to such packets.
net.ipv4.tcp_pacing_ca_ratio = 120
This parameter specifies the pacing rate as a percentage of the current congestion window during Congestion Avoidance (CA) phase. This can allow for more efficient data transfers by pacing out packets over time to match the capacity of the link and reduce the likelihood of congestion.
net.ipv4.tcp_pacing_ss_ratio = 200
Defines the pacing rate setting as a percentage of the congestion window during the Slow Start (SS) phase. Like tcp_pacing_ca_ratio, this helps to reduce the chances of incurring congestion by spreading out packet transmissions.
net.ipv4.tcp_mtu_probe_floor = 48
This parameter sets the minimum MTU (Maximum Transmission Unit) value that can be probed for if Path MTU Discovery is unable to find a higher confirmable MTU. This ensures that there is a floor value below which the probing mechanism will not go, to avoid exceedingly small packets that would be very inefficient.
Some of these parameters are fine-tuning options that can affect network performance and should be adjusted with a good understanding of the network conditions and the expected traffic patterns. Improper adjustments may lead to suboptimal network performance or other issues.
When tuning net.ipv4.tcp_pacing_ss_ratio, net.ipv4.tcp_pacing_ca_ratio, and net.ipv4.tcp_limit_output_bytes for a specific connection with a 1ms Round-Trip Time (RTT) and throughput of 1 Gigabit per second (Gbps), you would begin by considering the default behavior of TCP pacing in Linux.
net.ipv4.tcp_pacing_ss_ratio and net.ipv4.tcp_pacing_ca_ratio:
These values define the pacing rate as a percentage of the sending rate that TCP uses during the Slow Start (SS) and Congestion Avoidance (CA) phases, respectively.
For a high-speed connection with a very low RTT, you may want to set these to a higher value to allow a faster sending rate, hence utilizing the available bandwidth more effectively.
However, determining "better" values for these parameters is not straightforward and requires careful testing. The optimal values can depend on many factors, including the specific characteristics of the network and overall cross-traffic.
net.ipv4.tcp_limit_output_bytes:
This limits the maximum number of bytes that can be outstanding (not acknowledged) in the network at any time.
For a 1 Gbps link with a 1ms RTT, the bandwidth-delay product (BDP) would be 1 Gbps * 1 ms = 125,000 bytes. To fully utilize the link, you might start by setting net.ipv4.tcp_limit_output_bytes to at least the BDP.
However, you might set it to a higher value to allow the sender to keep more data in flight, which could maintain throughput during variations in RTT or acknowledgment pacing from the receiver.
On the topic of net.ipv4.tcp_min_snd_mss and net.ipv4.tcp_mtu_probe_floor both being 48:
Ethernet frames have a minimum payload size requirement (to ensure they occupy the medium for a sufficient amount of time for collision detection), but that does not apply to the TCP MSS, which is the maximum segment size TCP will use, not counting headers. The standard Ethernet frame has a minimum size of 64 bytes (which includes the Ethernet header and CRC trailer), but the TCP/IP headers can take a significant portion of that, leading to a small MSS being possible in theory.
However, in practice, network equipment might not handle such tiny MSS values well, leading to inefficiencies and other issues. Therefore, 48 bytes is a conservative lower bound to avoid possible fragmentation or other problems at the IP layer.
An MSS of 48 bytes is very small and would almost never be used because it would be extremely inefficient: the ratio of header bytes to payload bytes would be very large, leading to high overhead. In normal situations, the MSS would be set based on the MTU size minus the standard header sizes for IP and TCP (for Ethernet, typically an MSS of 1460 bytes is used with an MTU of 1500 bytes).
Remember to always test any changes to these values in a controlled environment prior to deploying them in production. The "best" settings often depend on specific network characteristics and goals and should ideally be determined through empirical analysis and benchmarking.
Setting net.ipv4.tcp_limit_output_bytes to zero would effectively disable the output buffering for TCP, meaning no data could be queued for transmission on a TCP socket's send queue. This would likely break the ability of the TCP stack to send any data at all, making the setting counterproductive and should be avoided.
The value of net.ipv4.tcp_limit_output_bytes should generally be a reflection of the effective bandwidth-delay product (BDP) for your connection, with some additional headroom to accommodate for variations in connection speed and latency. The BDP is calculated by multiplying the available bandwidth by the RTT of the connection and represents the amount of data that can be "in-flight" on the network at any one time.
Setting net.ipv4.tcp_limit_output_bytes:
Higher than the BDP:
Can provide benefits if the RTT fluctuates, ensuring that the connection can still reach its full throughput potential during periods of lower latency.
Can be beneficial if the application is transmitting bursts of data and you want to avoid application-level blocking or waiting for TCP acknowledgments before sending more data.
However, setting it too high can lead to queuing delays and increased bufferbloat, which can contribute to higher latencies and decreased performance for other traffic.
Lower than the BDP:
This would restrict the amount of data that can be in flight, which might reduce the impact of bufferbloat and ensure other applications/systems on the same network have fair access to the bandwidth.
However, it might also prevent the connection from reaching its full bandwidth potential, particularly for high-capacity, low-latency networks where the BDP is significant.
Relative to the write buffer size:
If you set net.ipv4.tcp_limit_output_bytes to a value lower than the allocated write buffer size for the socket, you create a bottleneck at the send queue that might not be necessary and may impede performance.
If you set it higher than the write buffer size, the extra space is effectively unusable because the application cannot write more data to the kernel than the size of the write buffer.
In summary, the value for net.ipv4.tcp_limit_output_bytes should be set according to the network's BDP, possibly with some buffer for variability, but should not be set to zero or less than the write buffer size to prevent under-utilization of the available bandwidth. Proper tuning requires an understanding of the specific network conditions and potential competing traffic. It should be done with care and tested under realistic scenarios to assess the impact of changes.
When you set net.ipv4.tcp_limit_output_bytes, you are controlling the maximum number of bytes that can be queued for transmission on the TCP socket, which is separate from the existing socket write buffer. The socket write buffer determines how much data an application can write to the TCP socket before the write call blocks or returns (if the socket is non-blocking), whereas net.ipv4.tcp_limit_output_bytes limits the amount of data that can be "in flight" across the network before TCP will prevent additional writes to the network, regardless of write buffer space.
There are a couple of reasons why socket write buffers are subject to auto-tuning while net.ipv4.tcp_limit_output_bytes is a fixed value:
Auto-Tuning of Socket Buffers:
The TCP stack is designed to auto-tune socket buffer sizes for optimal performance based on the observed network conditions. Modern operating systems can adjust the size of these buffers dynamically as the network conditions change, such as variations in bandwidth or latency, to optimize resource usage and performance.
The idea behind this is to make better use of memory and adapt to a wide range of environments without expecting the user to manually adjust buffer sizes. Dynamic sizing allows the system to scale buffer sizes down when bandwidth or RTT is low (lower BDP), thus conserving memory, and to scale them up when network capacity and delays increase (higher BDP) to fully utilize the available bandwidth.
Fixed Value for net.ipv4.tcp_limit_output_bytes:
On the other hand, net.ipv4.tcp_limit_output_bytes is typically a fixed value set by the administrator to impose an artificial upper bound on the amount of outstanding data allowed, typically as a form of congestion management or to limit bufferbloat.
Having a fixed limit allows administrators to set a policy that aligns with their desired network behavior, such as maintaining low latency by preventing excessive queuing, or ensuring fair bandwidth sharing among many connections. The fixed nature makes it suitable for network administrators who want to enforce specific limits based on their understanding of the network's characteristics and performance goals.
Ultimately, the fixed value for net.ipv4.tcp_limit_output_bytes is a way to give control over how aggressive TCP can be with its transmissions, offering a method to balance throughput and latency outside of the standard congestion control algorithms. But unlike the auto-tuned socket buffers, it requires manual tuning and does not adapt to changing network conditions on its own.
In contrast, net.ipv4.tcp_limit_output_bytes is a system-wide setting that acts as a cap on the amount of data that the TCP stack can have in the network (on the wire) without receiving an acknowledgment, regardless of the size of the write buffer. It doesn't allocate any memory; it's simply a threshold that, once reached, will cause the TCP stack to temporarily stop sending more data, even if there is still space in the socket write buffer.
So, while the socket write buffer determines how much data the application can "write" into the kernel, net.ipv4.tcp_limit_output_bytes determines how much of that data can actually be "sent out and unacknowledged" at any point in time. It's a traffic control mechanism aimed at preventing the network from becoming overwhelmed with too much data (that might lead to congestion and increased latency), and is part of TCP's congestion control strategy.
By imposing this limit, the TCP/IP stack can manage the pacing of the data that leaves the host, helping to prevent network congestion. When this limit is reached, the TCP/IP stack will refrain from transmitting any more data until some of the in-flight data has been acknowledged by the receiver, ensuring that the amount of buffered data at the network layer does not exceed a pre-set amount.
net.ipv4.tcp_limit_output_bytes
If you set net.ipv4.tcp_limit_output_bytes to the maximum allowed value, it does not mean that the congestion control algorithm will send data beyond what the receiver's TCP window can accept. Here's why:
Receiver's Window:
Each TCP connection has a receiver window (advertised window), which is the amount of data the receiver can accept and buffer at any given moment. This window size is communicated to the sender and dictates how much data can be in-flight before receiving further acknowledgment.
The sender cannot send data exceeding this receiver window because doing so would violate the TCP flow control protocol, potentially leading to data loss if the receiver cannot buffer the excess data.
Congestion Control:
TCP's congestion control algorithm dynamically adjusts the amount of data that can be in-flight based on network conditions. It increases the congestion window when acknowledgments are received promptly (indicating a clear path) and decreases it in response to network congestion signals (like packet loss or ECN-CE marks).
The congestion control algorithm works independently of net.ipv4.tcp_limit_output_bytes and operates within its bounds. If the congestion window (cwnd) calculated by the congestion control algorithm is smaller than net.ipv4.tcp_limit_output_bytes, then cwnd prevails and the sending rate is limited accordingly.
Even if net.ipv4.tcp_limit_output_bytes is set to a large value, the actual amount of data sent cannot exceed the minimum of the current congestion window and the receiver's advertised window.
By setting net.ipv4.tcp_limit_output_bytes to a large value, you essentially allow the TCP congestion control algorithm to operate without an artificial constraint imposed by this parameter. However, the transmission will still be limited by the congestion window and the receiver's window, ensuring that the sender respects the network's available bandwidth and the receiver's ability to handle incoming data.
In essence, proper congestion control cannot solely rely on unlimited net.ipv4.tcp_limit_output_bytes. Instead, it must consider dynamic network conditions and the receiver's limitations to prevent congestion and ensure efficient data transmission within TCP's flow control and congestion control mechanisms.
If you don't need any artificial cap on the amount of unacknowledged data (data in-flight) and you want to rely solely on the built-in TCP congestion control mechanisms to manage traffic, you could set net.ipv4.tcp_limit_output_bytes to a very high value to effectively disable this limit.
The maximum value for net.ipv4.tcp_limit_output_bytes is determined by the maximum value that can be stored in an unsigned 32-bit integer, which is 4294967295 (2^32 - 1). Setting it to this value would mean the cap is so high that it is unlikely to ever be the limiting factor in the amount of data in flight.
However, before setting it to the maximum, here are some points to consider:
Network Stability: A large or maximum value for this parameter means you are trusting the congestion control mechanisms completely to manage the data flow. This is generally fine in well-behaved networks with stable latency and no known issues with bufferbloat.
Bufferbloat: By removing the cap, you might inadvertently contribute to bufferbloat if the network devices along the path have oversized buffers. Bufferbloat occurs when too much data is allowed to queue in network buffers, causing high latency and jitter.
Congestion Control Performance: TCP congestion control algorithms are designed to dynamically adjust to network conditions and should prevent congestion on their own. However, tuning net.ipv4.tcp_limit_output_bytes might still be beneficial in certain scenarios, such as in networks with highly variable bandwidth or in cases where there are specific throughput goals or latency requirements to be met.
Testing Changes: Any modification to TCP parameters should be made in a controlled environment and tested for the particular use case. It's important to monitor the network performance before and after the change to ensure no adverse effects occur.
Specific Use Cases: In some specialized high-speed networking environments (e.g., data centers, high-performance computing clusters), such limits are often increased or set high to allow for full utilization of available bandwidth, as these networks are typically engineered to handle large amounts of data with minimal congestion.
In practice, many systems will never reach such high values due to the constraints of their physical or virtual network interfaces, the effective bandwidth of their network paths, and the limits imposed by the congestion control algorithms themselves. It is often unnecessary to set net.ipv4.tcp_limit_output_bytes to its maximum value unless you're dealing with a very specific networking situation where the default limits are known to be a bottleneck.
The net.ipv4.tcp_notsent_lowat parameter in Linux controls the threshold for the low water mark of not yet sent data in the write buffer of a TCP socket. Specifically, it is the number of bytes of unsent data in the socket's send buffer below which the socket becomes writable again, notifying any processes that are waiting to send more data.
Here's an example to illustrate how the net.ipv4.tcp_notsent_lowat parameter works with different values:
Suppose we have a simple client-server application where the client continuously sends data to the server as quickly as it can. Let's consider the send buffer size to be 500,000 bytes (for the sake of example).
With net.ipv4.tcp_notsent_lowat set to its maximum possible value (2^32 - 1 or 4294967295), which effectively disables this feature, the client application will only be notified when the TCP send buffer is empty (or nearly empty), because this threshold is higher than the buffer size itself.
The application can write data to the socket until the buffer is full. Once the buffer is full, the application will have to wait until all (or nearly all) the data has been sent and acknowledged before it can write again.
Modified Low Water Mark (net.ipv4.tcp_notsent_lowat = 100000):
If we now set net.ipv4.tcp_notsent_lowat to 100,000, it means the socket will become writable (and the application will be notified) when there are 100,000 or fewer bytes of unsent data in the send buffer.
The client application can write data until the buffer is full. If the send buffer gets filled, the application has to wait. But once the amount of unsent data drops below 100,000 bytes (because data is sent out and space is freed up), the application will be notified and can resume sending data without waiting for the entire buffer to clear.
Low Low Water Mark (net.ipv4.tcp_notsent_lowat = 1):
Further lowering the net.ipv4.tcp_notsent_lowat to just 1 byte means the socket is almost always writable as long as there's free space in the send buffer.
This makes the client application highly responsive because it can almost immediately resume sending once any amount of data has been sent out, keeping the pipeline more continuously filled and possibly leading to better throughput, but potentially at the cost of more frequent wake-ups and less efficient use of system calls.
In summary, the net.ipv4.tcp_notsent_lowat parameter helps control the flow of data from the application to the TCP stack by setting a threshold for when the application is allowed to resume writing to the socket. It can be helpful for fine-tuning performance for applications that rapidly send data over TCP and want to avoid the overhead of waiting for the socket's send buffer to completely drain before writing again. However, specialists typically use such tuning in specific use cases since the default behavior suffices for most applications.
epoll
Non-Blocking Sockets: When sockets are in non-blocking mode, if the send buffer is full, a call to send or write will not block. Instead, it will return an error (typically EAGAIN or EWOULDBLOCK). The application will then typically use epoll or another I/O event notification system to know when it can attempt to write again.
epoll and I/O Multiplexing: With epoll, the application can wait for multiple file descriptors to become ready for I/O operations without blocking. When a TCP socket's send buffer has enough space (below the net.ipv4.tcp_notsent_lowat threshold), epoll will report that the socket is ready for writing (i.e., it has hit the "low water mark").
For blocking sockets, the concept of a low water mark doesn't apply in the same way, because a blocking send or write call will simply wait (block) until it can transfer some or all of the data. The application doesn't need to be notified when it can write again because it's not responsible for checking—instead, the call will just eventually succeed once there's space available.
In summary, the net.ipv4.tcp_notsent_lowat parameter is most useful when an application is managing non-blocking sockets and needs to efficiently determine when it can resume sending data without polling the kernel. In blocking mode, the kernel manages write readiness internally, and the application does not need to act on such notifications.
These parameters are advanced Linux TCP settings that allow you to control various aspects of TCP behavior within the kernel. Here is what each one does:
net.ipv4.tcp_autocorking = 1
This setting controls TCP autocorking, which is similar to TCP_CORK. When autocorking is enabled (set to 1), the kernel attempts to automatically optimize sending small packets by temporarily "corking" the connection to accumulate data in the send buffer and send fewer, larger packets. When set to 0, autocorking is disabled. This can be particularly beneficial for workloads that frequently send small bursts of data, such as a web server.
net.ipv4.tcp_available_ulp
ULP stands for Upper Layer Protocol. This read-only sysctl displays a list of available TCP ULPs (User-Level Protocols) that can be loaded on top of the TCP stack, such as MPTCP (Multipath TCP). It doesn't take a value per se; it's more like an informational parameter.
net.ipv4.tcp_early_demux = 1
This setting, when enabled, allows the kernel to demultiplex incoming TCP packets to the appropriate socket before the full handling of the packet within the kernel. This can help reduce latency, especially in high-performance scenarios like receiving data for established connections. However, some networking features might rely on delayed demultiplexing, so it may need to be disabled for compatibility reasons.
net.ipv4.tcp_early_retrans = 3
This setting governs TCP's behavior with regard to retransmitting packets that are believed to be lost - what is known as "early retransmit". There are different levels (from 0 to 3) that dictate how aggressively the kernel will retransmit unacknowledged segments before the standard RTO (Retransmission Timeout) has elapsed. Using early retransmit can help reduce retransmission timeout-induced delays in communication, but aggressive early retransmits can also increase the bandwidth usage if non-lost packets are retransmitted unnecessarily.
net.ipv4.tcp_ecn = 2
TCP ECN stands for Explicit Congestion Notification, a mechanism that allows network nodes to signal congestion to the endpoints before loss occurs, letting senders reduce their transmission rate preemptively. When this is set to 1, ECN is enabled and will be used when both endpoints support it. When it's set to 2 (the default), ECN usage is attempted, and if any issues are encountered, TCP falls back to not using ECN for the remainder of the connection.
net.ipv4.tcp_ecn_fallback = 1
When this is enabled (set to 1), the kernel will allow a TCP connection to fall back to not using ECN if any issues with ECN negotiation are encountered during the initial handshake. If set to 0, connections that fail to establish using ECN will be reset.
net.ipv4.tcp_fwmark_accept = 0
When enabled (set to 1), this setting allows incoming connections to inherit the fwmark of the listening socket. fwmark is a mark that can be set on sockets using the SO_MARK socket option, which can be used to match traffic against specific iptables firewall rules. This is typically used in advanced routing scenarios.
net.ipv4.tcp_l3mdev_accept = 0
This parameter, when set to 1, allows the TCP stack to accept incoming packets that have been routed via an l3mdev (L3 master device, such as a VRF - Virtual Routing and Forwarding instance). If set to 0, packets arriving on l3mdev that do not match the socket's associated device will be dropped.
Adjusting these parameters requires a good understanding of your network topology and traffic patterns, as well as the specific behaviors and compatibility requirements of the applications that will be affected by them. They should be modified with care, and changes should be tested thoroughly to ensure positive outcomes.
Delayed Demultiplexing:
Some network features that may rely on delayed demultiplexing include those that require inspecting or modifying packets higher up in the network stack before determining the destination socket, such as:
Load Balancers and Reverse Proxies: These often need to inspect the destination address and port within packet payloads (e.g., for HTTP Host headers) to route traffic appropriately.
Firewalls and Network Address Translators (NAT): They may manipulate packet headers, which requires delayed demultiplexing to decide on how to modify or route a packet before it reaches the application.
Deep Packet Inspection: Systems that analyze the content of network packets for security, monitoring, or traffic shaping may require analyzing the payloads before the packets are delivered to the correct socket.
Values for net.ipv4.tcp_early_retrans:
Here's when to consider different values for net.ipv4.tcp_early_retrans:
0: Disables early retransmit. Use this if you have a highly stable network with minimal packet reordering, and you wish to avoid any unnecessary retransmissions.
1: Enables early retransmit only after an ACK has been received for a segment transmitted after the lost segment. This mode is less aggressive and can be used on networks with some degree of reordering.
2: Enables a more aggressive form of early retransmit which will be triggered without needing an ACK for a post-loss segment, however, it is only triggered when there are new data to send. It's a balance between performance and cautious network use.
3: The most aggressive mode, where an early retransmission can be triggered without an ACK for subsequent segments. Use this in a network where reordering is uncommon, and low latency is crucial, as it will help to minimize retransmission delay.
Each level incrementally reduces the constraints on when early retransmission can occur, possibly at the cost of increasing unnecessary retransmissions due to misinterpreting out-of-order delivery as a sign of packet loss.
Explicit Congestion Notification (ECN):
ECN works by allowing network devices to mark packets as experiencing congestion without dropping them. This is done using two bits in the IP header that a router can set to indicate congestion to the receiving host. The receiver, in turn, notifies the sender of the congestion through TCP's ECHO and CWR flags, so the sender can adjust its sending rate preemptively.
ECN can be beneficial in avoiding packet losses and therefore providing a smoother and sometimes higher throughput. However, you might choose not to enable ECN if:
Interoperability: Older or misconfigured network equipment may not properly handle ECN-enabled packets, resulting in connectivity issues or degraded performance.
Performance Impact: In networks where routers do not support ECN or the small benefit of reduced packet loss does not justify the potential interoperability risks.
L3mdev (L3 Master Device):
An L3 master device is an interface associated with a particular L3 domain, such as a Virtual Routing and Forwarding (VRF) instance. VRF allows the coexistence of multiple instances of a routing table within the same router at the same time. This capability is useful for:
Multi-tenancy: Isolating network traffic for different tenants in a shared infrastructure.
VPNs: Creating separate routing tables for different VPN customers or services.
Segmenting: Network segmentation for security or administrative purposes.
You would route packets through an L3mdev when you need to maintain separate network namespaces or routing tables for different services or tenants. It helps manage traffic routing in a fine-grained, isolated manner without interfering with the global routing table. If your network design doesn't require these features, you might not need to enable tcp_l3mdev_accept.
These parameters are part of the sysctl mechanism provided by the Linux kernel to control various aspects of the network stack, particularly the TCP protocol behavior. Here’s a breakdown of what each of these settings does:
net.ipv4.tcp_moderate_rcvbuf = 1
Enables the kernel's ability to automatically tune the TCP receive buffer size (i.e., auto-tuning) according to the memory used by the connection and the actual rate at which data is received. This can optimize the use of buffer space, improving throughput and reducing memory bloat.
net.ipv4.tcp_no_ssthresh_metrics_save = 1
When set to 1, disables the feature where the kernel saves the slow start threshold (ssthresh) of prior TCP connections on a per-destination basis. Saved ssthresh values might help in optimizing the start of new connections to the same destinations, but this setting will turn off the saving of such metrics.
net.ipv4.tcp_recovery = 1
Enables TCP loss recovery as specified by RFC 4015, which defines the "Loss Recovery Mechanism for TCP". This generally involves improved algorithms for dealing with packet loss, retransmission, and recovery and may result in more robust TCP performance in networks that experience varying levels of congestion.
net.ipv4.tcp_reflect_tos = 0
Determines if the Type of Service (TOS) field from incoming to outgoing packets should be reflected by the TCP stack. When disabled (0), the outgoing packets will not automatically inherit the TOS values from the incoming packets.
net.ipv4.tcp_rx_skb_cache = 0
Controls whether socket buffer (skb) caching is enabled for the TCP receive path. Caching received skbs may improve performance by reducing the time spent allocating and freeing memory, but this is set to 0 (disabled) by default.
net.ipv4.tcp_stdurg = 0
Sets whether the TCP stack should interpret the URGENT pointer in a TCP segment using the "old" (non-compliant) BSD interpretation (1) or the standard one defined in the RFCs (0). This is rarely set to anything other than the default (0), as the standard interpretation is almost universally adopted.
net.ipv4.tcp_thin_linear_timeouts = 0
Dictates whether the TCP retransmission timeouts (RTOs) for "thin" streams, which typically represent interactive flows with small amounts of data, will be handled using linear back-off instead of exponential. This feature is intended to improve the responsiveness of such connections during loss and is disabled (0) by default.
net.ipv4.tcp_tso_win_divisor = 3
Defines the divisor used to limit the TCP Segment Offloading (TSO) size by the window size. The TSO size is reduced to the "window size" divided by this divisor, which prevents sending very large bursts of data on connections with large windows.
net.ipv4.tcp_tx_skb_cache = 0
Similar to tcp_rx_skb_cache, but for the transmit path. Controls whether skbs are cached for TCP data transmission, which can theoretically improve performance. This is also disabled by default (0).
net.ipv4.tcp_workaround_signed_windows = 0
Provides a workaround for TCP window scaling issues with old, broken routers that might incorrectly handle the "window scale" option, leading to a signed interpretation of the window size. When 1, this enables a workaround, and is typically not needed unless you're experiencing issues with such devices in your network.
These settings should generally be left at their defaults unless there's a specific behavior you wish to tune based on network performance analysis or compatibility reasons. Adjusting them without comprehensive network knowledge can lead to unexpected behavior or decreased performance.
net.ipv4.tcp_reflect_tos usage:
This setting may be enabled when you want the Type of Service (TOS) field in the IP header to be reflected from incoming to outgoing packets automatically. This could be useful in maintaining certain quality of service (QoS) requirements throughout a conversation between two endpoints. For example, if the incoming packets are marked with a TOS field that prioritizes low latency, you might want net.ipv4.tcp_reflect_tos enabled so that the outgoing acknowledgment packets are similarly prioritized by intermediate routers. However, this is typically managed by applications or intermediate network devices like routers, so it isn't commonly enabled on end hosts.
Efficiency of net.ipv4.tcp_no_ssthresh_metrics_save:
Setting net.ipv4.tcp_no_ssthresh_metrics_save to 0 enables the saving of slow start threshold (ssthresh) metrics, which may help optimize the start of new TCP connections to the same destination. This is because the TCP stack can reuse the previous connection's ssthresh as a starting point, potentially avoiding unnecessary slow start phases that can occur if the ssthresh starts too low. This can be efficient for environments with stable network conditions where past performance metrics are likely to be relevant for future connections.
TCP Receive Path and SKB Caching:
The TCP receive path refers to the processing sequence TCP packets undergo in the kernel after being received from the network and before being passed to the user-space application. Socket buffers (SKBs) are data structures used in the Linux kernel to manage network packets.
Caching SKBs for the receive path (if such functionality is available) could improve performance by reducing the time spent allocating and deallocating these structures with each packet that is received. However, SKB caching is typically disabled by default (tcp_rx_skb_cache = 0) because it can increase memory usage and might not always result in a performance gain, especially on systems that are not under high network load or handle more diverse traffic.
Disabling net.ipv4.tcp_thin_linear_timeouts:
Disabling this setting (net.ipv4.tcp_thin_linear_timeouts = 0) means staying with the default exponential backoff for retransmission timeouts. This setting would be enabled for "thin" streams (e.g., telnet or SSH sessions) where consistency of response is more important than throughput, and it is preferable to have a steady retransmission schedule in case of packet loss. However, using standard exponential backoff for retransmission timeouts (FRTO or not) helps prevent network congestion by reducing the number of packets retransmitted in a lossy environment. FRTO (Forward RTO-Recovery) is a separate algorithm that seeks to distinguish between spurious timeouts and real packet loss.
Working of net.ipv4.tcp_tso_win_divisor:
The net.ipv4.tcp_tso_win_divisor setting is used to limit the size of TCP segments that are offloaded for transmission by the network interface (using TCP Segment Offloading, TSO). For example, if the TCP congestion window allows you to send 120,000 bytes but your tcp_tso_win_divisor is set to 3, then the maximum segment size offloaded to the hardware would be 40,000 bytes (120,000/3). This prevents sending too large bursts that could result in bufferbloat or overwhelming the receiver. This relates to the TSO feature in the networking hardware which lets the hardware handle the segmentation of a large TCP payload into smaller packets, reducing CPU overhead. The divisor gives a measure of control over the burstiness of TSO.
Does it allocate a fixed memory per connection?
The caching of SKBs does not normally allocate a fixed amount of memory per connection. Instead, it works by keeping a small pool of recently freed SKBs that can be quickly reused for new packets. This pool is not specific to any one connection but is available for use by any part of the network stack handling incoming packets.
The goal of SKB caching is not to reserve memory for specific connections, but to have a ready supply of buffers to handle incoming packets more efficiently across all connections. However, because these caches could potentially grow to a large size under heavy network load, there might be limits in place on how many SKBs can be cached.
It's also worth noting that the presence and behavior of SKB caching can vary depending on the kernel version and configuration, as it's an optimization that might not be applicable in all environments or might have been replaced by other, more effective mechanisms in newer kernels.
The decision to enable or disable SKB caching (if it's not already managed automatically by the kernel) should be made based on an understanding of the specific network workloads and performance characteristics, as well as through monitoring and testing to ensure it produces a net benefit.
Fast Recovery: This mechanism is triggered by Fast Retransmit. Fast Recovery allows the sender to continue transmitting new data (if available) while also retransmitting the lost segment, avoiding the need to reduce the congestion window to a single segment (which would happen in a slow start).
Selective Acknowledgments (SACK): SACK informs the sender about which data have been received successfully, allowing the sender to retransmit only the missing segments instead of everything after the missing segment. SACK can be particularly effective in cases where multiple packets have been lost.
Forward Acknowledgment (FACK)/NewReno: Variants of TCP that extend recovery capabilities beyond what original TCP Reno provides. NewReno, for instance, improves the Fast Recovery algorithm by better handling multiple packet losses within a single congestion window.
The tcp_recovery setting allows the kernel to use more sophisticated and efficient ways to handle packet loss and to recover from it, in line with the modern standards set by the IETF. Disabling it (net.ipv4.tcp_recovery = 0) would tell the TCP stack to use older, less efficient mechanisms for loss recovery that are more compatible with very early versions of TCP that predate these improvements.
While the RFCs related to these advanced features suggest that they improve network performance, there can be reasons to disable them in some scenarios:
Interoperability: In networks with older devices or software that do not support or properly handle these advanced TCP features, disabling net.ipv4.tcp_recovery might avoid compatibility issues.
Debugging: During troubleshooting, it can be helpful to simplify the TCP behavior to isolate issues.
Performance Testing: Network administrators may wish to compare the impact of these features on network performance through controlled experiments.
Overall, it is generally recommended to leave net.ipv4.tcp_recovery enabled for better performance and more efficient loss recovery unless a specific issue or requirement dictates otherwise. Disabling advanced recovery features could lead to suboptimal performance, especially in networks where packet loss is common.
The tcp_tso_win_divisor parameter influences the size of the segments that are offloaded to the NIC for TSO. It does this by dividing the maximum window size advertised by the peer by the value of tcp_tso_win_divisor to calculate the maximum size of a TSO segment that the NIC should use.
Here's how it works:
A higher tcp_tso_win_divisor reduces the maximum TSO segment size, which can result in more evenly distributed packet transmission over time. This may prevent sending very large bursts of data, which might otherwise result in microbursts or bufferbloat in the network.
A lower tcp_tso_win_divisor means larger TSO segments can be offloaded at once, which might be more efficient in terms of CPU utilization but can lead to larger bursts of data being sent if the congestion window is large.
In terms of multiple connections, the tcp_tso_win_divisor doesn't directly control how offloading is distributed across them. However, by controlling the size of the TSO segments, it indirectly affects how network traffic is shaped for all connections capable of using TSO. If the calculated segment size results in more segments sent more frequently, it can have the effect of mixing the traffic from multiple connections more evenly across time, potentially avoiding the situation where one connection can dominate the use of the network link due to large bursts.
In summary, while net.ipv4.tcp_tso_win_divisor is relevant for hardware offloading (TSO), it's not just used to evenly distribute offloading for multiple connections. Its main purpose is to control the burstiness of TSO by limiting the size of the data bursts that the NIC is allowed to send, which indirectly can lead to a more even distribution of data across different connections.
ToS (Type of Service):
ToS is a field in the IPv4 header that was originally intended to specify how an internet service should make trade-offs between throughput, latency, reliability, and cost. It can be used to indicate the quality of service (QoS) desired by the packet. It includes what is now called the DSCP field, which specifies the level of service that should be provided to the packet.
QoS (Quality of Service):
QoS refers to the overall performance of your network traffic, which can be measured by factors such as error rates, bandwidth, throughput, transmission delay, availability, and jitter. In networking, QoS is the ability to provide different priority to different applications, users, or data flows, or to guarantee a level of performance to a data flow.
In general, while QoS policies can be strictly enforced within a controlled network such as an enterprise LAN or a well-managed WAN, adherence to these policies on the public internet is neither guaranteed nor consistent, and often QoS markings may be stripped or altered by network intermediaries. Therefore, when sending traffic over the internet, you should not rely on QoS markers like ToS or DSCP being respected end-to-end. However, these fields can still be very useful within private networks where you have control over the network devices and their configurations.
net.ipv4.tcp_rx_skb_cache:
This setting would enable caching of SKBs on the receive path, which can reduce the CPU time spent on allocating and freeing these structures as packets are received.
net.ipv4.tcp_tx_skb_cache:
Similarly, this setting would enable caching of SKBs on the transmit path, conserving CPU resources when sending packets.
Do you need both to improve CPU performance?
Whether enabling these caches will improve CPU performance depends to a certain extent on the nature of the traffic your system is handling:
For mixed or balanced traffic: If your system handles both incoming and outgoing TCP traffic in relatively equal measure, then enabling both caches could improve CPU efficiency because it handles both receiving and sending packets efficiently.
For mostly inbound traffic: If the system predominantly handles inbound connections (e.g., a web server), then net.ipv4.tcp_rx_skb_cache might offer more benefits.
For mostly outbound traffic: If the system is primarily sending data (e.g., a file server), then net.ipv4.tcp_tx_skb_cache might be more useful.
However, these settings are somewhat nuanced:
These caches must be managed carefully to ensure they provide net performance benefits without consuming disproportionate amounts of memory.
Sometimes, the kernel's built-in mechanisms for managing memory allocation and freeing are already optimized for the typical workloads they encounter. This means that manually enabling these caches might not offer a significant improvement and could even degrade performance by increasing memory usage unnecessarily.
Not all versions of the Linux kernel may support these settings. They may be experimental features or could have been phased out or replaced by other, more comprehensive optimizations in newer kernels.
Consequently, whether to enable these settings requires careful consideration of your system's workload, the version and configuration of your Linux kernel, and the available system resources. Testing and benchmarking with your specific applications and traffic patterns is the best way to determine if enabling these caches will provide the desired CPU performance improvement.
Traffic volume and patterns: The amount of memory consumed by the SKB caches will correlate with the number and size of packets being received and sent. Systems with heavy network traffic will see more SKBs being cached, hence using more memory.
SKB Cache Limits: Depending on the Linux kernel version and configuration, there may be limits to how many SKBs can be cached. These limits help to prevent the caches from using an excessive amount of memory.
Dynamic Allocation: SKB caching is designed to be dynamic, reusing recently freed SKBs up to a certain limit. Memory usage will increase with the cache enabled, but only to a point where the cached SKBs can be efficiently reused.
System Resources: The available memory of the system also plays a role. On a system with ample memory, the percentage increase in memory usage may be negligible, while on systems with limited memory, it might be more significant.
Kernel Version and Features: Different kernel versions might implement these caches and their management differently, affecting how much memory is used.
As socket buffers are not particularly large by themselves (an SKB can be around a couple of hundred bytes plus the actual data), the memory overhead with the caches enabled may not be exorbitant for most systems under normal workload conditions. Yet, in very high-performance environments or under heavy network load, the memory usage could be more noticeable and should be monitored.
To determine the actual impact on your system, it's best to conduct empirical testing while monitoring memory usage through tools like htop, free, vmstat, /proc/meminfo, or more detailed memory profiling tools. This testing can quantify the impact of enabling these options on your system's memory usage under its specific operational conditions.
0
ssthresh
Not beneficial to use (net.ipv4.tcp_no_ssthresh_metrics_save = 1):
On the other hand, setting it to 1 (metrics save disabled) can be preferable in highly dynamic network conditions or when connections are not repeated to the same destinations frequently. In such cases, previously saved ssthresh values might not be representative of the current network state, so starting slow start with the default behavior might prevent using an inaccurate ssthresh that could either be too aggressive and cause congestion or too conservative and degrade performance.
In summary, enabling ssthresh metrics save is generally beneficial for repeat connections in stable network environments, while disabling it may help in networks where conditions change rapidly or where connections to the same destinations are not consistently repeated. As with most kernel settings, the right choice depends on the specific use case and testing is recommended to determine the best configuration for your environment.
net.ipv4.tcp_early_retrans
When net.ipv4.tcp_early_retrans is set to 1:
Early retransmit is enabled but is more conservative. A TCP segment is retransmitted early only after an acknowledgment is received for data that was sent after the lost packet. This implies that if there's packet reordering — that is, if a packet appears to be missing because packets sent after it have been acknowledged — TCP won't immediately retransmit. It waits for a small number of duplicate acknowledgments (DUPACKs) first, to be sure that the packet is indeed lost and not just delayed. This property can help avoid unnecessary retransmissions caused by reordering.
Behavior differences between net.ipv4.tcp_early_retrans values 2 and 3:
With net.ipv4.tcp_early_retrans = 2, TCP performs early retransmit more aggressively than at 1 but won't retransmit merely due to reordering. The early retransmit can still be triggered without requiring an ACK for a segment sent after the lost segment. This level attempts to start the retransmission timer earlier, which can decrease latency by addressing loss sooner than standard retransmission algorithms would.
With net.ipv4.tcp_early_retrans = 3, it becomes even more aggressive. Early retransmit will now trigger as soon as possible when loss is suspected, not accounting for reordering. At this level, if packet loss is indicated by DUPACKs, the early retransmission will occur immediately without waiting for an ACK of subsequent data, which attempts to recover from packet loss with minimal delay. Thus, setting it to 3 can further reduce latency in scenarios where the fastest recovery from packet loss is more critical than the possibility of unnecessary retransmission due to misinterpreting out-of-order packets as losses.
The trade-off between these values is between potentially reducing latency (with aggressive early retransmission) and avoiding unnecessary retransmissions (which could occur with packet reordering). Systems concerned with low latency (like real-time applications) can benefit from a more aggressive early retransmit strategy, while systems where bandwidth or congestion is a more significant concern might opt for a less aggressive setting.
As always with TCP tuning, the optimal setting can vary depending on the network conditions, and such changes should be tested thoroughly to ensure they positively impact the desired performance metrics.
The net.ipv4.tcp_early_retrans sysctl setting in Linux controls the aggressiveness of the early retransmission when TCP detects a packet loss. As we go from 1 to 3, the conditions under which an early retransmit is triggered become less stringent.
Here's how the mechanism changes between the values 1, 2, and 3:
net.ipv4.tcp_early_retrans = 1:
Condition for Retransmission: An early retransmission occurs only after TCP receives an acknowledgment for a packet sent after the one that appears to be lost.
Mechanism: This is less aggressive and helps to avoid unnecessary retransmissions that might occur because of out-of-order packets. It is a conservative approach that works well when packet reordering might be present.
net.ipv4.tcp_early_retrans = 2:
Condition for Retransmission: TCP triggers early retransmit without needing to receive subsequent ACKs. However, early retransmission happens only if there are outstanding unacknowledged segments in the send queue.
Mechanism: This is more aggressive than 1 and can help improve retransmission times in cases where mild packet reordering exists.
net.ipv4.tcp_early_retrans = 3:
Condition for Retransmission: TCP triggers early retransmission immediately upon detection of a potential loss, indicated by duplicate ACKs.
Mechanism: This is the most aggressive setting, and TCP will retransmit even if there are no subsequent segments outstanding (even when the send queue is empty). It minimizes latency by quickly retransmitting lost segments but may increase unneeded retransmissions when packet reordering is mistaken for a packet loss.
The main difference between 1 and 2 is that 1 waits for an acknowledgment that arrives for data sent after the lost segment before retransmitting, potentially delaying the retransmission, whereas 2 does not require such an acknowledgment, thus reacting faster to the suspected loss. On the other hand, 3 is ready to retransmit immediately based on duplicate ACKs, without waiting for any further signal of loss or the presence of unacknowledged data in the queue. The faster reaction in 3 might be optimal for reducing latency at the risk of triggering unnecessary retransmissions if the duplicate ACKs were caused by packet reordering.
When to use each setting depends on the characteristics of the underlying network:
If the network experiences considerable packet reordering, it may be advantageous to use a less aggressive setting (1) to avoid the unnecessary overhead of retransmissions.
If the network has low latency requirements and minimal packet reordering, a more aggressive setting like 2 or 3 can help minimize response times to actual packet loss, benefiting applications that demand quick reactions, such as real-time communications or interactive applications.
This contrasts with the conservative approach of 1, where early retransmission requires not just DUPACKs but an acknowledgment for data sent after the lost packet, and with the aggressive approach of 3, where early retransmission occurs immediately after DUPACKs are received and does not consider whether new data is queued for transmission.
So, to summarize, with net.ipv4.tcp_early_retrans = 2, the early retransmission is triggered by DUPACKs, provided there is pending data to send. This allows for a compromise between quick loss recovery and avoiding unnecessary transmissions that might be due to packet reordering in more heavily loaded network conditions.
Certainly, let's clarify the differences in the triggers for early retransmission when net.ipv4.tcp_early_retrans is set to 1, 2, or 3.
net.ipv4.tcp_early_retrans = 1:
TCP will not execute an early retransmit immediately after receiving a small number of duplicate ACKs (DUPACKs).
The trigger for early retransmit in this mode is an acknowledgment for a segment sent after the one which is suspected to be lost. This implies that the network has successfully delivered a segment sent later, confirming that there likely was a loss rather than just reordering.
Early retransmission will occur if the ssthresh (slow start threshold) is undefined or after receiving DUPACKs, provided at least one more unacknowledged segment has been acknowledged in between.
net.ipv4.tcp_early_retrans = 2:
In this mode, TCP becomes more aggressive and can perform an early retransmission before the traditional retransmission timeout (RTO) expires, but it still considers whether new data is being sent.
Early retransmit is permitted upon the reception of a certain number of DUPACKs, suggesting a segment has been lost, even if no subsequent segment has been ACKed.
The main difference from 1 is that TCP does not wait for an ACK for data sent after the missing segment, allowing for a slightly more aggressive retransmit that could benefit connections that don't suffer from frequent reordering.
net.ipv4.tcp_early_retrans = 3:
This mode is the most aggressive setting for early retransmission and will trigger a retransmit as soon as duplicate ACKs imply any segment loss, without the need for further confirmation.
TCP does not require an ACK for a segment sent after the one that is lost or any evidence that there is more data to send. As soon as DUPACKs are received, TCP assumes a loss and acts immediately.
The lack of dependency on subsequent data or other loss confirmation minimizes the wait time before a retransmit and is aimed at reducing latency, but it can lead to unnecessary retransmissions in the case of simple packet reordering.
In summary:
With "1", TCP waits for a partial ACK (an ACK for a packet after the lost one) before starting a retransmit, which prevents unnecessary retransmits in the case of reordering.
With "2", TCP will retransmit earlier than "1", after the network gives a strong suggestion that a packet was lost, even if ACKs for later packets aren't received, but takes pending data into account.
With "3", TCP reacts in the swiftest and most aggressive manner to suspected packet loss, indicated by duplicate ACKs, without waiting for any additional network traffic that could confirm loss versus reordering.
net.ipv4.tcp_early_retrans = 2:
Early retransmit could trigger potentially after fewer than three DUPACKs, but only if there are outstanding unacknowledged segments in the send queue. This setting still allows for early retransmit before traditionally hitting three DUPACKs under the right conditions.
net.ipv4.tcp_early_retrans = 3:
Early retransmit will immediately trigger on receipt of DUPACKs without additional conditions, so it does not require exactly three DUPACKs to proceed with an early retransmission.
In essence, while the traditional fast retransmit mechanism relies on receiving three DUPACKs to indicate packet loss, the early retransmission optimization adjusted by net.ipv4.tcp_early_retrans can potentially allow for retransmission after fewer DUPACKs, depending on the level of aggressiveness configured (from more conservative with 1 to more aggressive with 3).
net.ipv4.tcp_early_retrans = 2:
Early retransmission may occur with potentially fewer than three DUPACKs, but only if there is outstanding unacknowledged data yet to be sent. This setting allows early retransmit without the strict requirement for a subsequent ACK, but still considers the presence of pending data.
net.ipv4.tcp_early_retrans = 3:
TCP will perform an early retransmission upon detecting DUPACKs, even without additional conditions. This setting is the most aggressive and does not require pending data or a partial ACK to trigger an early retransmission, which can be executed with potentially fewer than three DUPACKs.
It is important to note, however, that the policy for minimal DUPACKs before considering a packet lost can depend on kernel versions and implementations. Some implementations may still require at least two DUPACKs even in the most aggressive settings, to avoid false positives from single packet reordering incidents. The early retransmission in all modes is an optimization to address perceived packet loss sooner than the traditional fast retransmit, but the exact behavior can depend on the kernel's TCP stack implementation.
For more detailed or implementation-specific behaviors, reviewing the source code of the TCP subsystem of the Linux kernel or the relevant TCP RFCs and documents is advised.
When a packet is considered lost, the sender may retransmit the packet based on duplicate ACKs.
A subsequent ACK that advances the acknowledgment point but does not acknowledge all outstanding data is considered a "partial ACK."
The presence of a partial ACK can indicate that there have been multiple losses in the window of data in flight, and some of the lost segments have not yet been recovered. In terms of recovery mechanism, a partial ACK can alter the sender's behavior, such as by indicating it should continue retransmissions or adjust its recovery state.
For example, in the recovery phase following fast retransmit, if the sender receives an ACK that only acknowledges part of the outstanding data (thereby partially exiting recovery window), it generally signals that data segments might still be missing between the newly acknowledged data and the remaining unacknowledged data.
In the context of net.ipv4.tcp_early_retrans:
When set to 1, early retransmission can be triggered by a partial ACK as it implies that some segments are being acknowledged out-of-order, likely due to a segment being genuinely lost, rather than simple packet reordering.
It's important to understand that partial ACKs play a key role in loss recovery algorithms such as NewReno, which adjusts the congestion window in response to partial ACKs during fast recovery.