linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: fix the calculation of sysctl_max_tw_buckets in tcp_sk_init()
@ 2018-08-06 11:47 Yafang Shao
  2018-08-06 20:41 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Yafang Shao @ 2018-08-06 11:47 UTC (permalink / raw)
  To: edumazet, davem, yanhaishuang; +Cc: netdev, linux-kernel, Yafang Shao

tcp_hashinfo.ehash_mask is always an odd number, which is set in function
alloc_large_system_hash(). See bellow,
	if (_hash_mask)
		*_hash_mask = (1 << log2qty) - 1; <<< always odd number

Hence the local variable 'cnt' is a even number, as a result of that it is
no difference to do the incrementation here.

Maybe the compiler could also optimize it, but this code is a little ugly.

Fix: fee83d09 ("ipv4: Namespaceify tcp_max_syn_backlog knob")
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 net/ipv4/tcp_ipv4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 9e041fa..a9b7c4b 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2543,7 +2543,7 @@ static int __net_init tcp_sk_init(struct net *net)
 	net->ipv4.sysctl_tcp_tw_reuse = 2;
 
 	cnt = tcp_hashinfo.ehash_mask + 1;
-	net->ipv4.tcp_death_row.sysctl_max_tw_buckets = (cnt + 1) / 2;
+	net->ipv4.tcp_death_row.sysctl_max_tw_buckets = cnt / 2;
 	net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo;
 
 	net->ipv4.sysctl_max_syn_backlog = max(128, cnt / 256);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] tcp: fix the calculation of sysctl_max_tw_buckets in tcp_sk_init()
  2018-08-06 11:47 [PATCH net-next] tcp: fix the calculation of sysctl_max_tw_buckets in tcp_sk_init() Yafang Shao
@ 2018-08-06 20:41 ` David Miller
  2018-08-07  1:40   ` Yafang Shao
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2018-08-06 20:41 UTC (permalink / raw)
  To: laoar.shao; +Cc: edumazet, yanhaishuang, netdev, linux-kernel

From: Yafang Shao <laoar.shao@gmail.com>
Date: Mon,  6 Aug 2018 19:47:00 +0800

> tcp_hashinfo.ehash_mask is always an odd number, which is set in function
> alloc_large_system_hash(). See bellow,
> 	if (_hash_mask)
> 		*_hash_mask = (1 << log2qty) - 1; <<< always odd number
> 
> Hence the local variable 'cnt' is a even number, as a result of that it is
> no difference to do the incrementation here.
> 
> Maybe the compiler could also optimize it, but this code is a little ugly.
> 
> Fix: fee83d09 ("ipv4: Namespaceify tcp_max_syn_backlog knob")

The correct tag is "Fixes: "

> @@ -2543,7 +2543,7 @@ static int __net_init tcp_sk_init(struct net *net)
>  	net->ipv4.sysctl_tcp_tw_reuse = 2;
>  
>  	cnt = tcp_hashinfo.ehash_mask + 1;
> -	net->ipv4.tcp_death_row.sysctl_max_tw_buckets = (cnt + 1) / 2;
> +	net->ipv4.tcp_death_row.sysctl_max_tw_buckets = cnt / 2;
>  	net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo;

This is completely harmless, and does no harm.

You aren't "fixing" anything.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] tcp: fix the calculation of sysctl_max_tw_buckets in tcp_sk_init()
  2018-08-06 20:41 ` David Miller
@ 2018-08-07  1:40   ` Yafang Shao
  0 siblings, 0 replies; 3+ messages in thread
From: Yafang Shao @ 2018-08-07  1:40 UTC (permalink / raw)
  To: David Miller; +Cc: Eric Dumazet, yanhaishuang, netdev, LKML

On Tue, Aug 7, 2018 at 4:41 AM, David Miller <davem@davemloft.net> wrote:
> From: Yafang Shao <laoar.shao@gmail.com>
> Date: Mon,  6 Aug 2018 19:47:00 +0800
>
>> tcp_hashinfo.ehash_mask is always an odd number, which is set in function
>> alloc_large_system_hash(). See bellow,
>>       if (_hash_mask)
>>               *_hash_mask = (1 << log2qty) - 1; <<< always odd number
>>
>> Hence the local variable 'cnt' is a even number, as a result of that it is
>> no difference to do the incrementation here.
>>
>> Maybe the compiler could also optimize it, but this code is a little ugly.
>>
>> Fix: fee83d09 ("ipv4: Namespaceify tcp_max_syn_backlog knob")
>
> The correct tag is "Fixes: "

OK

>
>> @@ -2543,7 +2543,7 @@ static int __net_init tcp_sk_init(struct net *net)
>>       net->ipv4.sysctl_tcp_tw_reuse = 2;
>>
>>       cnt = tcp_hashinfo.ehash_mask + 1;
>> -     net->ipv4.tcp_death_row.sysctl_max_tw_buckets = (cnt + 1) / 2;
>> +     net->ipv4.tcp_death_row.sysctl_max_tw_buckets = cnt / 2;
>>       net->ipv4.tcp_death_row.hashinfo = &tcp_hashinfo;
>
> This is completely harmless, and does no harm.
>

It is harmless, meanwhile, it is useless and a little ugly.

By the way,  why do we init sysctl_max_tw_buckets to
(tcp_hashinfo.ehash_mask + 1) / 2 or (tcp_hashinfo.ehash_mask + 2) / 2
?
Per my pespective, this default value is a little huge, sometimes we
have to set this value to a lower value with sysctl, otherwise it may
easily cause tcp port exhaustion issue.
So why not just init it to a lower value ?

> You aren't "fixing" anything.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-07  1:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-06 11:47 [PATCH net-next] tcp: fix the calculation of sysctl_max_tw_buckets in tcp_sk_init() Yafang Shao
2018-08-06 20:41 ` David Miller
2018-08-07  1:40   ` Yafang Shao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).