Skip to contentSkip to conversation

tcp: introduce tcp_tw_interval to specifiy the time of TIME-WAIT

RFC PATCH In review Cong Wang 4 participants 15 messages Sep 27, 2012 – Oct 9, 2012

Subsystems (4)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

RFC PATCH 1/1 tcp: introduce tcp_tw_interval to specifiy the time of TIME-WAIT

Some customer requests this feature, as they stated:

"This parameter is necessary, especially for software that continually creates many ephemeral processes which open sockets, to avoid socket exhaustion. In many cases, the risk of the exhaustion can be reduced by tuning reuse interval to allow sockets to be reusable earlier.

In commercial Unix systems, this kind of parameters, such as tcp_timewait in AIX and tcp_time_wait_interval in HP-UX, have already been available. Their implementations allow users to tune how long they keep TCP connection as TIME-WAIT state on the millisecond time scale."

We indeed have "tcp_tw_reuse" and "tcp_tw_recycle", but these tunings are not equivalent in that they cannot be tuned directly on the time scale nor in a safe way, as some combinations of tunings could still cause some problem in NAT. And, I think second scale is enough, we don't have to make it in millisecond time scale.

See also: https://lkml.org/lkml/2008/11/15/80

Any comments?

Cc "David S. Miller" <[email protected]>
Cc Alexey Kuznetsov <[email protected]>
Cc Patrick McHardy <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neil Horman <[email protected]>

---

Documentation/networking/ip-sysctl.txt +6 -0
index c7fc107..4b24398 100644
@@ -520,6 +520,12 @@ tcp_tw_reuse - BOOLEAN
 	It should not be changed without advice/request of technical
 	experts.
 
+tcp_tw_interval - INTEGER
+	Specify the timeout, in seconds, of TIME-WAIT sockets.
+	It should not be changed without advice/request of technical
+	experts.
+	Default: 60
+
 tcp_window_scaling - BOOLEAN
 	Enable window scaling as defined in RFC1323.
 
include/net/tcp.h +5 -3
index 6feeccd..72f92a1 100644
@@ -114,9 +114,10 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
 				 * initial RTO.
 				 */
 
