Refer to the official documentation (http://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt) for the following explanation:
Tcp_max_tw_buckets-INTEGER
Maximal number of timewait sockets held by system simultaneously.
If this number is exceeded time-wait socket is immediately destroyed
And warning is printed.
The official document does not describe the default value. After a few simple verification systems, it is preliminarily determined that the default value is 180000.
The source code shows that this option is relatively simple. The implementation code is as follows:
===== Linux-2.6.37 net/ipv4/tcp_minisocks.c 269 ======
Void tcp_time_wait (struct sock * sk, int state, int timeo)
{
Struct inet_timewait_sock * tw = NULL;
Const struct inet_connection_sock * icsk = inet_csk (sk );
Const struct tcp_sock * tp = tcp_sk (sk );
Int recycle_ OK = 0;
If (tcp_death_row.sysctl_tw_recycle & tp-> rx_opt.ts_recent_stamp)
Recycle_ OK = icsk-> icsk_af_ops-> remember_stamp (sk );
If (tcp_death_row.tw_count <tcp_death_row.sysctl_max_tw_buckets)
Tw = inet_twsk_alloc (sk, state );
If (tw! = NULL ){
// The allocation is successful and the TIME_WAIT status is processed. A lot of code is omitted here.
Else {
// Allocation failed, not processed, only logs recorded: TCP:
Time wait bucket table overflow
/* Sorry, if we're out of memory, just CLOSE this
* Socket up. We 've got bigger problems
* Non-graceful socket closings.
*/
NET_INC_STATS_BH (sock_net (sk), LINUX_MIB_TCPTIMEWAITOVERFLOW );
}
Tcp_update_metrics (sk );
Tcp_done (sk );
}
The test result shows that if the value is set to 100, the number of TIME_WAIT connections is stable at 100, and is not affected by the networking and other configurations.
There is a warning in the official manual:
This limit exists only to prevent
Simple DoS attacks, you _ must _ not lower the limit artificially,
But rather increase it (probably, after increasing installed memory ),
If network conditions require more than default value.
Basically, this is used to prevent DoS attacks. We should not manually reduce them. If network conditions are needed, they should increase.
But in fact, this risk is not big for our LAN or company intranet applications.