public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: io-uring@vger.kernel.org
Cc: asml.silence@gmail.com, David Wei <dw@davidwei.uk>
Subject: [PATCH 6/8] io_uring/zcrx: add infra for large pages
Date: Tue, 17 Jun 2025 15:48:24 +0100	[thread overview]
Message-ID: <34e8280b870599c1cfa0e084b8b64578dec34de2.1750171297.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1750171297.git.asml.silence@gmail.com>

Currently, zcrx assumes PAGE_SIZE pages, add infrastructure to support
uniformly sized higher order pages. sg_table hides most of the details
and the only place that need index recalculation is the copy fallback.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 io_uring/zcrx.c | 13 ++++++++-----
 io_uring/zcrx.h |  1 +
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/io_uring/zcrx.c b/io_uring/zcrx.c
index a83b80c16491..44b5f8084279 100644
--- a/io_uring/zcrx.c
+++ b/io_uring/zcrx.c
@@ -44,13 +44,14 @@ static inline struct folio *io_niov_folio(const struct net_iov *niov,
 					  unsigned long *off)
 {
 	struct io_zcrx_area *area = io_zcrx_iov_to_area(niov);
-	struct page *page;
+	unsigned long niov_off, folio_idx;
 
 	lockdep_assert(!area->mem.is_dmabuf);
 
-	page = area->mem.pages[net_iov_idx(niov)];
-	*off = (page - compound_head(page)) << PAGE_SHIFT;
-	return page_folio(page);
+	niov_off = net_iov_idx(niov) << PAGE_SHIFT;
+	folio_idx = niov_off >> area->mem.folio_shift;
+	*off = niov_off - (folio_idx << area->mem.folio_shift);
+	return page_folio(area->mem.pages[folio_idx]);
 }
 
 static int io_populate_area_dma(struct io_zcrx_ifq *ifq,
@@ -164,6 +165,7 @@ static int io_import_umem(struct io_zcrx_ifq *ifq,
 			  struct io_zcrx_mem *mem,
 			  struct io_uring_zcrx_area_reg *area_reg)
 {
+	unsigned folio_shift = PAGE_SHIFT;
 	struct scatterlist *sgl;
 	struct page **pages;
 	int nr_pages, ret;
@@ -182,11 +184,12 @@ static int io_import_umem(struct io_zcrx_ifq *ifq,
 	if (ret)
 		return ret;
 	for_each_sg(mem->page_sg_table.sgl, sgl, nr_pages, i)
-		sg_set_page(sgl, pages[i], PAGE_SIZE, 0);
+		sg_set_page(sgl, pages[i], 1U << folio_shift, 0);
 
 	mem->pages = pages;
 	mem->nr_folios = nr_pages;
 	mem->size = area_reg->len;
+	mem->folio_shift = folio_shift;
 	return 0;
 }
 
diff --git a/io_uring/zcrx.h b/io_uring/zcrx.h
index 89015b923911..4f718b3088d9 100644
--- a/io_uring/zcrx.h
+++ b/io_uring/zcrx.h
@@ -14,6 +14,7 @@ struct io_zcrx_mem {
 
 	struct page			**pages;
 	unsigned long			nr_folios;
+	unsigned			folio_shift;
 	struct sg_table			page_sg_table;
 
 	struct dma_buf_attachment	*attach;
-- 
2.49.0


  parent reply	other threads:[~2025-06-17 14:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17 14:48 [PATCH 0/8] zcrx huge pages support Vol 1 Pavel Begunkov
2025-06-17 14:48 ` [PATCH 1/8] io_uring/zcrx: return error from io_zcrx_map_area_* Pavel Begunkov
2025-06-17 14:48 ` [PATCH 2/8] io_uring/zcrx: introduce io_populate_area_dma Pavel Begunkov
2025-06-17 14:48 ` [PATCH 3/8] io_uring/zcrx: allocate sgtable for umem areas Pavel Begunkov
2025-06-17 14:48 ` [PATCH 4/8] io_uring/zcrx: assert area type in io_zcrx_iov_page Pavel Begunkov
2025-06-17 14:48 ` [PATCH 5/8] io_uring/zcrx: convert io_zcrx_iov_page to use folios Pavel Begunkov
2025-06-17 14:48 ` Pavel Begunkov [this message]
2025-06-17 14:48 ` [PATCH 7/8] io_uring: export io_coalesce_buffer() Pavel Begunkov
2025-06-17 14:48 ` [PATCH 8/8] io_uring/zcrx: try to coalesce area pages Pavel Begunkov
2025-06-30 17:12 ` [PATCH 0/8] zcrx huge pages support Vol 1 Pavel Begunkov
2025-06-30 17:31   ` Jens Axboe
2025-06-30 17:44     ` 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=34e8280b870599c1cfa0e084b8b64578dec34de2.1750171297.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=dw@davidwei.uk \
    --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