Skip to content

Commit bad93e9

Browse files
Octavian Purdiladavem330
authored andcommitted
net: add __pskb_copy_fclone and pskb_copy_for_clone
There are several instances where a pskb_copy or __pskb_copy is immediately followed by an skb_clone. Add a couple of new functions to allow the copy skb to be allocated from the fclone cache and thus speed up subsequent skb_clone calls. Cc: Alexander Smirnov <alex.bluesman.smirnov@gmail.com> Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Cc: Marek Lindner <mareklindner@neomailbox.ch> Cc: Simon Wunderlich <sw@simonwunderlich.de> Cc: Antonio Quartulli <antonio@meshcoding.com> Cc: Marcel Holtmann <marcel@holtmann.org> Cc: Gustavo Padovan <gustavo@padovan.org> Cc: Johan Hedberg <johan.hedberg@gmail.com> Cc: Arvid Brodin <arvid.brodin@alten.se> Cc: Patrick McHardy <kaber@trash.net> Cc: Pablo Neira Ayuso <pablo@netfilter.org> Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> Cc: Lauro Ramos Venancio <lauro.venancio@openbossa.org> Cc: Aloisio Almeida Jr <aloisio.almeida@openbossa.org> Cc: Samuel Ortiz <sameo@linux.intel.com> Cc: Jon Maloy <jon.maloy@ericsson.com> Cc: Allan Stephens <allan.stephens@windriver.com> Cc: Andrew Hendry <andrew.hendry@gmail.com> Cc: Eric Dumazet <edumazet@google.com> Reviewed-by: Christoph Paasch <christoph.paasch@uclouvain.be> Signed-off-by: Octavian Purdila <octavian.purdila@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1a0b20b commit bad93e9

8 files changed

Lines changed: 34 additions & 16 deletions

File tree

‎include/linux/skbuff.h‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,13 @@ struct sk_buff *skb_morph(struct sk_buff *dst, struct sk_buff *src);
744744
int skb_copy_ubufs(struct sk_buff *skb, gfp_t gfp_mask);
745745
struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t priority);
746746
struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t priority);
747-
struct sk_buff *__pskb_copy(struct sk_buff *skb, int headroom, gfp_t gfp_mask);
747+
struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom,
748+
gfp_t gfp_mask, bool fclone);
749+
static inline struct sk_buff *__pskb_copy(struct sk_buff *skb, int headroom,
750+
gfp_t gfp_mask)
751+
{
752+
return __pskb_copy_fclone(skb, headroom, gfp_mask, false);
753+
}
748754

