Skip to content

Commit ff04a77

Browse files
edumazetdavem330
authored andcommitted
net : optimize skb_release_data()
Cache skb_shinfo(skb) in a variable to avoid computing it multiple times. Reorganize the tests to remove one indentation level. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cec0831 commit ff04a77

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

net/core/skbuff.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -491,32 +491,33 @@ static void skb_free_head(struct sk_buff *skb)
491491

492492
static void skb_release_data(struct sk_buff *skb)
493493
{
494-
if (!skb->cloned ||
495-
!atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1,
496-
&skb_shinfo(skb)->dataref)) {
497-
if (skb_shinfo(skb)->nr_frags) {
498-
int i;
499-
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
500-
skb_frag_unref(skb, i);
501-
}
494+
struct skb_shared_info *shinfo = skb_shinfo(skb);
495+
int i;
502496

503-
/*
504-
* If skb buf is from userspace, we need to notify the caller
505-
* the lower device DMA has done;
506-
*/
507-
if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
508-
struct ubuf_info *uarg;
497+
if (skb->cloned &&
498+
atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1,
499+
&shinfo->dataref))
500+
return;
509501

510-
uarg = skb_shinfo(skb)->destructor_arg;
511-
if (uarg->callback)
512-
uarg->callback(uarg, true);
513-
}
502+
for (i = 0; i < shinfo->nr_frags; i++)
503+
__skb_frag_unref(&shinfo->frags[i]);
514504

515-
if (skb_has_frag_list(skb))
516-
skb_drop_fraglist(skb);
505+
/*
506+
* If skb buf is from userspace, we need to notify the caller
507+
* the lower device DMA has done;
508+
*/
509+
if (shinfo->tx_flags & SKBTX_DEV_ZEROCOPY) {
510+
struct ubuf_info *uarg;
517511

518-
skb_free_head(skb);
512+
uarg = shinfo->destructor_arg;
513+
if (uarg->callback)
514+
uarg->callback(uarg, true);
519515
}
516+
517+
if (shinfo->frag_list)
518+
kfree_skb_list(shinfo->frag_list);
519+
520+
skb_free_head(skb);
520521
}
521522

522523
/*

0 commit comments

Comments
 (0)