netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: add a scheduling point in established_get_first()
@ 2023-06-30  7:18 Jian Wen
  2023-06-30 10:49 ` Eric Dumazet
  2023-07-11  3:24 ` [PATCH v2 " Jian Wen
  0 siblings, 2 replies; 5+ messages in thread
From: Jian Wen @ 2023-06-30  7:18 UTC (permalink / raw)
  To: edumazet, davem; +Cc: Jian Wen, netdev, wenjianhn

Kubernetes[1] is going to stick with /proc/net/tcp for a while.

This commit reduces the scheduling latency introduced by established_get_first(),
similar to commit acffb584cda7 ("net: diag: add a scheduling point in inet_diag_dump_icsk()").

In our environment, the scheduling latency affects:
1. the performance of latency-sensitive services like Redis
2. the delay of synchronize_net() that is called with RTNL is locked
   12 times when Dockerd is deleting a container

[1] https://github.com/google/cadvisor/blob/v0.47.2/container/libcontainer/handler.go#L130

Signed-off-by: Jian Wen <wenjian1@xiaomi.com>
---
 net/ipv4/tcp_ipv4.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index fd365de4d5ff..3271848e9c9a 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -57,6 +57,7 @@
 #include <linux/init.h>
 #include <linux/times.h>
 #include <linux/slab.h>
+#include <linux/sched.h>
 
 #include <net/net_namespace.h>
 #include <net/icmp.h>
@@ -2456,6 +2457,7 @@ static void *established_get_first(struct seq_file *seq)
 				return sk;
 		}
 		spin_unlock_bh(lock);
+		cond_resched();
 	}
 
 	return NULL;
-- 
2.25.1


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

* Re: [PATCH net-next] tcp: add a scheduling point in established_get_first()
  2023-06-30  7:18 [PATCH net-next] tcp: add a scheduling point in established_get_first() Jian Wen
@ 2023-06-30 10:49 ` Eric Dumazet
  2023-07-11  3:24 ` [PATCH v2 " Jian Wen
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2023-06-30 10:49 UTC (permalink / raw)
  To: Jian Wen; +Cc: davem, Jian Wen, netdev

On Fri, Jun 30, 2023 at 9:18 AM Jian Wen <wenjianhn@gmail.com> wrote:
>
> Kubernetes[1] is going to stick with /proc/net/tcp for a while.
>
> This commit reduces the scheduling latency introduced by established_get_first(),
> similar to commit acffb584cda7 ("net: diag: add a scheduling point in inet_diag_dump_icsk()").
>
> In our environment, the scheduling latency affects:
> 1. the performance of latency-sensitive services like Redis
> 2. the delay of synchronize_net() that is called with RTNL is locked
>    12 times when Dockerd is deleting a container
>
> [1] https://github.com/google/cadvisor/blob/v0.47.2/container/libcontainer/handler.go#L130
>
> Signed-off-by: Jian Wen <wenjian1@xiaomi.com>
> ---
>  net/ipv4/tcp_ipv4.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index fd365de4d5ff..3271848e9c9a 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -57,6 +57,7 @@
>  #include <linux/init.h>
>  #include <linux/times.h>
>  #include <linux/slab.h>
> +#include <linux/sched.h>
>
>  #include <net/net_namespace.h>
>  #include <net/icmp.h>
> @@ -2456,6 +2457,7 @@ static void *established_get_first(struct seq_file *seq)
>                                 return sk;
>                 }
>                 spin_unlock_bh(lock);
> +               cond_resched();
>         }
>
>         return NULL;
> --
> 2.25.1
>
Hi Jian, thanks for your patch.

Few points:

- Note that net-next is currently closed (merge window)

- Also, /proc interface does not hold RTNL, not sure why you mention
RTNL in the changelog,
and not other mutexes in the kernel that also would be impacted by the
long duration of established_get_first() ?

- The cond_resched() should be done even if all buckets are empty ?

- Using inet_diag, Kubernetes could list both IPv4/IPv6 sockets in one dump,
and benefit from more modern interface (with cond_resched() already there)

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

* [PATCH v2 net-next] tcp: add a scheduling point in established_get_first()
  2023-06-30  7:18 [PATCH net-next] tcp: add a scheduling point in established_get_first() Jian Wen
  2023-06-30 10:49 ` Eric Dumazet
@ 2023-07-11  3:24 ` Jian Wen
  2023-07-12 13:22   ` Simon Horman
  2023-07-12 21:50   ` patchwork-bot+netdevbpf
  1 sibling, 2 replies; 5+ messages in thread
