mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jim Harris <jim.harris@nvidia.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: <linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Joanne Koong" <joannelkoong@gmail.com>,
	Konrad Sztyber <ksztyber@nvidia.com>,
	"Max Gurtovoy" <mgurtovoy@nvidia.com>,
	Idan Zach <izach@nvidia.com>
Subject: [PATCH v2] fuse: allow larger read requests by setting bdi->io_pages
Date: Mon, 22 Jun 2026 17:42:27 -0700	[thread overview]
Message-ID: <20260623004227.77628-1-jim.harris@nvidia.com> (raw)

A FUSE server that advertises a large max_pages and max_write (e.g.
max_pages=256, max_write=1MB) cannot currently obtain matching
FUSE_READ request sizes from the kernel.  Buffered sequential writes
arrive at the server at the negotiated max_write size, but a large
buffered read() is split into several smaller FUSE_READ requests.

For a buffered read, filemap_get_pages() -> page_cache_sync_ra() sizes
the read against ractl_max_pages():

	max_pages = ractl->ra->ra_pages;
	if (req_size > max_pages && bdi->io_pages > max_pages)
		max_pages = min(req_size, bdi->io_pages);

fuse leaves bdi->io_pages at the default VM_READAHEAD_PAGES (128KB), so
a 1MB read() (req_size = 256 pages) is clamped to the readahead window
(128KB, or 256KB for POSIX_FADV_SEQUENTIAL), producing four 256KB
FUSE_READ round-trips instead of one.

Set bdi->io_pages to fc->max_pages after feature negotiation.  As the
code above shows, io_pages only raises the limit when the request size
already exceeds the readahead window, so it enlarges explicitly
requested reads without enlarging the speculative readahead window.
This avoids increasing speculative page-cache readahead on behalf of
an unprivileged server.  NFS does the same, setting io_pages from
rpages while leaving ra_pages at the default.

fc->max_pages is already bounded by fc->max_pages_limit (and, for
virtio-fs, by the virtqueue descriptor count), so io_pages inherits
the same bound.

Suggested-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Jim Harris <jim.harris@nvidia.com>
Assisted-by: Cursor:claude-opus-4.8
---
Changes since v1 [1]:
 - Set bdi->io_pages instead of bdi->ra_pages, per Joanne's review.
   Raising ra_pages would also enlarge the speculative readahead
   window for all workloads (including small sequential reads),
   increasing page-cache readahead on behalf of the server.  Setting
   io_pages enlarges only explicitly requested reads larger than the
   readahead window, leaving speculative readahead unchanged.

[1] https://lore.kernel.org/linux-fsdevel/20260602204430.18427-1-jim.harris@nvidia.com/

Notes on AI assistance:

  The mm/readahead analysis (confirming ractl_max_pages() consults
  io_pages only when the request exceeds the readahead window) and the
  bulk of this changelog were drafted with an AI coding assistant (see
  Assisted-by trailer).  The one-line code change was reviewed by me.
  The motivating performance observation was made by me on a real
  virtio-fs workload, and verification was performed by me.

 fs/fuse/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index deddfffb037f..c8373e537d2b 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1495,6 +1495,7 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args,
 
 		fm->sb->s_bdi->ra_pages =
 				min(fm->sb->s_bdi->ra_pages, ra_pages);
+		fm->sb->s_bdi->io_pages = fc->max_pages;
 		fc->minor = arg->minor;
 		fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
 		fc->max_write = max_t(unsigned, 4096, fc->max_write);
-- 
2.43.0


             reply	other threads:[~2026-06-23  0:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23  0:42 Jim Harris [this message]
2026-06-23 17:48 ` Joanne Koong
2026-07-17 12:54 ` Miklos Szeredi

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=20260623004227.77628-1-jim.harris@nvidia.com \
    --to=jim.harris@nvidia.com \
    --cc=izach@nvidia.com \
    --cc=joannelkoong@gmail.com \
    --cc=ksztyber@nvidia.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgurtovoy@nvidia.com \
    --cc=miklos@szeredi.hu \
    /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

all inboxes | Powered by JetHome®