Skip to content

Commit c818fa9

Browse files
edumazetdavem330
authored andcommitted
net: cache skb_shinfo() in skb_try_coalesce()
Compiler does not really know that skb_shinfo(to|from) are constants in skb_try_coalesce(), lets cache their values to shrink code. We might even take care of skb_zcopy() calls later. $ size net/core/skbuff.o.before net/core/skbuff.o text data bss dec hex filename 40727 1298 0 42025 a429 net/core/skbuff.o.before 40631 1298 0 41929 a3c9 net/core/skbuff.o Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e9b871e commit c818fa9

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

net/core/skbuff.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,6 +4767,7 @@ EXPORT_SYMBOL(kfree_skb_partial);
47674767
bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
47684768
bool *fragstolen, int *delta_truesize)
47694769
{
4770+
struct skb_shared_info *to_shinfo, *from_shinfo;
47704771
int i, delta, len = from->len;
47714772

47724773
*fragstolen = false;
@@ -4781,7 +4782,9 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
47814782
return true;
47824783
}
47834784

4784-
if (skb_has_frag_list(to) || skb_has_frag_list(from))
4785+
to_shinfo = skb_shinfo(to);
4786+
from_shinfo = skb_shinfo(from);
4787+
if (to_shinfo->frag_list || from_shinfo->frag_list)
47854788
return false;
47864789
if (skb_zcopy(to) || skb_zcopy(from))
47874790
return false;
@@ -4790,8 +4793,8 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
47904793
struct page *page;
47914794
unsigned int offset;
47924795

4793-
if (skb_shinfo(to)->nr_frags +
4794-
skb_shinfo(from)->nr_frags >= MAX_SKB_FRAGS)
4796+
if (to_shinfo->nr_frags +
4797+
from_shinfo->nr_frags >= MAX_SKB_FRAGS)
47954798
return false;
47964799

47974800
if (skb_head_is_locked(from))
@@ -4802,32 +4805,32 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
48024805
page = virt_to_head_page(from->head);
48034806
offset = from->data - (unsigned char *)page_address(page);
48044807

4805-
skb_fill_page_desc(to, skb_shinfo(to)->nr_frags,
4808+
skb_fill_page_desc(to, to_shinfo->nr_frags,
48064809
page, offset, skb_headlen(from));
48074810
*fragstolen = true;
48084811
} else {
4809-
if (skb_shinfo(to)->nr_frags +
4810-
skb_shinfo(from)->nr_frags > MAX_SKB_FRAGS)
4812+
if (to_shinfo->nr_frags +
4813+
from_shinfo->nr_frags > MAX_SKB_FRAGS)
48114814
return false;
48124815

48134816
delta = from->truesize - SKB_TRUESIZE(skb_end_offset(from));
48144817
}
48154818

48164819
WARN_ON_ONCE(delta < len);
48174820

4818-
memcpy(skb_shinfo(to)->frags + skb_shinfo(to)->nr_frags,
4819-
skb_shinfo(from)->frags,
4820-
skb_shinfo(from)->nr_frags * sizeof(skb_frag_t));
4821-
skb_shinfo(to)->nr_frags += skb_shinfo(from)->nr_frags;
4821+
memcpy(to_shinfo->frags + to_shinfo->nr_frags,
4822+
from_shinfo->frags,
4823+
from_shinfo->nr_frags * sizeof(skb_frag_t));
4824+
to_shinfo->nr_frags += from_shinfo->nr_frags;
48224825

48234826
if (!skb_cloned(from))
4824-
skb_shinfo(from)->nr_frags = 0;
4827+
from_shinfo->nr_frags = 0;
48254828

48264829
/* if the skb is not cloned this does nothing
48274830
* since we set nr_frags to 0.
48284831
*/
4829-
for (i = 0; i < skb_shinfo(from)->nr_frags; i++)
4830-
skb_frag_ref(from, i);
4832+
for (i = 0; i < from_shinfo->nr_frags; i++)
4833+
__skb_frag_ref(&from_shinfo->frags[i]);
48314834

48324835
to->truesize += delta;
48334836
to->len += len;

0 commit comments

Comments
 (0)