749755
int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, gfp_t gfp_mask);
750756
struct sk_buff *skb_realloc_headroom(struct sk_buff *skb,
@@ -2238,6 +2244,14 @@ static inline struct sk_buff *pskb_copy(struct sk_buff *skb,
22382244
return __pskb_copy(skb, skb_headroom(skb), gfp_mask);
22392245
}
22402246

2247+
2248+
static inline struct sk_buff *pskb_copy_for_clone(struct sk_buff *skb,
2249+
gfp_t gfp_mask)
2250+
{
2251+
return __pskb_copy_fclone(skb, skb_headroom(skb), gfp_mask, true);
2252+
}
2253+
2254+
22412255
/**
22422256
* skb_clone_writable - is the header of a clone writable
22432257
* @skb: buffer to check

‎net/batman-adv/distributed-arp-table.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static bool batadv_dat_send_data(struct batadv_priv *bat_priv,
594594
if (!neigh_node)
595595
goto free_orig;
596596

597-
tmp_skb = pskb_copy(skb, GFP_ATOMIC);
597+
tmp_skb = pskb_copy_for_clone(skb, GFP_ATOMIC);
598598
if (!batadv_send_skb_prepare_unicast_4addr(bat_priv, tmp_skb,
599599
cand[i].orig_node,
600600
packet_subtype)) {

‎net/batman-adv/network-coding.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ static void batadv_nc_skb_store_before_coding(struct batadv_priv *bat_priv,
13441344
struct ethhdr *ethhdr;
13451345

13461346
/* Copy skb header to change the mac header */
1347-
skb = pskb_copy(skb, GFP_ATOMIC);
1347+
skb = pskb_copy_for_clone(skb, GFP_ATOMIC);
13481348
if (!skb)
13491349
return;
13501350

‎net/bluetooth/hci_sock.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
143143

144144
if (!skb_copy) {
145145
/* Create a private copy with headroom */
146-
skb_copy = __pskb_copy(skb, 1, GFP_ATOMIC);
146+
skb_copy = __pskb_copy_fclone(skb, 1, GFP_ATOMIC, true);
147147
if (!skb_copy)
148148
continue;
149149

@@ -247,8 +247,8 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)
247247
struct hci_mon_hdr *hdr;
248248

249249
/* Create a private copy with headroom */
250-
skb_copy = __pskb_copy(skb, HCI_MON_HDR_SIZE,
251-
GFP_ATOMIC);
250+
skb_copy = __pskb_copy_fclone(skb, HCI_MON_HDR_SIZE,
251+
GFP_ATOMIC, true);
252252
if (!skb_copy)
253253
continue;
254254

‎net/core/skbuff.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,13 @@ struct sk_buff *skb_copy(const struct sk_buff *skb, gfp_t gfp_mask)
951951
EXPORT_SYMBOL(skb_copy);
952952

953953
/**
954-
* __pskb_copy - create copy of an sk_buff with private head.
954+
* __pskb_copy_fclone - create copy of an sk_buff with private head.
955955
* @skb: buffer to copy
956956
* @headroom: headroom of new skb
957957
* @gfp_mask: allocation priority
958+
* @fclone: if true allocate the copy of the skb from the fclone
959+
* cache instead of the head cache; it is recommended to set this
960+
* to true for the cases where the copy will likely be cloned
958961
*
959962
* Make a copy of both an &sk_buff and part of its data, located
960963
* in header. Fragmented data remain shared. This is used when
@@ -964,11 +967,12 @@ EXPORT_SYMBOL(skb_copy);
964967
* The returned buffer has a reference count of 1.
965968
*/
966969

967-
struct sk_buff *__pskb_copy(struct sk_buff *skb, int headroom, gfp_t gfp_mask)
970+
struct sk_buff *__pskb_copy_fclone(struct sk_buff *skb, int headroom,
971+
gfp_t gfp_mask, bool fclone)
968972
{
969973
unsigned int size = skb_headlen(skb) + headroom;
970-
struct sk_buff *n = __alloc_skb(size, gfp_mask,
971-
skb_alloc_rx_flag(skb), NUMA_NO_NODE);
974+
int flags = skb_alloc_rx_flag(skb) | (fclone ? SKB_ALLOC_FCLONE : 0);
975+
struct sk_buff *n = __alloc_skb(size, gfp_mask, flags, NUMA_NO_NODE);
972976

973977
if (!n)
974978
goto out;
@@ -1008,7 +1012,7 @@ struct sk_buff *__pskb_copy(struct sk_buff *skb, int headroom, gfp_t gfp_mask)
10081012
out:
10091013
return n;
10101014
}
1011-
EXPORT_SYMBOL(__pskb_copy);
1015+
EXPORT_SYMBOL(__pskb_copy_fclone);
10121016

10131017
/**
10141018
* pskb_expand_head - reallocate header of &sk_buff

‎net/nfc/llcp_core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ void nfc_llcp_send_to_raw_sock(struct nfc_llcp_local *local,
680680
continue;
681681

682682
if (skb_copy == NULL) {
683-
skb_copy = __pskb_copy(skb, NFC_RAW_HEADER_SIZE,
684-
GFP_ATOMIC);
683+
skb_copy = __pskb_copy_fclone(skb, NFC_RAW_HEADER_SIZE,
684+
GFP_ATOMIC, true);
685685

686686
if (skb_copy == NULL)
687687
continue;

‎net/nfc/rawsock.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ void nfc_send_to_raw_sock(struct nfc_dev *dev, struct sk_buff *skb,
378378

379379
sk_for_each(sk, &raw_sk_list.head) {
380380
if (!skb_copy) {
381-
skb_copy = __pskb_copy(skb, NFC_RAW_HEADER_SIZE,
382-
GFP_ATOMIC);
381+
skb_copy = __pskb_copy_fclone(skb, NFC_RAW_HEADER_SIZE,
382+
GFP_ATOMIC, true);
383383
if (!skb_copy)
384384
continue;
385385

‎net/tipc/bcast.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
653653
tipc_bearer_send(b->identity, buf, &b->bcast_addr);
654654
} else {
655655
/* Avoid concurrent buffer access */
656-
tbuf = pskb_copy(buf, GFP_ATOMIC);
656+
tbuf = pskb_copy_for_clone(buf, GFP_ATOMIC);
657657
if (!tbuf)
658658
break;
659659
tipc_bearer_send(b->identity, tbuf, &b->bcast_addr);

0 commit comments

Comments
 (0)