net: pskb_expand_head() optimization
authorEric Dumazet <eric.dumazet@gmail.com>
Thu, 22 Jul 2010 19:09:08 +0000 (19:09 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sun, 25 Jul 2010 04:05:57 +0000 (21:05 -0700)
Move frags[] at the end of struct skb_shared_info, and make
pskb_expand_head() copy only the used part of it instead of whole array.

This should avoid kmemcheck warnings and speedup pskb_expand_head() as
well, avoiding a lot of cache misses.

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/skbuff.h
net/core/skbuff.c

index f5aa87e1e0c8c8a8ef4ec34f50129f51a013de4a..d89876b806a0eb5a79adc0cce7546fca1f95b164 100644 (file)
@@ -202,10 +202,11 @@ struct skb_shared_info {
         */
        atomic_t        dataref;
 
-       skb_frag_t      frags[MAX_SKB_FRAGS];
        /* Intermediate layers must ensure that destructor_arg
         * remains valid until skb destructor */
        void *          destructor_arg;
+       /* must be last field, see pskb_expand_head() */
+       skb_frag_t      frags[MAX_SKB_FRAGS];
 };
 
 /* We divide dataref into two halves.  The higher 16 bits hold references
index 76d33ca5f037a5c886052e9e7aff206ee266c654..7da58a25ad923b74a0486ced4e516305efd0d187 100644 (file)
@@ -817,7 +817,7 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail,
        memcpy(data + nhead, skb->head, skb->tail - skb->head);
 #endif
        memcpy(data + size, skb_end_pointer(skb),
-              sizeof(struct skb_shared_info));
+              offsetof(struct skb_shared_info, frags[skb_shinfo(skb)->nr_frags]));
 
        for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
                get_page(skb_shinfo(skb)->frags[i].page);