netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][net-next] netlink: avoid to allocate full skb when sending to many devices
@ 2018-09-18  5:26 Li RongQing
  2018-09-18 14:08 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Li RongQing @ 2018-09-18  5:26 UTC (permalink / raw)
  To: netdev

if skb->head is vmalloc address, when this skb is delivered, full
allocation for this skb is required, if there are many devices,
the full allocation will be called for every devices

now using the first time allocated skb when iterate other devices
to send, reduce full allocation and speedup deliver.

Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 net/netlink/af_netlink.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index e3a0538ec0be..095b99e3c1fb 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -278,11 +278,11 @@ static bool netlink_filter_tap(const struct sk_buff *skb)
 	return false;
 }
 
-static int __netlink_deliver_tap_skb(struct sk_buff *skb,
+static int __netlink_deliver_tap_skb(struct sk_buff **skb,
 				     struct net_device *dev)
 {
 	struct sk_buff *nskb;
-	struct sock *sk = skb->sk;
+	struct sock *sk = (*skb)->sk;
 	int ret = -ENOMEM;
 
 	if (!net_eq(dev_net(dev), sock_net(sk)))
@@ -290,10 +290,12 @@ static int __netlink_deliver_tap_skb(struct sk_buff *skb,
 
 	dev_hold(dev);
 
-	if (is_vmalloc_addr(skb->head))
-		nskb = netlink_to_full_skb(skb, GFP_ATOMIC);
+	if (is_vmalloc_addr((*skb)->head)) {
+		nskb = netlink_to_full_skb(*skb, GFP_ATOMIC);
+		*skb = nskb;
+	}
 	else
-		nskb = skb_clone(skb, GFP_ATOMIC);
+		nskb = skb_clone(*skb, GFP_ATOMIC);
 	if (nskb) {
 		nskb->dev = dev;
 		nskb->protocol = htons((u16) sk->sk_protocol);
@@ -318,7 +320,7 @@ static void __netlink_deliver_tap(struct sk_buff *skb, struct netlink_tap_net *n
 		return;
 
 	list_for_each_entry_rcu(tmp, &nn->netlink_tap_all, list) {
-		ret = __netlink_deliver_tap_skb(skb, tmp->dev);
+		ret = __netlink_deliver_tap_skb(&skb, tmp->dev);
 		if (unlikely(ret))
 			break;
 	}
-- 
2.16.2

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

* Re: [PATCH][net-next] netlink: avoid to allocate full skb when sending to many devices
  2018-09-18  5:26 [PATCH][net-next] netlink: avoid to allocate full skb when sending to many devices Li RongQing
@ 2018-09-18 14:08 ` Eric Dumazet
  2018-09-19  1:19   ` 答复: " Li,Rongqing
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2018-09-18 14:08 UTC (permalink / raw)
  To: Li RongQing, netdev



On 09/17/2018 10:26 PM, Li RongQing wrote:
> if skb->head is vmalloc address, when this skb is delivered, full
> allocation for this skb is required, if there are many devices,
> the full allocation will be called for every devices
> 
> now using the first time allocated skb when iterate other devices
> to send, reduce full allocation and speedup deliver.
> 
> Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  net/netlink/af_netlink.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
>

This looks very broken to me.

Only the original skb (given as an argument to __netlink_deliver_tap()) is guaranteed to not
disappear while the loop is performed.

(There is no skb_clone() after the first netlink_to_full_skb())

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

* 答复: [PATCH][net-next] netlink: avoid to allocate full skb when sending to many devices
  2018-09-18 14:08 ` Eric Dumazet
@ 2018-09-19  1:19   ` Li,Rongqing
  0 siblings, 0 replies; 3+ messages in thread
From: Li,Rongqing @ 2018-09-19  1:19 UTC (permalink / raw)
  To: Eric Dumazet, netdev

> On 09/17/2018 10:26 PM, Li RongQing wrote:
> > if skb->head is vmalloc address, when this skb is delivered, full
> > allocation for this skb is required, if there are many devices, the
> > ---
> >  net/netlink/af_netlink.c | 14 ++++++++------
> >  1 file changed, 8 insertions(+), 6 deletions(-)
> >
> >
> 
> This looks very broken to me.
> 
> Only the original skb (given as an argument to __netlink_deliver_tap()) is
> guaranteed to not disappear while the loop is performed.
> 
> (There is no skb_clone() after the first netlink_to_full_skb())
> 

Thank you;

I will rework it

-RongQing

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

end of thread, other threads:[~2018-09-19  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-18  5:26 [PATCH][net-next] netlink: avoid to allocate full skb when sending to many devices Li RongQing
2018-09-18 14:08 ` Eric Dumazet
2018-09-19  1:19   ` 答复: " Li,Rongqing

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