All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge()
@ 2024-03-27 19:12 Eric Dumazet
  2024-03-27 19:29 ` Kuniyuki Iwashima
  2024-03-29 15:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2024-03-27 19:12 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: netdev, eric.dumazet, Eric Dumazet

TCP ehash table is often sparsely populated.

inet_twsk_purge() spends too much time calling cond_resched().

This patch can reduce time spent in inet_twsk_purge() by 20x.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/inet_timewait_sock.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
index e8de45d34d56a507a4bdcceaccbd5707692b6c0a..b0cc07d9a568c5dc52bd29729862bcb03e5d595d 100644
--- a/net/ipv4/inet_timewait_sock.c
+++ b/net/ipv4/inet_timewait_sock.c
@@ -266,12 +266,17 @@ EXPORT_SYMBOL_GPL(__inet_twsk_schedule);
 /* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */
 void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
 {
+	struct inet_ehash_bucket *head = &hashinfo->ehash[0];
+	unsigned int ehash_mask = hashinfo->ehash_mask;
 	struct hlist_nulls_node *node;
 	unsigned int slot;
 	struct sock *sk;
 
-	for (slot = 0; slot <= hashinfo->ehash_mask; slot++) {
-		struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
+	for (slot = 0; slot <= ehash_mask; slot++, head++) {
+
+		if (hlist_nulls_empty(&head->chain))
+			continue;
+
 restart_rcu:
 		cond_resched();
 		rcu_read_lock();
-- 
2.44.0.396.g6e790dbe36-goog


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

* Re: [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge()
  2024-03-27 19:12 [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge() Eric Dumazet
@ 2024-03-27 19:29 ` Kuniyuki Iwashima
  2024-03-29 15:06   ` Jakub Kicinski
  2024-03-29 15:20 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Kuniyuki Iwashima @ 2024-03-27 19:29 UTC (permalink / raw)
  To: edumazet; +Cc: davem, eric.dumazet, kuba, netdev, pabeni, Kuniyuki Iwashima

From: Eric Dumazet <edumazet@google.com>
Date: Wed, 27 Mar 2024 19:12:06 +0000
> TCP ehash table is often sparsely populated.
> 
> inet_twsk_purge() spends too much time calling cond_resched().
> 
> This patch can reduce time spent in inet_twsk_purge() by 20x.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Sounds good!

Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>

1 nit below.


> ---
>  net/ipv4/inet_timewait_sock.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
> index e8de45d34d56a507a4bdcceaccbd5707692b6c0a..b0cc07d9a568c5dc52bd29729862bcb03e5d595d 100644
> --- a/net/ipv4/inet_timewait_sock.c
> +++ b/net/ipv4/inet_timewait_sock.c
> @@ -266,12 +266,17 @@ EXPORT_SYMBOL_GPL(__inet_twsk_schedule);
>  /* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */
>  void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
>  {
> +	struct inet_ehash_bucket *head = &hashinfo->ehash[0];
> +	unsigned int ehash_mask = hashinfo->ehash_mask;
>  	struct hlist_nulls_node *node;
>  	unsigned int slot;
>  	struct sock *sk;
>  
> -	for (slot = 0; slot <= hashinfo->ehash_mask; slot++) {
> -		struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
> +	for (slot = 0; slot <= ehash_mask; slot++, head++) {
> +

unnecessary blank link here.

Thanks!

> +		if (hlist_nulls_empty(&head->chain))
> +			continue;
> +
>  restart_rcu:
>  		cond_resched();
>  		rcu_read_lock();
> -- 
> 2.44.0.396.g6e790dbe36-goog
> 

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

* Re: [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge()
  2024-03-27 19:29 ` Kuniyuki Iwashima
@ 2024-03-29 15:06   ` Jakub Kicinski
  2024-03-29 15:24     ` Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2024-03-29 15:06 UTC (permalink / raw)
  To: Kuniyuki Iwashima; +Cc: edumazet, davem, eric.dumazet, netdev, pabeni

On Wed, 27 Mar 2024 12:29:34 -0700 Kuniyuki Iwashima wrote:
> > -	for (slot = 0; slot <= hashinfo->ehash_mask; slot++) {
> > -		struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
> > +	for (slot = 0; slot <= ehash_mask; slot++, head++) {
> > +  
> 
> unnecessary blank link here.

I've seen some other core kernel contributors add empty lines after 
for or if statements, so I think this is intentional. Not sure why
the empty line helps, either, TBH, but we have been letting it slide 
so far.

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

* Re: [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge()
  2024-03-27 19:12 [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge() Eric Dumazet
  2024-03-27 19:29 ` Kuniyuki Iwashima
@ 2024-03-29 15:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-03-29 15:20 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, pabeni, netdev, eric.dumazet

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 27 Mar 2024 19:12:06 +0000 you wrote:
> TCP ehash table is often sparsely populated.
> 
> inet_twsk_purge() spends too much time calling cond_resched().
> 
> This patch can reduce time spent in inet_twsk_purge() by 20x.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> 
> [...]

Here is the summary with links:
  - [net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge()
    https://git.kernel.org/netdev/net-next/c/50e2907ef8bb

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge()
  2024-03-29 15:06   ` Jakub Kicinski
@ 2024-03-29 15:24     ` Eric Dumazet
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2024-03-29 15:24 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Kuniyuki Iwashima, davem, eric.dumazet, netdev, pabeni

On Fri, Mar 29, 2024 at 4:06 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Wed, 27 Mar 2024 12:29:34 -0700 Kuniyuki Iwashima wrote:
> > > -   for (slot = 0; slot <= hashinfo->ehash_mask; slot++) {
> > > -           struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
> > > +   for (slot = 0; slot <= ehash_mask; slot++, head++) {
> > > +
> >
> > unnecessary blank link here.
>
> I've seen some other core kernel contributors add empty lines after
> for or if statements, so I think this is intentional. Not sure why
> the empty line helps, either, TBH, but we have been letting it slide
> so far.

I will delete this extra line in the following patch, thanks !

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

end of thread, other threads:[~2024-03-29 15:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27 19:12 [PATCH net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge() Eric Dumazet
2024-03-27 19:29 ` Kuniyuki Iwashima
2024-03-29 15:06   ` Jakub Kicinski
2024-03-29 15:24     ` Eric Dumazet
2024-03-29 15:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.