Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: netdev@vger.kernel.org, "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
linux-kernel@vger.kernel.org,
Pavel Begunkov <asml.silence@gmail.com>
Subject: [PATCH 12/14] skbuff: optimise alloc_skb_with_frags()
Date: Tue, 11 Jan 2022 01:21:45 +0000 [thread overview]
Message-ID: <d98094be1435d5d8a98e0f7af26f175b64259d86.1641863490.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1641863490.git.asml.silence@gmail.com>
Many users of alloc_skb_with_frags() pass zero datalen, e.g.
all callers sock_alloc_send_skb() including udp. Extract and inline a
part of it doing skb allocation. BTW, do a minor cleanup, e.g. don't
set errcode in advance as it can't be optimised.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
include/linux/skbuff.h | 41 ++++++++++++++++++++++++++++++++++++-----
net/core/skbuff.c | 31 ++++++++++++-------------------
2 files changed, 48 insertions(+), 24 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 7fd2b44aada0..8ea145101b56 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1130,11 +1130,42 @@ static inline struct sk_buff *alloc_skb(unsigned int size,
return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
}
-struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
- unsigned long data_len,
- int max_page_order,
- int *errcode,
- gfp_t gfp_mask);
+struct sk_buff *alloc_skb_frags(struct sk_buff *skb,
+ unsigned long data_len,
+ int max_page_order,
+ int *errcode,
+ gfp_t gfp_mask);
+
+/**
+ * alloc_skb_with_frags - allocate skb with page frags
+ *
+ * @header_len: size of linear part
+ * @data_len: needed length in frags
+ * @max_page_order: max page order desired.
+ * @errcode: pointer to error code if any
+ * @gfp_mask: allocation mask
+ *
+ * This can be used to allocate a paged skb, given a maximal order for frags.
+ */
+static inline struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
+ unsigned long data_len,
+ int max_page_order,
+ int *errcode,
+ gfp_t gfp_mask)
+{
+ struct sk_buff *skb;
+
+ skb = alloc_skb(header_len, gfp_mask);
+ if (unlikely(!skb)) {
+ *errcode = -ENOBUFS;
+ return NULL;
+ }
+
+ if (!data_len)
+ return skb;
+ return alloc_skb_frags(skb, data_len, max_page_order, errcode, gfp_mask);
+}
+
struct sk_buff *alloc_skb_for_msg(struct sk_buff *first);
/* Layout of fast clones : [skb1][skb2][fclone_ref] */
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index a9b8ac38dc1a..7811dde22f26 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5922,40 +5922,32 @@ int skb_mpls_dec_ttl(struct sk_buff *skb)
EXPORT_SYMBOL_GPL(skb_mpls_dec_ttl);
/**
- * alloc_skb_with_frags - allocate skb with page frags
+ * alloc_skb_frags - allocate page frags for skb
*
- * @header_len: size of linear part
+ * @skb: buffer
* @data_len: needed length in frags
* @max_page_order: max page order desired.
* @errcode: pointer to error code if any
* @gfp_mask: allocation mask
*
- * This can be used to allocate a paged skb, given a maximal order for frags.
+ * This can be used to allocate pages for skb, given a maximal order for frags.
*/
-struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
- unsigned long data_len,
- int max_page_order,
- int *errcode,
- gfp_t gfp_mask)
+struct sk_buff *alloc_skb_frags(struct sk_buff *skb,
+ unsigned long data_len,
+ int max_page_order,
+ int *errcode,
+ gfp_t gfp_mask)
{
int npages = (data_len + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
unsigned long chunk;
- struct sk_buff *skb;
struct page *page;
int i;
- *errcode = -EMSGSIZE;
/* Note this test could be relaxed, if we succeed to allocate
* high order pages...
*/
- if (npages > MAX_SKB_FRAGS)
- return NULL;
-
- *errcode = -ENOBUFS;
- skb = alloc_skb(header_len, gfp_mask);
- if (!skb)
- return NULL;
-
+ if (unlikely(npages > MAX_SKB_FRAGS))
+ goto failure;
skb->truesize += npages << PAGE_SHIFT;
for (i = 0; npages > 0; i++) {
@@ -5989,9 +5981,10 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
failure:
kfree_skb(skb);
+ *errcode = -EMSGSIZE;
return NULL;
}
-EXPORT_SYMBOL(alloc_skb_with_frags);
+EXPORT_SYMBOL(alloc_skb_frags);
/* carve out the first off bytes from skb when off < headlen */
static int pskb_carve_inside_header(struct sk_buff *skb, const u32 off,
--
2.34.1
next prev parent reply other threads:[~2022-01-11 1:25 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-11 1:21 [PATCH 00/14] udp optimisation Pavel Begunkov
2022-01-11 1:21 ` [PATCH 01/14] ipv6: optimise dst referencing Pavel Begunkov
2022-01-11 1:21 ` [PATCH 02/14] ipv6: shuffle up->pending AF_INET bits Pavel Begunkov
2022-01-11 1:21 ` [PATCH 03/14] ipv6: remove daddr temp buffer in __ip6_make_skb Pavel Begunkov
2022-01-11 1:21 ` [PATCH 04/14] ipv6: clean up cork setup/release Pavel Begunkov
2022-01-11 1:21 ` [PATCH 05/14] ipv6: don't zero cork's flowi after use Pavel Begunkov
2022-01-11 1:21 ` [PATCH 06/14] ipv6: pass full cork into __ip6_append_data() Pavel Begunkov
2022-01-11 1:21 ` [PATCH 07/14] ipv6: pass flow in ip6_make_skb together with cork Pavel Begunkov
2022-01-11 1:21 ` [PATCH 08/14] ipv6/udp: don't make extra copies of iflow Pavel Begunkov
2022-01-11 1:21 ` [PATCH 09/14] ipv6: hand dst refs to cork setup Pavel Begunkov
2022-01-11 15:39 ` Willem de Bruijn
2022-01-11 15:57 ` Pavel Begunkov
2022-01-11 17:11 ` Paolo Abeni
2022-01-11 20:39 ` Pavel Begunkov
2022-01-12 11:15 ` Paolo Abeni
2022-01-12 16:49 ` Pavel Begunkov
2022-01-11 1:21 ` [PATCH 10/14] skbuff: drop zero check from skb_zcopy_set Pavel Begunkov
2022-01-11 1:21 ` [PATCH 11/14] skbuff: drop null check from skb_zcopy Pavel Begunkov
2022-01-11 1:21 ` Pavel Begunkov [this message]
2022-01-11 1:21 ` [PATCH 13/14] net: inline part of skb_csum_hwoffload_help Pavel Begunkov
2022-01-11 9:24 ` David Laight
2022-01-11 16:59 ` Pavel Begunkov
2022-01-11 17:25 ` David Laight
2022-01-11 20:48 ` Pavel Begunkov
2022-01-12 2:41 ` David Laight
2022-01-12 16:43 ` Pavel Begunkov
2022-01-11 1:21 ` [PATCH 14/14] net: inline sock_alloc_send_skb Pavel Begunkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d98094be1435d5d8a98e0f7af26f175b64259d86.1641863490.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yoshfuji@linux-ipv6.org \
--subject='Re: [PATCH 12/14] skbuff: optimise alloc_skb_with_frags()' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).