Skip to content

Commit dbe6629

Browse files
edumazetNipaLocal
authored andcommitted
net: fclone allocation small optimization
After skb allocation, initial skb->fclone value is 0 (SKB_FCLONE_UNAVAILABLE) We can replace one RMW sequence with a single OR instruction. movzbl 0x7e(%r13),%eax // skb->fclone = SKB_FCLONE_ORIG; and $0xf3,%al or $0x4,%al mov %al,0x7e(%r13) -> or $0x4,0x7e(%r13) // skb->fclone |= SKB_FCLONE_ORIG; Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: NipaLocal <nipa@local>
1 parent 60caabc commit dbe6629

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

net/core/skbuff.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,14 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
723723

724724
fclones = container_of(skb, struct sk_buff_fclones, skb1);
725725

726-
skb->fclone = SKB_FCLONE_ORIG;
726+
/* skb->fclone is a 2bits field.
727+
* Replace expensive RMW (skb->fclone = SKB_FCLONE_ORIG)
728+
* with a single OR.
729+
*/
730+
BUILD_BUG_ON(SKB_FCLONE_UNAVAILABLE != 0);
731+
DEBUG_NET_WARN_ON_ONCE(skb->fclone != SKB_FCLONE_UNAVAILABLE);
732+
skb->fclone |= SKB_FCLONE_ORIG;
733+
727734
refcount_set(&fclones->fclone_ref, 1);
728735
}
729736

0 commit comments

Comments
 (0)