All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liang Chen <liangchen.linux@gmail.com>
To: hawk@kernel.org, horms@kernel.org, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	linyunsheng@huawei.com
Cc: ilias.apalodimas@linaro.org, daniel@iogearbox.net,
	ast@kernel.org, netdev@vger.kernel.org,
	liangchen.linux@gmail.com
Subject: [RFC PATCH net-next v3 2/2] net: veth: Optimizing skb reuse in NAPI Context
Date: Wed, 16 Aug 2023 20:30:29 +0800	[thread overview]
Message-ID: <20230816123029.20339-3-liangchen.linux@gmail.com> (raw)
In-Reply-To: <20230816123029.20339-1-liangchen.linux@gmail.com>

In cases where the skb is reallocated by veth_convert_skb_to_xdp_buff,
we leverage the NAPI version of the "head stolen" function to enable
fast skb reuse. The following test results evaluate the performance
improvement resulting from reusing skb in the NAPI context with
pktgen-generated traffic.

Test environment setup:
ns1                 ns2
veth0   <-peer->    veth1
veth2   <-peer->    veth3

Test Results:
pktgen -> veth1 -> veth0(XDP_TX) -> veth1(XDP_DROP)
    without reusing skb: 2,033,439
    reusing skb: 2,167,749
    improvement: ~6%

pktgen -> veth1 -> veth0(XDP_TX) -> veth1(XDP_PASS)
    without reusing skb: 1,585,462
    reusing skb: 1,650,572
    improvement: ~4%

pktgen -> veth1 -> veth0(XDP_REDIRECT) -> veth2 -> veth3(XDP_DROP)
    without reusing skb: 1,787,342
    reusing skb: 1,848,516
    improvement: ~3%

pktgen -> veth1 -> veth0(XDP_REDIRECT) -> veth2 -> veth3(XDP_PASS)
    without reusing skb: 1,391,587
    reusing skb: 1,439,866
    improvement: ~3%

pktgen -> veth1 -> veth0(AF_XDP) -> user space(DROP)
    without reusing skb: 1,811,844
    with reusing skb: 1,861,027
    improvement: ~3%

Signed-off-by: Liang Chen <liangchen.linux@gmail.com>
---
 drivers/net/veth.c | 5 ++++-
 net/core/skbuff.c  | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 7234eb0297dd..4e1ee110ab84 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -838,9 +838,12 @@ static void __skb2xdp_steal_data(struct sk_buff *skb,
 	if (local_pp_alloc) {
 		/* This is the most common case where the skb was reallocated locally in
 		 * veth_convert_skb_to_xdp_buff, and it's safe to use the xdp_mem_pp model.
+		 * Since the skb is "reallocated" in the NAPI context of veth, it is possible
+		 * to use the NAPI version of the "head stolen" function to optimize the
+		 * reuse of skb as well.
 		 */
 		xdp->rxq->mem = rq->xdp_mem_pp;
-		kfree_skb_partial(skb, true);
+		napi_skb_free_stolen_head(skb);
 	} else if (!skb->pp_recycle) {
 		/* We can safely use kfree_skb_partial here because this cannot be an fclone
 		 * skb. Fclone skbs are allocated via __alloc_skb, with their head buffer
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index a298992060e6..954ba1b94840 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1284,6 +1284,7 @@ void napi_skb_free_stolen_head(struct sk_buff *skb)
 	}
 	napi_skb_cache_put(skb);
 }
+EXPORT_SYMBOL(napi_skb_free_stolen_head);
 
 void napi_consume_skb(struct sk_buff *skb, int budget)
 {
-- 
2.40.1


  parent reply	other threads:[~2023-08-16 12:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16 12:30 [RFC PATCH net-next v3 0/2] net: veth: Optimizing page pool usage Liang Chen
2023-08-16 12:30 ` [RFC PATCH net-next v3 1/2] net: veth: Improving page pool recycling Liang Chen
2023-08-16 12:30 ` Liang Chen [this message]
2023-08-21 14:21 ` [RFC PATCH net-next v3 0/2] net: veth: Optimizing page pool usage Jesper Dangaard Brouer
2023-08-21 21:54   ` Jesper Dangaard Brouer
2023-08-22 12:24     ` Yunsheng Lin
2023-08-22 13:05       ` Jesper Dangaard Brouer
2023-08-22 18:13         ` Jesper Dangaard Brouer

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=20230816123029.20339-3-liangchen.linux@gmail.com \
    --to=liangchen.linux@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linyunsheng@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.