From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com
Subject: [zcrx-next 7/8] io_uring/zcrx: make niov size variable
Date: Sun, 17 Aug 2025 23:44:18 +0100 [thread overview]
Message-ID: <08c3405810ebacbb8cbf59e3c0a1dfa6eb415f5f.1755467608.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1755467608.git.asml.silence@gmail.com>
Instead of using PAGE_SIZE for the niov size add a niov_shift field to
ifq, and patch up all important places. Copy fallback still assumes
PAGE_SIZE, so it'll be wasting some memory for now.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
io_uring/zcrx.c | 32 +++++++++++++++++++++-----------
io_uring/zcrx.h | 1 +
2 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index 87ba34c5a22f..952cd7669589 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -45,16 +45,19 @@ static inline struct io_zcrx_area *io_zcrx_iov_to_area(const struct net_iov *nio
static inline struct page *io_zcrx_iov_page(const struct net_iov *niov)
{
struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);
+ unsigned niov_pages_shift;
lockdep_assert(!area->mem.is_dmabuf);
- return area->mem.pages[net_iov_idx(niov)];
+ niov_pages_shift = area->ifq->niov_shift - PAGE_SHIFT;
+ return area->mem.pages[net_iov_idx(niov) << niov_pages_shift];
}
static int io_populate_area_dma(struct io_zcrx_ifq *ifq,
struct io_zcrx_area *area,
struct sg_table *sgt)
{
+ unsigned niov_size = 1U << ifq->niov_shift;
struct scatterlist *sg;
unsigned i, niov_idx = 0;
@@ -62,13 +65,16 @@ static int io_populate_area_dma(struct io_zcrx_ifq *ifq,
dma_addr_t dma = sg_dma_address(sg);
unsigned long sg_len = sg_dma_len(sg);
+ if (WARN_ON_ONCE(sg_len % niov_size))
+ return -EINVAL;
+
while (sg_len && niov_idx < area->nia.num_niovs) {
struct net_iov *niov = &area->nia.niovs[niov_idx];
if (net_mp_niov_set_dma_addr(niov, dma))
return -EFAULT;
- sg_len -= PAGE_SIZE;
- dma += PAGE_SIZE;
+ sg_len -= niov_size;
+ dma += niov_size;
niov_idx++;
}
}
@@ -396,7 +402,8 @@ static int io_zcrx_create_area(struct io_zcrx_ifq *ifq,
if (ret)
goto err;
- nr_iovs = area->mem.size >> PAGE_SHIFT;
+ ifq->niov_shift = PAGE_SHIFT;
+ nr_iovs = area->mem.size >> ifq->niov_shift;
area->nia.num_niovs = nr_iovs;
ret = -ENOMEM;
@@ -742,7 +749,7 @@ static void io_zcrx_ring_refill(struct page_pool *pp,
netmem_ref netmem;
area_idx = rqe->off >> IORING_ZCRX_AREA_SHIFT;
- niov_idx = (rqe->off & ~IORING_ZCRX_AREA_MASK) >> PAGE_SHIFT;
+ niov_idx = (rqe->off & ~IORING_ZCRX_AREA_MASK) >> ifq->niov_shift;
if (unlikely(rqe->__pad || area_idx))
continue;
@@ -785,20 +792,23 @@ static void io_zcrx_refill_slow(struct page_pool *pp, struct io_zcrx_ifq *ifq)
spin_unlock_bh(&area->freelist_lock);
}
-static void io_sync_allocated_niovs(struct page_pool *pp)
+static void io_sync_allocated_niovs(struct io_zcrx_ifq *ifq,
+ struct page_pool *pp)
{
#if defined(CONFIG_HAS_DMA) && defined(CONFIG_DMA_NEED_SYNC)
+ unsigned niov_size;
int i;
if (!dma_dev_need_sync(pp->p.dev))
return;
+ niov_size = 1U << ifq->niov_shift;
for (i = 0; i < pp->alloc.count; i++) {
netmem_ref netmem = pp->alloc.cache[i];
dma_addr_t dma_addr = page_pool_get_dma_addr_netmem(netmem);
__dma_sync_single_for_device(pp->p.dev, dma_addr + pp->p.offset,
- PAGE_SIZE, pp->p.dma_dir);
+ niov_size, pp->p.dma_dir);
}
#endif
}
@@ -819,7 +829,7 @@ static netmem_ref io_pp_zc_alloc_netmems(struct page_pool *pp, gfp_t gfp)
if (!pp->alloc.count)
return 0;
out_return:
- io_sync_allocated_niovs(pp);
+ io_sync_allocated_niovs(ifq, pp);
return pp->alloc.cache[--pp->alloc.count];
}
@@ -847,8 +857,8 @@ static int io_pp_zc_init(struct page_pool *pp)
return -EINVAL;
if (WARN_ON_ONCE(!pp->dma_map))
return -EOPNOTSUPP;
- if (pp->p.order != 0)
- return -EOPNOTSUPP;
+ if (pp->p.order + PAGE_SHIFT != ifq->niov_shift)
+ return -EINVAL;
if (pp->p.dma_dir != DMA_FROM_DEVICE)
return -EOPNOTSUPP;
@@ -920,7 +930,7 @@ static bool io_zcrx_queue_cqe(struct io_kiocb *req, struct net_iov *niov,
cqe->flags = IORING_CQE_F_MORE;
area = io_zcrx_iov_to_area(niov);
- offset = off + (net_iov_idx(niov) << PAGE_SHIFT);
+ offset = off + (net_iov_idx(niov) << ifq->niov_shift);
rcqe = (struct io_uring_zcrx_cqe *)(cqe + 1);
rcqe->off = offset + ((u64)area->area_id << IORING_ZCRX_AREA_SHIFT);
rcqe->__pad = 0;
diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h
index 4e94cfa720e6..41e4ceab8dd6 100644
--- a/io_uring/zcrx.h
+++ b/io_uring/zcrx.h
@@ -41,6 +41,7 @@ struct io_zcrx_area {
struct io_zcrx_ifq {
struct io_ring_ctx *ctx;
struct io_zcrx_area *area;
+ unsigned niov_shift;
spinlock_t rq_lock ____cacheline_aligned_in_smp;
struct io_uring *rq_ring;
--
2.49.0
next prev parent reply other threads:[~2025-08-17 22:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-17 22:44 [zcrx-next 0/8] niov sizing and area mapping improvement Pavel Begunkov
2025-08-17 22:44 ` [zcrx-next 1/8] io_uring/zcrx: don't pass slot to io_zcrx_create_area Pavel Begunkov
2025-08-17 22:44 ` [zcrx-next 2/8] io_uring/zcrx: move area reg checks into io_import_area Pavel Begunkov
2025-08-17 22:44 ` [zcrx-next 3/8] io_uring/zcrx: check all niovs filled with dma addresses Pavel Begunkov
2025-08-17 22:44 ` [zcrx-next 4/8] io_uring/zcrx: pass ifq to io_zcrx_alloc_fallback() Pavel Begunkov
2025-08-17 22:44 ` [zcrx-next 5/8] io_uring/zcrx: deduplicate area mapping Pavel Begunkov
2025-08-17 22:44 ` [zcrx-next 6/8] io_uring/zcrx: remove dmabuf_offset Pavel Begunkov
2025-08-17 22:44 ` Pavel Begunkov [this message]
2025-08-17 22:44 ` [zcrx-next 8/8] io_uring/zcrx: set sgt for umem area Pavel Begunkov
2025-08-20 18:20 ` [zcrx-next 0/8] niov sizing and area mapping improvement Jens Axboe
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=08c3405810ebacbb8cbf59e3c0a1dfa6eb415f5f.1755467608.git.asml.silence@gmail.com \
--to=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).