Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: J Louis Kaplan <Louis.Kaplan@arm.com>
To: cel@kernel.org, dai.ngo@oracle.com, jlayton@kernel.org,
	neil@brown.name, okorniev@redhat.com, tom@talpey.com
Cc: linux-nfs@vger.kernel.org, linux-rdma@vger.kernel.org,
	anna@kernel.org, jgg@ziepe.ca, leon@kernel.org,
	trondmy@kernel.org, J Louis Kaplan <Louis.Kaplan@arm.com>
Subject: [RFC PATCH 6/6] sunrpc: Allocate svc request pages from large folios
Date: Tue,  6 Oct 2026 10:00:28 +0100	[thread overview]
Message-ID: <20261006090028.3412544-7-Louis.Kaplan@arm.com> (raw)
In-Reply-To: <20261006090028.3412544-1-Louis.Kaplan@arm.com>

Bulk allocation of base pages does not guarantee physical
contiguity, limiting opportunities to coalesce service buffers.

Allocate large folios opportunistically and populate the service
page arrays with their constituent pages. Cap folio size at
64 KiB and allocation order at PAGE_ALLOC_COSTLY_ORDER, falling
back through smaller orders to bulk base-page allocation.

Retain one reference per populated page-array slot so existing
page-based ownership and release paths remain valid.

Signed-off-by: J Louis Kaplan <Louis.Kaplan@arm.com>
Assisted-by: LLM
---
 net/sunrpc/svc_xprt.c | 44 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index 9858dfcb846a8..90ec75a848da9 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -19,6 +19,7 @@
 #include <linux/sunrpc/bc_xprt.h>
 #include <linux/module.h>
 #include <linux/netdevice.h>
+#include <linux/sizes.h>
 #include <trace/events/sunrpc.h>
 
 #define RPCDBG_FACILITY	RPCDBG_SVCXPRT
@@ -708,20 +709,53 @@ static void svc_check_conn_limits(struct svc_serv *serv)
 static bool svc_fill_pages(struct svc_rqst *rqstp, struct page **pages,
 			   unsigned long npages)
 {
-	unsigned long filled, ret;
+	unsigned int order = min_t(unsigned int, PAGE_ALLOC_COSTLY_ORDER,
+				   get_order(SZ_64K));
+	unsigned long filled = 0;
 
-	for (filled = 0; filled < npages; filled = ret) {
-		ret = alloc_pages_bulk(GFP_KERNEL, npages, pages);
-		if (ret > filled)
+	/*
+	 * Prefer folios no larger than 64 KiB or the page allocator's
+	 * costly-order threshold. After a failure, use smaller orders for
+	 * the rest of this fill; order zero is handled by the bulk allocator.
+	 * All callers provide a range containing only NULL entries.
+	 */
+	while (filled < npages) {
+		struct folio *folio;
+		unsigned int nr_pages;
+		unsigned long ret;
+
+		while (order && (1UL << order) > npages - filled)
+			order--;
+
+		if (order) {
+			folio = folio_alloc(GFP_NOWAIT, order);
+			if (!folio) {
+				order--;
+				continue;
+			}
+
+			nr_pages = folio_nr_pages(folio);
+			folio_ref_add(folio, nr_pages - 1);
+			for (unsigned int i = 0; i < nr_pages; i++)
+				pages[filled + i] = folio_page(folio, i);
+			filled += nr_pages;
+			continue;
+		}
+
+		ret = alloc_pages_bulk(GFP_KERNEL, npages - filled,
+				       pages + filled);
+		if (ret) {
+			filled += ret;
 			/* Made progress, don't sleep yet */
 			continue;
+		}
 
 		set_current_state(TASK_IDLE);
 		if (svc_thread_should_stop(rqstp)) {
 			set_current_state(TASK_RUNNING);
 			return false;
 		}
-		trace_svc_alloc_arg_err(npages, ret);
+		trace_svc_alloc_arg_err(npages, filled);
 		memalloc_retry_wait(GFP_KERNEL);
 	}
 	return true;
-- 
2.43.0


  parent reply	other threads:[~2026-10-06  9:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06  9:00 [RFC PATCH 0/6] Improve NFS server direct throughput with passthrough enabled J Louis Kaplan
2026-10-06  9:00 ` [RFC PATCH 1/6] sunrpc: Add helpers to build bvecs from contiguous pages J Louis Kaplan
2026-10-06 13:49   ` Chuck Lever
2026-10-08 22:44     ` J Louis Kaplan
2026-10-06  9:00 ` [RFC PATCH 2/6] nfsd: Coalesce contiguous pages for direct reads J Louis Kaplan
2026-10-06  9:00 ` [RFC PATCH 3/6] svcrdma: Coalesce contiguous pages when mapping replies J Louis Kaplan
2026-10-06 13:55   ` Chuck Lever
2026-10-08 22:54     ` J Louis Kaplan
2026-10-06  9:00 ` [RFC PATCH 4/6] svcrdma: Coalesce contiguous pages in RDMA Write chunks J Louis Kaplan
2026-10-06  9:00 ` [RFC PATCH 5/6] svcrdma: Coalesce contiguous pages in RDMA Read chunks J Louis Kaplan
2026-10-06  9:00 ` J Louis Kaplan [this message]
2026-10-06 14:00   ` [RFC PATCH 6/6] sunrpc: Allocate svc request pages from large folios Chuck Lever
2026-10-08 22:58     ` J Louis Kaplan
2026-10-06 13:47 ` [RFC PATCH 0/6] Improve NFS server direct throughput with passthrough enabled Chuck Lever
2026-10-08 22:50   ` J Louis Kaplan

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=20261006090028.3412544-7-Louis.Kaplan@arm.com \
    --to=louis.kaplan@arm.com \
    --cc=anna@kernel.org \
    --cc=cel@kernel.org \
    --cc=dai.ngo@oracle.com \
    --cc=jgg@ziepe.ca \
    --cc=jlayton@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.com \
    --cc=trondmy@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