-#define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT
-				  * state, about 60 seconds	*/
-#define TCP_FIN_TIMEOUT	TCP_TIMEWAIT_LEN
+#define TCP_TIMEWAIT_LEN (sysctl_tcp_tw_interval * HZ)
+				 /* how long to wait to destroy TIME-WAIT
+				  * state, default 60 seconds	*/
+#define TCP_FIN_TIMEOUT	(60*HZ)
                                  /* BSD style FIN_WAIT2 deadlock breaker.
 				  * It used to be 3min, new value is 60sec,
 				  * to combine FIN-WAIT-2 timeout with
@@ -292,6 +293,7 @@ extern int sysctl_tcp_thin_dupack;
 extern int sysctl_tcp_early_retrans;
 extern int sysctl_tcp_limit_output_bytes;
 extern int sysctl_tcp_challenge_ack_limit;
+extern int sysctl_tcp_tw_interval;
 
 extern atomic_long_t tcp_memory_allocated;
 extern struct percpu_counter tcp_sockets_allocated;
net/ipv4/sysctl_net_ipv4.c +30 -0
index 9205e49..f99cacf 100644
@@ -27,6 +27,7 @@
 #include <net/tcp_memcontrol.h>
 
 static int zero;
+static int one = 1;
 static int two = 2;
 static int tcp_retr1_max = 255;
 static int ip_local_port_range_min[] = { 1, 1 };
@@ -271,6 +272,28 @@ bad_key:
 	return ret;
 }
 
+static int proc_tcp_tw_interval(ctl_table *ctl, int write,
+				void __user *buffer, size_t *lenp,
+				loff_t *ppos)
+{
+	int ret;
+	ctl_table tmp = {
+		.data = &sysctl_tcp_tw_interval,
+		.maxlen = sizeof(int),
+		.mode = ctl->mode,
+		.extra1 = &one,
+	};
+
+	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+	if (ret)
+		return ret;
+	if (write)
+		tcp_death_row.period = (HZ / INET_TWDR_TWKILL_SLOTS)
+				       * sysctl_tcp_tw_interval;
+
+	return 0;
+}
+
 static struct ctl_table ipv4_table[] = {
 	{
 		.procname	= "tcp_timestamps",
@@ -794,6 +817,13 @@ static struct ctl_table ipv4_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= &zero
 	},
+	{
+		.procname	= "tcp_tw_interval",
+		.data		= &sysctl_tcp_tw_interval,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_tcp_tw_interval,
+	},
 	{ }
 };
 
net/ipv4/tcp_ipv4.c +1 -0
index 93406c5..64af0b6 100644
@@ -86,6 +86,7 @@
 #include <linux/scatterlist.h>
 
 int sysctl_tcp_tw_reuse __read_mostly;
+int sysctl_tcp_tw_interval __read_mostly = 60;
 int sysctl_tcp_low_latency __read_mostly;
 EXPORT_SYMBOL(sysctl_tcp_low_latency);
 
net/ipv4/tcp_minisocks.c +1 -1
index 27536ba..e16f524 100644
@@ -34,7 +34,7 @@ int sysctl_tcp_abort_on_overflow __read_mostly;
 
 struct inet_timewait_death_row tcp_death_row = {
 	.sysctl_max_tw_buckets = NR_FILE * 2,
-	.period		= TCP_TIMEWAIT_LEN / INET_TWDR_TWKILL_SLOTS,
+	.period		= (60 * HZ) / INET_TWDR_TWKILL_SLOTS,
 	.death_lock	= __SPIN_LOCK_UNLOCKED(tcp_death_row.death_lock),
 	.hashinfo	= &tcp_hashinfo,
 	.tw_timer	= TIMER_INITIALIZER(inet_twdr_hangman, 0,
#1 lore raw
Quoted 13 lines · Cong Wang

Some customer requests this feature, as they stated:

"This parameter is necessary, especially for software that continually creates many ephemeral processes which open sockets, to avoid socket exhaustion. In many cases, the risk of the exhaustion can be reduced by tuning reuse interval to allow sockets to be reusable earlier.

In commercial Unix systems, this kind of parameters, such as tcp_timewait in AIX and tcp_time_wait_interval in HP-UX, have already been available. Their implementations allow users to tune how long they keep TCP connection as TIME-WAIT state on the millisecond time scale."

Quoted 6 lines

We indeed have "tcp_tw_reuse" and "tcp_tw_recycle", but these tunings are not equivalent in that they cannot be tuned directly on the time scale nor in a safe way, as some combinations of tunings could still cause some problem in NAT. And, I think second scale is enough, we don't have to make it in millisecond time scale.

I think I have a little difficultly seeing how this does anything other than pay lip service to actually having sockets spend time in TIME_WAIT state. That is to say, while I see users using this to just make the pain stop. If we wait less time than it takes to be sure that a connection isn't being reused (either by waiting two segment lifetimes, or by checking timestamps), then you might as well not wait at all. I see how its tempting to be able to say "Just don't wait as long", but it seems that theres no difference between waiting half as long as the RFC mandates, and waiting no time at all. Neither is a good idea.

Given the problem you're trying to solve here, I'll ask the standard question in
response: How does using SO_REUSEADDR not solve the problem? Alternatively, in a pinch, why not reduce the tcp_max_tw_buckets sufficiently to start forcing TIME_WAIT sockets back into CLOSED state?

The code looks fine, but the idea really doesn't seem like a good plan to me. I'm sure HPUX/Solaris/AIX/etc have done this in response to customer demand, but that doesn't make it the right solution.

Regards
Neil

Quoted 136 lines

See also: https://lkml.org/lkml/2008/11/15/80

Any comments?

Cc "David S. Miller" <[email protected]>
Cc Alexey Kuznetsov <[email protected]>
Cc Patrick McHardy <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Neil Horman <[email protected]>

---

Documentation/networking/ip-sysctl.txt +6 -0
index c7fc107..4b24398 100644
@@ -520,6 +520,12 @@ tcp_tw_reuse - BOOLEAN
 	It should not be changed without advice/request of technical
 	experts.
 
+tcp_tw_interval - INTEGER
+	Specify the timeout, in seconds, of TIME-WAIT sockets.
+	It should not be changed without advice/request of technical
+	experts.
+	Default: 60
+
 tcp_window_scaling - BOOLEAN
 	Enable window scaling as defined in RFC1323.
 
include/net/tcp.h +5 -3
index 6feeccd..72f92a1 100644
@@ -114,9 +114,10 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
 				 * initial RTO.
 				 */
 
