udp: introduce __sk_mem_schedule() usage
Subsystems (4)
PATCH v3 1/1 udp: introduce __sk_mem_schedule() usage
From: Jason Xing <[email protected]>
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.
---
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 | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-)
net/ipv4/udp.c +18 -13
@@ -1531,10 +1531,23 @@ 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 ; + + sk->sk_forward_alloc -= size; + +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,20 +1580,12 @@ 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; -/* no need to setup a destructor, we will explicitly release the * forward allocated memory on dequeue */
Signature · 1 line
2.37.3
Paolo Abeni
maintainerQuoted 28 lines · Jason Xing
From: Jason Xing <[email protected]>
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.Signed-off-by Jason Xing <[email protected]>---
v3:
1) get rid of inline suggested by Simon Hormanv2:
1) change the title and body message
2) use__sk_mem_schedule()instead suggested by Paolo Abeni--- net/ipv4/udp.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-)net/ipv4/udp.c +0
-0@@ -1531,10 +1531,23 @@ static void busylock_release(spinlock_t *busy)spin_unlock (busy); }
net/ipv4/udp.c static void busylock_release(spinlock_t *busy) · line 1542
Quoted 10 lines
net/ipv4/udp.c +9
-0+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 ; + + sk->sk_forward_alloc -= size;
I think it's better if you maintain the above statement outside of this
helper: it's a bit confusing that rmem_schedule() actually consumes fwd memory.
Side note
Cheers,
Paolo
Quoted 31 lines · Paolo Abeni
Quoted 29 lines · Jason Xing
From: Jason Xing <[email protected]>
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.Signed-off-by Jason Xing <[email protected]>---
v3:
1) get rid of inline suggested by Simon Hormanv2:
1) change the title and body message
2) use__sk_mem_schedule()instead suggested by Paolo Abeni--- net/ipv4/udp.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-)net/ipv4/udp.c +0
-0@@ -1531,10 +1531,23 @@ static void busylock_release(spinlock_t *busy)spin_unlock (busy); }
Quoted 13 lines
net/ipv4/udp.c static void busylock_release(spinlock_t *busy) · line 1542
Quoted 9 lines
net/ipv4/udp.c +9
-0+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 ; + + sk->sk_forward_alloc -= size;I think it's better if you maintain the above statement outside of this
helper: it's a bit confusing thatrmem_schedule()actually consumes fwd memory.
It does make sense.
Thanks,
Jason
Quoted 7 lines
Side note
Cheers,
Paolo