diff mbox series

[net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge()

Message ID 20240327191206.508114-1-edumazet@google.com (mailing list archive)
State Accepted
Commit 50e2907ef8bb52cf80ecde9eec5c4dac07177146
Delegated to: Netdev Maintainers
Headers show
Series [net-next] tcp/dccp: bypass empty buckets in inet_twsk_purge() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 946 this patch: 946
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 1 maintainers not CCed: dsahern@kernel.org
netdev/build_clang success Errors and warnings before: 956 this patch: 956
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 957 this patch: 957
netdev/checkpatch warning CHECK: Blank lines aren't necessary after an open brace '{'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-29--06-00 (tests: 951)

Commit Message

Eric Dumazet March 27, 2024, 7:12 p.m. UTC
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(-)

Comments

Kuniyuki Iwashima March 27, 2024, 7:29 p.m. UTC | #1
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
>
Jakub Kicinski March 29, 2024, 3:06 p.m. UTC | #2
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.
patchwork-bot+netdevbpf@kernel.org March 29, 2024, 3:20 p.m. UTC | #3
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!
Eric Dumazet March 29, 2024, 3:24 p.m. UTC | #4
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 !
diff mbox series

Patch

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();