Commit fdfb8047 authored by Mala Anand's avatar Mala Anand Committed by David S. Miller

[NET]: Move SKB header init to allocation time for better cache behavior.

parent 19e8c107
...@@ -196,40 +196,6 @@ struct sk_buff *alloc_skb(unsigned int size, int gfp_mask) ...@@ -196,40 +196,6 @@ struct sk_buff *alloc_skb(unsigned int size, int gfp_mask)
goto nodata; goto nodata;
/* XXX: does not include slab overhead */ /* XXX: does not include slab overhead */
skb->truesize = size + sizeof(struct sk_buff);
/* Load the data pointers. */
skb->head = skb->data = skb->tail = data;
skb->end = data + size;
/* Set up other state */
skb->len = 0;
skb->cloned = 0;
skb->data_len = 0;
atomic_set(&skb->users, 1);
atomic_set(&(skb_shinfo(skb)->dataref), 1);
skb_shinfo(skb)->nr_frags = 0;
skb_shinfo(skb)->tso_size = 0;
skb_shinfo(skb)->tso_segs = 0;
skb_shinfo(skb)->frag_list = NULL;
out:
return skb;
nodata:
skb_head_to_pool(skb);
skb = NULL;
goto out;
}
/*
* Slab constructor for a skb head.
*/
static void skb_headerinit(void *p, kmem_cache_t *cache,
unsigned long flags)
{
struct sk_buff *skb = p;
skb->next = skb->prev = NULL; skb->next = skb->prev = NULL;
skb->list = NULL; skb->list = NULL;
skb->sk = NULL; skb->sk = NULL;
...@@ -238,27 +204,50 @@ static void skb_headerinit(void *p, kmem_cache_t *cache, ...@@ -238,27 +204,50 @@ static void skb_headerinit(void *p, kmem_cache_t *cache,
skb->dst = NULL; skb->dst = NULL;
skb->sp = NULL; skb->sp = NULL;
memset(skb->cb, 0, sizeof(skb->cb)); memset(skb->cb, 0, sizeof(skb->cb));
/* Set up other state */
skb->len = 0;
skb->data_len = 0;
skb->csum = 0;
skb->cloned = 0;
skb->pkt_type = PACKET_HOST; /* Default type */ skb->pkt_type = PACKET_HOST; /* Default type */
skb->ip_summed = 0; skb->ip_summed = 0;
skb->priority = 0; skb->priority = 0;
atomic_set(&skb->users, 1);
skb->security = 0; /* By default packets are insecure */ skb->security = 0; /* By default packets are insecure */
skb->destructor = NULL; skb->truesize = size + sizeof(struct sk_buff);
/* Load the data pointers. */
skb->head = skb->data = skb->tail = data;
skb->end = data + size;
skb->destructor = NULL;
#ifdef CONFIG_NETFILTER #ifdef CONFIG_NETFILTER
skb->nfmark = skb->nfcache = 0; skb->nfmark = skb->nfcache = 0;
skb->nfct = NULL; skb->nfct = NULL;
#ifdef CONFIG_NETFILTER_DEBUG #ifdef CONFIG_NETFILTER_DEBUG
skb->nf_debug = 0; skb->nf_debug = 0;
#endif #endif
#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
skb->nf_bridge = NULL; skb->nf_bridge = NULL;
#endif #endif
#endif #endif
#ifdef CONFIG_NET_SCHED #ifdef CONFIG_NET_SCHED
skb->tc_index = 0; skb->tc_index = 0;
#endif #endif
atomic_set(&(skb_shinfo(skb)->dataref), 1);
skb_shinfo(skb)->nr_frags = 0;
skb_shinfo(skb)->tso_size = 0;
skb_shinfo(skb)->tso_segs = 0;
skb_shinfo(skb)->frag_list = NULL;
out:
return skb;
nodata:
skb_head_to_pool(skb);
skb = NULL;
goto out;
} }
static void skb_drop_fraglist(struct sk_buff *skb) static void skb_drop_fraglist(struct sk_buff *skb)
{ {
struct sk_buff *list = skb_shinfo(skb)->frag_list; struct sk_buff *list = skb_shinfo(skb)->frag_list;
...@@ -339,7 +328,6 @@ void __kfree_skb(struct sk_buff *skb) ...@@ -339,7 +328,6 @@ void __kfree_skb(struct sk_buff *skb)
nf_bridge_put(skb->nf_bridge); nf_bridge_put(skb->nf_bridge);
#endif #endif
#endif #endif
skb_headerinit(skb, NULL, 0); /* clean state */
kfree_skbmem(skb); kfree_skbmem(skb);
} }
...@@ -1261,7 +1249,7 @@ void __init skb_init(void) ...@@ -1261,7 +1249,7 @@ void __init skb_init(void)
sizeof(struct sk_buff), sizeof(struct sk_buff),
0, 0,
SLAB_HWCACHE_ALIGN, SLAB_HWCACHE_ALIGN,
skb_headerinit, NULL); NULL, NULL);
if (!skbuff_head_cache) if (!skbuff_head_cache)
panic("cannot create skbuff cache"); panic("cannot create skbuff cache");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment