From: Pavel Begunkov <asml.silence@gmail.com>
To: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org
Cc: io-uring@vger.kernel.org, asml.silence@gmail.com
Subject: [RFC 9/9] io_uring/zcrx: add rq_lock cache of "user" niov refs
Date: Sat, 11 Jul 2026 10:22:19 +0100 [thread overview]
Message-ID: <a866ed180eb5b7512b7fba0d4d6f431fcacee650.1783619193.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1783619193.git.asml.silence@gmail.com>
Now the "user" refs are acquired and released by NAPI/page pool for the
optimised path, cache them on the NAPI side and protect it by rq.lock.
Store it in net_iov as we'd be touching the cache line by refilling soon
anyway.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/zcrx.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 23669471a8f0..04a80d1a2b3a 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -393,9 +393,20 @@ static inline atomic_t *io_get_user_counter(struct net_iov *niov)
static bool io_zcrx_put_niov_uref(struct net_iov *niov, unsigned refs)
{
- atomic_t *uref = io_get_user_counter(niov);
+ unsigned *cached_ref = &niov->mp_private;
+ atomic_t *uref;
int old;
+ lockdep_assert_held(&io_zcrx_iov_to_area(niov)->ifq->rq.lock);
+
+ if (likely(*cached_ref >= refs)) {
+ *cached_ref -= refs;
+ return true;
+ }
+ refs -= *cached_ref;
+ *cached_ref = 0;
+
+ uref = io_get_user_counter(niov);
old = atomic_read(uref);
do {
if (unlikely(old < refs))
@@ -744,6 +755,16 @@ static void io_zcrx_scrub_area(struct io_zcrx_ifq *ifq, struct io_zcrx_area *are
{
int i;
+ scoped_guard(spinlock_bh, &ifq->rq.lock) {
+ for (i = 0; i < area->nia.num_niovs; i++) {
+ struct net_iov *niov = &area->nia.niovs[i];
+ unsigned *ref = &niov->mp_private;
+
+ atomic_add(*ref, &area->user_refs[i]);
+ *ref = 0;
+ }
+ }
+
/* Reclaim back all buffers given to the user space. */
for (i = 0; i < area->nia.num_niovs; i++) {
struct net_iov *niov = &area->nia.niovs[i];
@@ -1327,9 +1348,9 @@ static void zcrx_release_skbs(struct io_zcrx_ifq *ifq)
for (i = 0; i < shi->nr_frags; i++) {
const skb_frag_t *frag = &shi->frags[i];
struct net_iov *niov = netmem_to_net_iov(frag->netmem);
+ unsigned *ref = &niov->mp_private;
- /* Take niov references the skb holds */
- io_zcrx_get_niov_uref(niov);
+ *ref += 1;
}
shi->nr_frags = 0;
--
2.54.0
prev parent reply other threads:[~2026-07-11 9:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-11 9:22 [RFC 0/9] optimise zcrx refs cache bouncing Pavel Begunkov
2026-07-11 9:22 ` [RFC 1/9] net: allow __tcp_read_sock actors to steal skbs Pavel Begunkov
2026-07-11 9:22 ` [RFC 2/9] net: add provider specific net_iov field Pavel Begunkov
2026-07-11 9:22 ` [RFC 3/9] io_uring/zcrx: don't save/restore count for frag skbs Pavel Begunkov
2026-07-11 9:22 ` [RFC 4/9] io_uring/zcrx: split frag handling loop Pavel Begunkov
2026-07-11 9:22 ` [RFC 5/9] io_uring/zcrx: split io_zcrx_recv_frag() Pavel Begunkov
2026-07-11 9:22 ` [RFC 6/9] io_uring/zcrx: implement skb stealing Pavel Begunkov
2026-07-11 9:22 ` [RFC 7/9] io_uring/zcrx: don't lock for single producer ptr ring Pavel Begunkov
2026-07-11 9:22 ` [RFC 8/9] io_uring/zcrx: steal niov refs Pavel Begunkov
2026-07-11 9:22 ` Pavel Begunkov [this message]
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=a866ed180eb5b7512b7fba0d4d6f431fcacee650.1783619193.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=kuba@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox