All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] tcp: use a smaller percpu_counter batch size for sk_alloc
@ 2021-02-02 19:34 Wei Wang
  2021-02-04  4:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Wang @ 2021-02-02 19:34 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, netdev
  Cc: Eric Dumazet, Soheil Hassas Yeganeh

Currently, a percpu_counter with the default batch size (2*nr_cpus) is
used to record the total # of active sockets per protocol. This means
sk_sockets_allocated_read_positive() could be off by +/-2*(nr_cpus^2).
This under/over-estimation could lead to wrong memory suppression
conditions in __sk_raise_mem_allocated().
Fix this by using a more reasonable fixed batch size of 16.

See related commit cf86a086a180 ("net/dst: use a smaller percpu_counter
batch for dst entries accounting") that addresses a similar issue.

Signed-off-by: Wei Wang <weiwan@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Soheil Hassas Yeganeh <soheil@google.com>
---
 include/net/sock.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 129d200bccb4..690e496a0e79 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1350,14 +1350,18 @@ sk_memory_allocated_sub(struct sock *sk, int amt)
 	atomic_long_sub(amt, sk->sk_prot->memory_allocated);
 }
 
+#define SK_ALLOC_PERCPU_COUNTER_BATCH 16
+
 static inline void sk_sockets_allocated_dec(struct sock *sk)
 {
-	percpu_counter_dec(sk->sk_prot->sockets_allocated);
+	percpu_counter_add_batch(sk->sk_prot->sockets_allocated, -1,
+				 SK_ALLOC_PERCPU_COUNTER_BATCH);
 }
 
 static inline void sk_sockets_allocated_inc(struct sock *sk)
 {
-	percpu_counter_inc(sk->sk_prot->sockets_allocated);
+	percpu_counter_add_batch(sk->sk_prot->sockets_allocated, 1,
+				 SK_ALLOC_PERCPU_COUNTER_BATCH);
 }
 
 static inline u64
-- 
2.30.0.365.g02bc693789-goog


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

* Re: [PATCH net-next] tcp: use a smaller percpu_counter batch size for sk_alloc
  2021-02-02 19:34 [PATCH net-next] tcp: use a smaller percpu_counter batch size for sk_alloc Wei Wang
@ 2021-02-04  4:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-02-04  4:00 UTC (permalink / raw)
  To: Wei Wang; +Cc: davem, kuba, netdev, edumazet, soheil

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Tue,  2 Feb 2021 11:34:08 -0800 you wrote:
> Currently, a percpu_counter with the default batch size (2*nr_cpus) is
> used to record the total # of active sockets per protocol. This means
> sk_sockets_allocated_read_positive() could be off by +/-2*(nr_cpus^2).
> This under/over-estimation could lead to wrong memory suppression
> conditions in __sk_raise_mem_allocated().
> Fix this by using a more reasonable fixed batch size of 16.
> 
> [...]

Here is the summary with links:
  - [net-next] tcp: use a smaller percpu_counter batch size for sk_alloc
    https://git.kernel.org/netdev/net-next/c/f5a5589c7250

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] 2+ messages in thread

end of thread, other threads:[~2021-02-04  4:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 19:34 [PATCH net-next] tcp: use a smaller percpu_counter batch size for sk_alloc Wei Wang
2021-02-04  4:00 ` 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.