* [PATCH v4 net-next] udp: introduce __sk_mem_schedule() usage
@ 2023-03-08 2:11 Jason Xing
2023-03-08 9:45 ` Eric Dumazet
2023-03-10 7:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jason Xing @ 2023-03-08 2:11 UTC (permalink / raw)
To: simon.horman, willemdebruijn.kernel, davem, dsahern, edumazet,
kuba, pabeni
Cc: netdev, linux-kernel, bpf, kerneljasonxing, Jason Xing
From: Jason Xing <kernelxing@tencent.com>
Keep the accounting schema consistent across different protocols
with __sk_mem_schedule(). Besides, it adjusts a little bit on how
to calculate forward allocated memory compared to before. After
applied this patch, we could avoid receive path scheduling extra
amount of memory.
Link: https://lore.kernel.org/lkml/20230221110344.82818-1-kerneljasonxing@gmail.com/
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
v4:
1) Move one statement outside of the helper suggested by Paolo Abeni
v3:
1) get rid of inline suggested by Simon Horman
v2:
1) change the title and body message
2) use __sk_mem_schedule() instead suggested by Paolo Abeni
---
net/ipv4/udp.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index c605d171eb2d..dc8feb54d835 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1531,10 +1531,21 @@ static void busylock_release(spinlock_t *busy)
spin_unlock(busy);
}
+static int udp_rmem_schedule(struct sock *sk, int size)
+{
+ int delta;
+
+ delta = size - sk->sk_forward_alloc;
+ if (delta > 0 && !__sk_mem_schedule(sk, delta, SK_MEM_RECV))
+ return -ENOBUFS;
+
+ return 0;
+}
+
int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
{
struct sk_buff_head *list = &sk->sk_receive_queue;
- int rmem, delta, amt, err = -ENOMEM;
+ int rmem, err = -ENOMEM;
spinlock_t *busy = NULL;
int size;
@@ -1567,16 +1578,10 @@ 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 (!__sk_mem_raise_allocated(sk, delta, amt, SK_MEM_RECV)) {
- err = -ENOBUFS;
- spin_unlock(&list->lock);
- goto uncharge_drop;
- }
-
- sk->sk_forward_alloc += delta;
+ err = udp_rmem_schedule(sk, size);
+ if (err) {
+ spin_unlock(&list->lock);
+ goto uncharge_drop;
}
sk->sk_forward_alloc -= size;
--
2.37.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4 net-next] udp: introduce __sk_mem_schedule() usage
2023-03-08 2:11 [PATCH v4 net-next] udp: introduce __sk_mem_schedule() usage Jason Xing
@ 2023-03-08 9:45 ` Eric Dumazet
2023-03-10 7:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2023-03-08 9:45 UTC (permalink / raw)
To: Jason Xing
Cc: simon.horman, willemdebruijn.kernel, davem, dsahern, kuba, pabeni,
netdev, linux-kernel, bpf, Jason Xing
On Wed, Mar 8, 2023 at 3:13 AM Jason Xing <kerneljasonxing@gmail.com> wrote:
>
> From: Jason Xing <kernelxing@tencent.com>
>
> Keep the accounting schema consistent across different protocols
> with __sk_mem_schedule(). Besides, it adjusts a little bit on how
> to calculate forward allocated memory compared to before. After
> applied this patch, we could avoid receive path scheduling extra
> amount of memory.
>
> Link: https://lore.kernel.org/lkml/20230221110344.82818-1-kerneljasonxing@gmail.com/
> Signed-off-by: Jason Xing <kernelxing@tencent.com>
>
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4 net-next] udp: introduce __sk_mem_schedule() usage
2023-03-08 2:11 [PATCH v4 net-next] udp: introduce __sk_mem_schedule() usage Jason Xing
2023-03-08 9:45 ` Eric Dumazet
@ 2023-03-10 7:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-10 7:40 UTC (permalink / raw)
To: Jason Xing
Cc: simon.horman, willemdebruijn.kernel, davem, dsahern, edumazet,
kuba, pabeni, netdev, linux-kernel, bpf, kernelxing
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 8 Mar 2023 10:11:53 +0800 you wrote:
> From: Jason Xing <kernelxing@tencent.com>
>
> Keep the accounting schema consistent across different protocols
> with __sk_mem_schedule(). Besides, it adjusts a little bit on how
> to calculate forward allocated memory compared to before. After
> applied this patch, we could avoid receive path scheduling extra
> amount of memory.
>
> [...]
Here is the summary with links:
- [v4,net-next] udp: introduce __sk_mem_schedule() usage
https://git.kernel.org/netdev/net-next/c/fd9c31f83441
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] 3+ messages in thread
end of thread, other threads:[~2023-03-10 7:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-08 2:11 [PATCH v4 net-next] udp: introduce __sk_mem_schedule() usage Jason Xing
2023-03-08 9:45 ` Eric Dumazet
2023-03-10 7:40 ` 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).