-#define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT
-				  * state, about 60 seconds	*/
-#define TCP_FIN_TIMEOUT	TCP_TIMEWAIT_LEN
+#define TCP_TIMEWAIT_LEN (sysctl_tcp_tw_interval * HZ)
+				 /* how long to wait to destroy TIME-WAIT
+				  * state, default 60 seconds	*/
+#define TCP_FIN_TIMEOUT	(60*HZ)
                                  /* BSD style FIN_WAIT2 deadlock breaker.
 				  * It used to be 3min, new value is 60sec,
 				  * to combine FIN-WAIT-2 timeout with
@@ -292,6 +293,7 @@ extern int sysctl_tcp_thin_dupack;
 extern int sysctl_tcp_early_retrans;
 extern int sysctl_tcp_limit_output_bytes;
 extern int sysctl_tcp_challenge_ack_limit;
+extern int sysctl_tcp_tw_interval;
 
 extern atomic_long_t tcp_memory_allocated;
 extern struct percpu_counter tcp_sockets_allocated;
net/ipv4/sysctl_net_ipv4.c +30 -0
index 9205e49..f99cacf 100644
@@ -27,6 +27,7 @@
 #include <net/tcp_memcontrol.h>
 
 static int zero;
+static int one = 1;
 static int two = 2;
 static int tcp_retr1_max = 255;
 static int ip_local_port_range_min[] = { 1, 1 };
@@ -271,6 +272,28 @@ bad_key:
 	return ret;
 }
 
+static int proc_tcp_tw_interval(ctl_table *ctl, int write,
+				void __user *buffer, size_t *lenp,
+				loff_t *ppos)
+{
+	int ret;
+	ctl_table tmp = {
+		.data = &sysctl_tcp_tw_interval,
+		.maxlen = sizeof(int),
+		.mode = ctl->mode,
+		.extra1 = &one,
+	};
+
+	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
+	if (ret)
+		return ret;
+	if (write)
+		tcp_death_row.period = (HZ / INET_TWDR_TWKILL_SLOTS)
+				       * sysctl_tcp_tw_interval;
+
+	return 0;
+}
+
 static struct ctl_table ipv4_table[] = {
 	{
 		.procname	= "tcp_timestamps",
@@ -794,6 +817,13 @@ static struct ctl_table ipv4_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= &zero
 	},
+	{
+		.procname	= "tcp_tw_interval",
+		.data		= &sysctl_tcp_tw_interval,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_tcp_tw_interval,
+	},
 	{ }
 };
 
net/ipv4/tcp_ipv4.c +1 -0
index 93406c5..64af0b6 100644
@@ -86,6 +86,7 @@
 #include <linux/scatterlist.h>
 
 int sysctl_tcp_tw_reuse __read_mostly;
+int sysctl_tcp_tw_interval __read_mostly = 60;
 int sysctl_tcp_low_latency __read_mostly;
 EXPORT_SYMBOL(sysctl_tcp_low_latency);
 
net/ipv4/tcp_minisocks.c +1 -1
index 27536ba..e16f524 100644
@@ -34,7 +34,7 @@ int sysctl_tcp_abort_on_overflow __read_mostly;
 
 struct inet_timewait_death_row tcp_death_row = {
 	.sysctl_max_tw_buckets = NR_FILE * 2,
-	.period		= TCP_TIMEWAIT_LEN / INET_TWDR_TWKILL_SLOTS,
+	.period		= (60 * HZ) / INET_TWDR_TWKILL_SLOTS,
 	.death_lock	= __SPIN_LOCK_UNLOCKED(tcp_death_row.death_lock),
 	.hashinfo	= &tcp_hashinfo,
 	.tw_timer	= TIMER_INITIALIZER(inet_twdr_hangman, 0,
#2 lore raw
Quoted 3 lines · Neil Horman

The code looks fine, but the idea really doesn't seem like a good plan to me. I'm sure HPUX/Solaris/AIX/etc have done this in response to customer demand, but that doesn't make it the right solution.

In the case of HP-UX at least, while the rope is indeed there, the advice is to not wrap it around one's neck unless one *really* has a handle on the environment. Instead things suggested, in no particular order:

*) The aforementioned SO_REUSEADDR to address the "I can't restart the server quickly enough." issue

*) Tuning the size of the anonymous/ephemeral port range.

*) Making explicit bind() calls using the entire non-privileged port range

*) Making the connections longer-lived. Especially if the comms are between a fixed set of IP addresses.

rick jones

maintainer
#12 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Thu, 27 Sep 2012 16:41:01 +0800

Quoted 5 lines

In commercial Unix systems, this kind of parameters, such as tcp_timewait in AIX and tcp_time_wait_interval in HP-UX, have already been available. Their implementations allow users to tune how long they keep TCP connection as TIME-WAIT state on the millisecond time scale."

This statement only makes me happy that these systems are not as widely deployed as Linux is.

Furthermore, the mere existence of a facility in another system is never an argument for why we should have it too. Often it's instead a huge reason for us not to add it.

Without appropriate confirmation that an early time-wait reuse is valid, decreasing this interval can only be dangerous.

author
#3 lore raw
In reply to Neil Horman
Quoted 20 lines · Neil Horman
Quoted 13 lines · Cong Wang

Some customer requests this feature, as they stated:

"This parameter is necessary, especially for software that continually creates many ephemeral processes which open sockets, to avoid socket exhaustion. In many cases, the risk of the exhaustion can be reduced by tuning reuse interval to allow sockets to be reusable earlier.

In commercial Unix systems, this kind of parameters, such as tcp_timewait in AIX and tcp_time_wait_interval in HP-UX, have already been available. Their implementations allow users to tune how long they keep TCP connection as TIME-WAIT state on the millisecond time scale."

Quoted 6 lines

We indeed have "tcp_tw_reuse" and "tcp_tw_recycle", but these tunings are not equivalent in that they cannot be tuned directly on the time scale nor in a safe way, as some combinations of tunings could still cause some problem in NAT. And, I think second scale is enough, we don't have to make it in millisecond time scale.

Quoted 8 lines

I think I have a little difficultly seeing how this does anything other than pay lip service to actually having sockets spend time in TIME_WAIT state. That is to say, while I see users using this to just make the pain stop. If we wait less time than it takes to be sure that a connection isn't being reused (either by waiting two segment lifetimes, or by checking timestamps), then you might as well not wait at all. I see how its tempting to be able to say "Just don't wait as long", but it seems that theres no difference between waiting half as long as the RFC mandates, and waiting no time at all. Neither is a good idea.

I don't think reducing TIME_WAIT is a good idea either, but there must be some reason behind as several UNIX provides a microsecond-scale tuning interface, or maybe in non-recycle mode, their RTO is much less than 2*MSL?

Quoted 10 lines

Given the problem you're trying to solve here, I'll ask the standard question in
response: How does using SO_REUSEADDR not solve the problem? Alternatively, in a pinch, why not reduce the tcp_max_tw_buckets sufficiently to start forcing TIME_WAIT sockets back into CLOSED state?

The code looks fine, but the idea really doesn't seem like a good plan to me. I'm sure HPUX/Solaris/AIX/etc have done this in response to customer demand, but that doesn't make it the right solution.

*I think* the customer doesn't want to modify their applications, so that is why they don't use SO_REUSERADDR.

I didn't know tcp_max_tw_buckets can do the trick, nor the customer, so this is a side effect of tcp_max_tw_buckets? Is it documented?

Thanks.

author
#13 lore raw
In reply to David Miller
Quoted 3 lines · David Miller

Without appropriate confirmation that an early time-wait reuse is valid, decreasing this interval can only be dangerous.

Yeah, would a proper documentation cure this? Something like we did for other tuning:

"It should not be changed without advice/request of technical experts."

maintainer
#4 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Fri, 28 Sep 2012 14:33:07 +0800

Quoted 4 lines

I don't think reducing TIME_WAIT is a good idea either, but there must be some reason behind as several UNIX provides a microsecond-scale tuning interface, or maybe in non-recycle mode, their RTO is much less than 2*MSL?

Yes, there is a reason. It's there for retaining multi-million-dollar customers.

There is no other reasons these other systems provide these facilities, they are simply there in an attempt to retain a dwindling customer base.

Any other belief is extremely naive.

maintainer
#14 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Fri, 28 Sep 2012 14:39:59 +0800

Quoted 9 lines · David Miller
Quoted 3 lines

Without appropriate confirmation that an early time-wait reuse is valid, decreasing this interval can only be dangerous.

Yeah, would a proper documentation cure this? Something like we did for other tuning:

"It should not be changed without advice/request of technical experts."

No, we're not adding this facility.

#6 lore raw
In reply to Cong Wang
Quoted 30 lines · Cong Wang
Quoted 20 lines · Neil Horman
Quoted 13 lines · Cong Wang

Some customer requests this feature, as they stated:

"This parameter is necessary, especially for software that continually creates many ephemeral processes which open sockets, to avoid socket exhaustion. In many cases, the risk of the exhaustion can be reduced by tuning reuse interval to allow sockets to be reusable earlier.

In commercial Unix systems, this kind of parameters, such as tcp_timewait in AIX and tcp_time_wait_interval in HP-UX, have already been available. Their implementations allow users to tune how long they keep TCP connection as TIME-WAIT state on the millisecond time scale."

Quoted 6 lines

We indeed have "tcp_tw_reuse" and "tcp_tw_recycle", but these tunings are not equivalent in that they cannot be tuned directly on the time scale nor in a safe way, as some combinations of tunings could still cause some problem in NAT. And, I think second scale is enough, we don't have to make it in millisecond time scale.

Quoted 8 lines

I think I have a little difficultly seeing how this does anything other than pay lip service to actually having sockets spend time in TIME_WAIT state. That is to say, while I see users using this to just make the pain stop. If we wait less time than it takes to be sure that a connection isn't being reused (either by waiting two segment lifetimes, or by checking timestamps), then you might as well not wait at all. I see how its tempting to be able to say "Just don't wait as long", but it seems that theres no difference between waiting half as long as the RFC mandates, and waiting no time at all. Neither is a good idea.

Quoted 5 lines

I don't think reducing TIME_WAIT is a good idea either, but there must be some reason behind as several UNIX provides a microsecond-scale tuning interface, or maybe in non-recycle mode, their RTO is much less than 2*MSL?

My guess? Cash was the reason. I certainly wasn't there for any of those developments, but a setting like this just smells to me like some customer waved some cash under IBM's/HP's/Sun's nose and said, "We'd like to get our tcp sockets back to CLOSED state faster, what can you do for us?"

Quoted 6 lines
Quoted 6 lines

Given the problem you're trying to solve here, I'll ask the standard question in
response: How does using SO_REUSEADDR not solve the problem? Alternatively, in a pinch, why not reduce the tcp_max_tw_buckets sufficiently to start forcing TIME_WAIT sockets back into CLOSED state?

Quoted 8 lines
Quoted 4 lines

The code looks fine, but the idea really doesn't seem like a good plan to me. I'm sure HPUX/Solaris/AIX/etc have done this in response to customer demand, but that doesn't make it the right solution.

*I think* the customer doesn't want to modify their applications, so that is why they don't use SO_REUSERADDR.

Well, ok, thats a legitimate distro problem. What its not is an upstream problem. Fixing the appilcation is the right thing to do, wether or not they want to.

Quoted 2 lines

I didn't know tcp_max_tw_buckets can do the trick, nor the customer, so this is a side effect of tcp_max_tw_buckets? Is it documented?

man 7 tcp:
tcp_max_tw_buckets (integer; default: see below; since Linux 2.4)
The maximum number of sockets in TIME_WAIT state allowed in the system. This limit exists only to prevent simple
denial-of-service attacks. The default value of NR_FILE*2 is
adjusted depending on the memory in the system. If this number is exceeded, the socket is closed and a warning is printed.

Neil

#5 lore raw
In reply to David Miller
Quoted 7 lines · David Miller

From: Cong Wang <[email protected]>
Date: Fri, 28 Sep 2012 14:33:07 +0800

Quoted 4 lines

I don't think reducing TIME_WAIT is a good idea either, but there must be some reason behind as several UNIX provides a microsecond-scale tuning interface, or maybe in non-recycle mode, their RTO is much less than 2*MSL?

Microsecond? HP-UX uses milliseconds for the units of the tunable, though that does not necessarily mean it will actually be implemented to millisecond accuracy

Quoted 8 lines

Yes, there is a reason. It's there for retaining multi-million-dollar customers.

There is no other reasons these other systems provide these facilities, they are simply there in an attempt to retain a dwindling customer base.

Any other belief is extremely naive.

HP-UX's TIME_WAIT interval tunability goes back to HP-UX 11.0, which first shipped in 1997. It got it by virtue of using a "Mentat-based" stack which had that functionality. I may not have my history completely correct, but Solaris 2 also got their networking bits from Mentat, and I believe shipped before HP-UX 11.

To my recollection, neither were faced with a dwindling customer base at the time.

rick jones

author
#7 lore raw
In reply to Neil Horman
Quoted 36 lines · Neil Horman
Quoted 30 lines · Cong Wang
Quoted 20 lines · Neil Horman
Quoted 13 lines · Cong Wang

Some customer requests this feature, as they stated:

"This parameter is necessary, especially for software that continually creates many ephemeral processes which open sockets, to avoid socket exhaustion. In many cases, the risk of the exhaustion can be reduced by tuning reuse interval to allow sockets to be reusable earlier.

In commercial Unix systems, this kind of parameters, such as tcp_timewait in AIX and tcp_time_wait_interval in HP-UX, have already been available. Their implementations allow users to tune how long they keep TCP connection as TIME-WAIT state on the millisecond time scale."

Quoted 6 lines

We indeed have "tcp_tw_reuse" and "tcp_tw_recycle", but these tunings are not equivalent in that they cannot be tuned directly on the time scale nor in a safe way, as some combinations of tunings could still cause some problem in NAT. And, I think second scale is enough, we don't have to make it in millisecond time scale.

Quoted 8 lines

I think I have a little difficultly seeing how this does anything other than pay lip service to actually having sockets spend time in TIME_WAIT state. That is to say, while I see users using this to just make the pain stop. If we wait less time than it takes to be sure that a connection isn't being reused (either by waiting two segment lifetimes, or by checking timestamps), then you might as well not wait at all. I see how its tempting to be able to say "Just don't wait as long", but it seems that theres no difference between waiting half as long as the RFC mandates, and waiting no time at all. Neither is a good idea.

Quoted 5 lines

I don't think reducing TIME_WAIT is a good idea either, but there must be some reason behind as several UNIX provides a microsecond-scale tuning interface, or maybe in non-recycle mode, their RTO is much less than 2*MSL?

Quoted 4 lines

My guess? Cash was the reason. I certainly wasn't there for any of those developments, but a setting like this just smells to me like some customer waved some cash under IBM's/HP's/Sun's nose and said, "We'd like to get our tcp sockets back to CLOSED state faster, what can you do for us?"

Yeah, maybe. But it still doesn't make sense even if they are sure their packets are impossible to linger in their high-speed LAN for 2*MSL?

Quoted 21 lines
Quoted 7 lines
Quoted 7 lines

Given the problem you're trying to solve here, I'll ask the standard question in
response: How does using SO_REUSEADDR not solve the problem? Alternatively, in a pinch, why not reduce the tcp_max_tw_buckets sufficiently to start forcing TIME_WAIT sockets back into CLOSED state?

Quoted 8 lines
Quoted 4 lines

The code looks fine, but the idea really doesn't seem like a good plan to me. I'm sure HPUX/Solaris/AIX/etc have done this in response to customer demand, but that doesn't make it the right solution.

*I think* the customer doesn't want to modify their applications, so that is why they don't use SO_REUSERADDR.

Well, ok, thats a legitimate distro problem. What its not is an upstream problem. Fixing the appilcation is the right thing to do, wether or not they want to.

Quoted 2 lines

I didn't know tcp_max_tw_buckets can do the trick, nor the customer, so this is a side effect of tcp_max_tw_buckets? Is it documented?

Quoted 8 lines

man 7 tcp:
tcp_max_tw_buckets (integer; default: see below; since Linux 2.4)
The maximum number of sockets in TIME_WAIT state allowed in the system. This limit exists only to prevent simple
denial-of-service attacks. The default value of NR_FILE*2 is
adjusted depending on the memory in the system. If this number is exceeded, the socket is closed and a warning is printed.

Hey, "a warning is printed" seems not very friendly. ;)

Thanks!

#8 lore raw
Quoted 37 lines · Cong Wang
Quoted 36 lines · Neil Horman
Quoted 35 lines · Cong Wang
Quoted 20 lines · Neil Horman
Quoted 13 lines · Cong Wang

Some customer requests this feature, as they stated:

"This parameter is necessary, especially for software that continually creates many ephemeral processes which open sockets, to avoid socket exhaustion. In many cases, the risk of the exhaustion can be reduced by tuning reuse interval to allow sockets to be reusable earlier.

In commercial Unix systems, this kind of parameters, such as tcp_timewait in AIX and tcp_time_wait_interval in HP-UX, have already been available. Their implementations allow users to tune how long they keep TCP connection as TIME-WAIT state on the millisecond time scale."

Quoted 6 lines

We indeed have "tcp_tw_reuse" and "tcp_tw_recycle", but these tunings are not equivalent in that they cannot be tuned directly on the time scale nor in a safe way, as some combinations of tunings could still cause some problem in NAT. And, I think second scale is enough, we don't have to make it in millisecond time scale.

Quoted 8 lines

I think I have a little difficultly seeing how this does anything other than pay lip service to actually having sockets spend time in TIME_WAIT state. That is to say, while I see users using this to just make the pain stop. If we wait less time than it takes to be sure that a connection isn't being reused (either by waiting two segment lifetimes, or by checking timestamps), then you might as well not wait at all. I see how its tempting to be able to say "Just don't wait as long", but it seems that theres no difference between waiting half as long as the RFC mandates, and waiting no time at all. Neither is a good idea.

I don't think reducing TIME_WAIT is a good idea either, but there must be some reason behind as several UNIX provides a microsecond-scale tuning interface, or maybe in non-recycle mode, their RTO is much less than 2*MSL?

Quoted 8 lines
Quoted 4 lines

My guess? Cash was the reason. I certainly wasn't there for any of those developments, but a setting like this just smells to me like some customer waved some cash under IBM's/HP's/Sun's nose and said, "We'd like to get our tcp sockets back to CLOSED state faster, what can you do for us?"

Yeah, maybe. But it still doesn't make sense even if they are sure their packets are impossible to linger in their high-speed LAN for 2*MSL?

No it doesn't make sense, but the universal rule is that the business people will focus more on revenue recognition than on sound design pracice.

Quoted 30 lines
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines

Given the problem you're trying to solve here, I'll ask the standard question in
response: How does using SO_REUSEADDR not solve the problem? Alternatively, in a pinch, why not reduce the tcp_max_tw_buckets sufficiently to start forcing TIME_WAIT sockets back into CLOSED state?

Quoted 8 lines
Quoted 4 lines

The code looks fine, but the idea really doesn't seem like a good plan to me. I'm sure HPUX/Solaris/AIX/etc have done this in response to customer demand, but that doesn't make it the right solution.

*I think* the customer doesn't want to modify their applications, so that is why they don't use SO_REUSERADDR.

Well, ok, thats a legitimate distro problem. What its not is an upstream problem. Fixing the appilcation is the right thing to do, wether or not they want to.

Quoted 2 lines

I didn't know tcp_max_tw_buckets can do the trick, nor the customer, so this is a side effect of tcp_max_tw_buckets? Is it documented?

Quoted 8 lines

man 7 tcp:
tcp_max_tw_buckets (integer; default: see below; since Linux 2.4)
The maximum number of sockets in TIME_WAIT state allowed in the system. This limit exists only to prevent simple
denial-of-service attacks. The default value of NR_FILE*2 is
adjusted depending on the memory in the system. If this number is exceeded, the socket is closed and a warning is printed.

Quoted 2 lines

Hey, "a warning is printed" seems not very friendly. ;)

No, its not very friendly, but the people using this are violating the RFC, which isn't very friendly. :)

Quoted 3 lines

Thanks!

author
#9 lore raw
Quoted 2 lines · Neil Horman

No, its not very friendly, but the people using this are violating the RFC, which isn't very friendly. :)

Could you be more specific? In RFC 793, AFAIK, it is allowed to be changed:

http://tools.ietf.org/html/rfc793

" To be sure that a TCP does not create a segment that carries a
sequence number which may be duplicated by an old segment remaining in the network, the TCP must keep quiet for a maximum segment lifetime (MSL) before assigning any sequence numbers upon starting up or recovering from a crash in which memory of sequence numbers in use was lost. For this specification the MSL is taken to be 2 minutes. This is an engineering choice, and may be changed if experience indicates it is desirable to do so."

or I must still be missing something here... :)

#10 lore raw
Quoted 9 lines · Cong Wang
Quoted 2 lines · Neil Horman

No, its not very friendly, but the people using this are violating the RFC, which isn't very friendly. :)

Could you be more specific? In RFC 793, AFAIK, it is allowed to be changed:

http://tools.ietf.org/html/rfc793

Quoted 9 lines

" To be sure that a TCP does not create a segment that carries a
sequence number which may be duplicated by an old segment remaining in the network, the TCP must keep quiet for a maximum segment lifetime (MSL) before assigning any sequence numbers upon starting up or recovering from a crash in which memory of sequence numbers in use was lost. For this specification the MSL is taken to be 2 minutes. This is an engineering choice, and may be changed if experience indicates it is desirable to do so."

Its the length of time that represents an MSL that was the choice, not the fact that reusing a TCP before the expiration of the MSL is a bad idea.

Quoted 2 lines

or I must still be missing something here... :)

Next paragraph down:
This specification provides that hosts which "crash" without
retaining any knowledge of the last sequence numbers transmitted on each active (i.e., not closed) connection shall delay emitting any TCP segments for at least the agreed Maximum Segment Lifetime (MSL) in the internet system of which the host is a part. In the paragraphs below, an explanation for this specification is given. TCP implementors may violate the "quiet time" restriction, but only at the risk of causing some old data to be accepted as new or new data rejected as old duplicated by some receivers in the internet system. .... etc.

author
#11 lore raw
Quoted 24 lines · Neil Horman
Quoted 9 lines · Cong Wang
Quoted 2 lines · Neil Horman

No, its not very friendly, but the people using this are violating the RFC, which isn't very friendly. :)

Could you be more specific? In RFC 793, AFAIK, it is allowed to be changed:

http://tools.ietf.org/html/rfc793

Quoted 9 lines

" To be sure that a TCP does not create a segment that carries a
sequence number which may be duplicated by an old segment remaining in the network, the TCP must keep quiet for a maximum segment lifetime (MSL) before assigning any sequence numbers upon starting up or recovering from a crash in which memory of sequence numbers in use was lost. For this specification the MSL is taken to be 2 minutes. This is an engineering choice, and may be changed if experience indicates it is desirable to do so."

Its the length of time that represents an MSL that was the choice, not the fact that reusing a TCP before the expiration of the MSL is a bad idea.

Quoted 2 lines

or I must still be missing something here... :)

Quoted 13 lines

Next paragraph down:
This specification provides that hosts which "crash" without
retaining any knowledge of the last sequence numbers transmitted on each active (i.e., not closed) connection shall delay emitting any TCP segments for at least the agreed Maximum Segment Lifetime (MSL) in the internet system of which the host is a part. In the paragraphs below, an explanation for this specification is given. TCP implementors may violate the "quiet time" restriction, but only at the risk of causing some old data to be accepted as new or new data rejected as old duplicated by some receivers in the internet system. .... etc.

Ah, ok. Thanks for the detailed answer!