netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] udp: fix memory schedule error
@ 2023-02-21 11:03 Jason Xing
  2023-02-21 12:27 ` Paolo Abeni
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Xing @ 2023-02-21 11:03 UTC (permalink / raw)
  To: willemdebruijn.kernel, davem, dsahern, edumazet, kuba, pabeni
  Cc: netdev, linux-kernel, bpf, kerneljasonxing, Jason Xing

From: Jason Xing <kernelxing@tencent.com>

Quoting from the commit 7c80b038d23e ("net: fix sk_wmem_schedule()
and sk_rmem_schedule() errors"):

"If sk->sk_forward_alloc is 150000, and we need to schedule 150001 bytes,
we want to allocate 1 byte more (rounded up to one page),
instead of 150001"

After applied this patch, we could avoid receive path scheduling
extra amount of memory.

Fixes: f970bd9e3a06 ("udp: implement memory accounting helpers")
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
 net/ipv4/udp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 9592fe3e444a..a13f622cfa36 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1567,16 +1567,16 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
 		goto uncharge_drop;
 
 	spin_lock(&list->lock);
-	if (size >= sk->sk_forward_alloc) {
-		amt = sk_mem_pages(size);
-		delta = amt << PAGE_SHIFT;
+	if (size > sk->sk_forward_alloc) {
+		delta = size - sk->sk_forward_alloc;
+		amt = sk_mem_pages(delta);
 		if (!__sk_mem_raise_allocated(sk, delta, amt, SK_MEM_RECV)) {
 			err = -ENOBUFS;
 			spin_unlock(&list->lock);
 			goto uncharge_drop;
 		}
 
-		sk->sk_forward_alloc += delta;
+		sk->sk_forward_alloc += amt << PAGE_SHIFT;
 	}
 
 	sk->sk_forward_alloc -= size;
-- 
2.37.3


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

end of thread, other threads:[~2023-02-23  9:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-21 11:03 [PATCH net] udp: fix memory schedule error Jason Xing
2023-02-21 12:27 ` Paolo Abeni
2023-02-21 12:35   ` Eric Dumazet
2023-02-21 13:44     ` Jason Xing
2023-02-21 13:39   ` Jason Xing
2023-02-21 14:46     ` Paolo Abeni
2023-02-21 15:46       ` Jason Xing
2023-02-22  3:47         ` Jason Xing
2023-02-23  8:39           ` Paolo Abeni
2023-02-23  9:07             ` Jason Xing

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