From: Jian Wen @ 2023-07-11  3:24 UTC (permalink / raw)
  To: edumazet, davem; +Cc: Jian Wen, netdev, wenjianhn

Kubernetes[1] is going to stick with /proc/net/tcp for a while.

This commit reduces the scheduling latency introduced by
established_get_first(), similar to commit acffb584cda7 ("net: diag:
add a scheduling point in inet_diag_dump_icsk()").

In our environment, the scheduling latency affects the performance of
latency-sensitive services like Redis.

Changes in V2 :
 - call cond_resched() before checking if a bucket is empty as
   suggested by Eric Dumazet
 - removed the delay of synchronize_net() from the commit message

[1] https://github.com/google/cadvisor/blob/v0.47.2/container/libcontainer/handler.go#L130

Signed-off-by: Jian Wen <wenjian1@xiaomi.com>
---
 net/ipv4/tcp_ipv4.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index fd365de4d5ff..cecd5a135e64 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -57,6 +57,7 @@
 #include <linux/init.h>
 #include <linux/times.h>
 #include <linux/slab.h>
+#include <linux/sched.h>
 
 #include <net/net_namespace.h>
 #include <net/icmp.h>
@@ -2446,6 +2447,8 @@ static void *established_get_first(struct seq_file *seq)
 		struct hlist_nulls_node *node;
 		spinlock_t *lock = inet_ehash_lockp(hinfo, st->bucket);
 
+		cond_resched();
+
 		/* Lockless fast path for the common case of empty buckets */
 		if (empty_bucket(hinfo, st))
 			continue;
-- 
2.25.1


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

* Re: [PATCH v2 net-next] tcp: add a scheduling point in established_get_first()
  2023-07-11  3:24 ` [PATCH v2 " Jian Wen
@ 2023-07-12 13:22   ` Simon Horman
  2023-07-12 21:50   ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Horman @ 2023-07-12 13:22 UTC (permalink / raw)
  To: Jian Wen; +Cc: edumazet, davem, Jian Wen, netdev

On Tue, Jul 11, 2023 at 11:24:05AM +0800, Jian Wen wrote:
> Kubernetes[1] is going to stick with /proc/net/tcp for a while.
> 
> This commit reduces the scheduling latency introduced by
> established_get_first(), similar to commit acffb584cda7 ("net: diag:
> add a scheduling point in inet_diag_dump_icsk()").
> 
> In our environment, the scheduling latency affects the performance of
> latency-sensitive services like Redis.
> 
> Changes in V2 :
>  - call cond_resched() before checking if a bucket is empty as
>    suggested by Eric Dumazet
>  - removed the delay of synchronize_net() from the commit message
> 
> [1] https://github.com/google/cadvisor/blob/v0.47.2/container/libcontainer/handler.go#L130
> 
> Signed-off-by: Jian Wen <wenjian1@xiaomi.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCH v2 net-next] tcp: add a scheduling point in established_get_first()
  2023-07-11  3:24 ` [PATCH v2 " Jian Wen
  2023-07-12 13:22   ` Simon Horman
@ 2023-07-12 21:50   ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-12 21:50 UTC (permalink / raw)
  To: Jian Wen; +Cc: edumazet, davem, wenjian1, netdev

Hello:

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

On Tue, 11 Jul 2023 11:24:05 +0800 you wrote:
> Kubernetes[1] is going to stick with /proc/net/tcp for a while.
> 
> This commit reduces the scheduling latency introduced by
> established_get_first(), similar to commit acffb584cda7 ("net: diag:
> add a scheduling point in inet_diag_dump_icsk()").
> 
> In our environment, the scheduling latency affects the performance of
> latency-sensitive services like Redis.
> 
> [...]

Here is the summary with links:
  - [v2,net-next] tcp: add a scheduling point in established_get_first()
    https://git.kernel.org/netdev/net-next/c/9f4a7c930284

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

end of thread, other threads:[~2023-07-12 21:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-30  7:18 [PATCH net-next] tcp: add a scheduling point in established_get_first() Jian Wen
2023-06-30 10:49 ` Eric Dumazet
2023-07-11  3:24 ` [PATCH v2 " Jian Wen
2023-07-12 13:22   ` Simon Horman
2023-07-12 21:50   ` patchwork-bot+netdevbpf

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).