Skip to content

Commit c2dd405

Browse files
edumazetdavem330
authored andcommitted
net: minor optimization in __alloc_skb()
TCP allocates 'fast clones' skbs for packets in tx queues. Currently, __alloc_skb() initializes the companion fclone field to SKB_FCLONE_CLONE, and leaves other fields untouched. It makes sense to defer this init much later in skb_clone(), because all fclone fields are copied and hot in cpu caches at that time. This removes one cache line miss in __alloc_skb(), cost seen on an host with 256 cpus all competing on memory accesses. Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8e15145 commit c2dd405

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

net/core/skbuff.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,6 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
454454

455455
skb->fclone = SKB_FCLONE_ORIG;
456456
refcount_set(&fclones->fclone_ref, 1);
457-
458-
fclones->skb2.fclone = SKB_FCLONE_CLONE;
459457
}
460458

461459
return skb;
@@ -1513,6 +1511,7 @@ struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
15131511
refcount_read(&fclones->fclone_ref) == 1) {
15141512
n = &fclones->skb2;
15151513
refcount_set(&fclones->fclone_ref, 2);
1514+
n->fclone = SKB_FCLONE_CLONE;
15161515
} else {
15171516
if (skb_pfmemalloc(skb))
15181517
gfp_mask |= __GFP_MEMALLOC;

0 commit comments

Comments
 (0)