From: Jaco Kroon <jaco@uls.co.za>
To: bernd.schubert@fastmail.fm, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, christophe.jaillet@wanadoo.fr,
joannelkoong@gmail.com
Cc: miklos@szeredi.hu, rdunlap@infradead.org, trapexit@spawn.link,
david.laight.linux@gmail.com, Jaco Kroon <jaco@uls.co.za>
Subject: [PATCH 2/2] fuse: Adjust readdir() buffer to requesting buffer size.
Date: Tue, 1 Apr 2025 16:18:17 +0200 [thread overview]
Message-ID: <20250401142831.25699-3-jaco@uls.co.za> (raw)
In-Reply-To: <20250401142831.25699-1-jaco@uls.co.za>
Clamp to min 1 page (4KB) and max 128 pages (512KB).
Glusterfs trial using strace ls -l.
Before:
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 600
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 616
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 624
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 600
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 600
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 624
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 600
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 600
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 600
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 600
getdents64(3, 0x7f2d7d7a7040 /* 25 entries */, 131072) = 608
getdents64(3, 0x7f2d7d7a7040 /* 1 entries */, 131072) = 24
getdents64(3, 0x7f2d7d7a7040 /* 0 entries */, 131072) = 0
After:
getdents64(3, 0x7ffae8eed040 /* 276 entries */, 131072) = 6696
getdents64(3, 0x7ffae8eed040 /* 0 entries */, 131072) = 0
Signed-off-by: Jaco Kroon <jaco@uls.co.za>
---
fs/fuse/readdir.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
index 17ce9636a2b1..a13534f411b4 100644
--- a/fs/fuse/readdir.c
+++ b/fs/fuse/readdir.c
@@ -12,6 +12,7 @@
#include <linux/posix_acl.h>
#include <linux/pagemap.h>
#include <linux/highmem.h>
+#include <linux/minmax.h>
static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ctx)
{
@@ -337,11 +338,21 @@ static int fuse_readdir_uncached(struct file *file, struct dir_context *ctx)
struct fuse_mount *fm = get_fuse_mount(inode);
struct fuse_io_args ia = {};
struct fuse_args_pages *ap = &ia.ap;
- struct fuse_folio_desc desc = { .length = PAGE_SIZE };
+ struct fuse_folio_desc desc = { .length = ctx->count };
u64 attr_version = 0, evict_ctr = 0;
bool locked;
+ int order;
- folio = folio_alloc(GFP_KERNEL, 0);
+ desc.length = clamp(desc.length, PAGE_SIZE, fm->fc->max_pages << PAGE_SHIFT);
+ order = get_count_order(desc.length >> CONFIG_PAGE_SHIFT);
+
+ do {
+ folio = folio_alloc(GFP_KERNEL, order);
+ if (folio)
+ break;
+ --order;
+ desc.length = PAGE_SIZE << order;
+ } while (order >= 0);
if (!folio)
return -ENOMEM;
@@ -353,10 +364,10 @@ static int fuse_readdir_uncached(struct file *file, struct dir_context *ctx)
if (plus) {
attr_version = fuse_get_attr_version(fm->fc);
evict_ctr = fuse_get_evict_ctr(fm->fc);
- fuse_read_args_fill(&ia, file, ctx->pos, PAGE_SIZE,
+ fuse_read_args_fill(&ia, file, ctx->pos, desc.length,
FUSE_READDIRPLUS);
} else {
- fuse_read_args_fill(&ia, file, ctx->pos, PAGE_SIZE,
+ fuse_read_args_fill(&ia, file, ctx->pos, desc.length,
FUSE_READDIR);
}
locked = fuse_lock_inode(inode);
--
2.48.1
next prev parent reply other threads:[~2025-04-01 14:29 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-26 10:59 [PATCH] fuse: enable larger read buffers for readdir Jaco Kroon
2023-07-26 11:43 ` Jaco Kroon
2023-07-26 13:53 ` Bernd Schubert
2023-07-26 15:26 ` Jaco Kroon
2023-07-26 15:30 ` Bernd Schubert
2023-07-26 15:45 ` Bernd Schubert
2023-07-26 17:23 ` Antonio SJ Musumeci
2023-07-26 18:25 ` Jaco Kroon
2023-07-27 15:21 ` Miklos Szeredi
2023-07-27 19:21 ` Miklos Szeredi
2023-07-27 19:43 ` Bernd Schubert
2023-07-28 8:42 ` Miklos Szeredi
2023-07-26 15:19 ` Randy Dunlap
2023-07-27 8:12 ` [PATCH] fuse: enable larger read buffers for readdir [v2] Jaco Kroon
2023-07-27 15:35 ` Miklos Szeredi
2023-07-27 16:58 ` Jaco Kroon
2023-07-27 19:17 ` Miklos Szeredi
2023-07-27 19:16 ` Bernd Schubert
2023-07-27 20:35 ` Bernd Schubert
2023-07-28 5:05 ` Jaco Kroon
2025-03-14 22:16 ` fuse: increase readdir() buffer size Jaco Kroon
2025-03-14 22:16 ` [PATCH 1/2] fs: Supply dir_context.count as readdir buffer size hint Jaco Kroon
2025-03-29 9:20 ` Christophe JAILLET
2025-03-30 14:27 ` Jaco Kroon
2025-03-14 22:16 ` [PATCH 2/2] fuse: Adjust readdir() buffer to requesting buffer size Jaco Kroon
2025-03-31 16:41 ` Joanne Koong
2025-03-31 20:43 ` Jaco Kroon
2025-03-31 21:48 ` Joanne Koong
2025-03-31 23:01 ` Joanne Koong
2025-03-28 10:15 ` fuse: increase readdir() " Jaco Kroon
2025-03-28 10:16 ` Bernd Schubert
2025-03-28 19:40 ` David Laight
2025-03-29 8:59 ` Jaco Kroon
2025-04-01 14:18 ` fuse: increase readdir() buffer size [v4] Jaco Kroon
2025-04-01 14:18 ` [PATCH 1/2] fs: Supply dir_context.count as readdir buffer size hint Jaco Kroon
2025-04-01 14:18 ` Jaco Kroon [this message]
2025-04-01 14:40 ` [PATCH 2/2] fuse: Adjust readdir() buffer to requesting buffer size Miklos Szeredi
2025-04-01 15:03 ` Jaco Kroon
2025-04-01 15:33 ` Miklos Szeredi
2025-04-02 7:54 ` Jaco Kroon
2025-04-02 8:18 ` Miklos Szeredi
2025-04-02 8:52 ` Jaco Kroon
2025-04-02 9:10 ` Bernd Schubert
2025-04-02 11:13 ` Jaco Kroon
2025-04-02 11:35 ` Miklos Szeredi
2025-04-02 11:59 ` Bernd Schubert
2025-04-08 14:19 ` Bernd Schubert
2025-04-09 7:12 ` Jaco Kroon
2025-04-09 8:31 ` Bernd Schubert
2025-04-09 15:03 ` Jaco Kroon
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=20250401142831.25699-3-jaco@uls.co.za \
--to=jaco@uls.co.za \
--cc=bernd.schubert@fastmail.fm \
--cc=christophe.jaillet@wanadoo.fr \
--cc=david.laight.linux@gmail.com \
--cc=joannelkoong@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=rdunlap@infradead.org \
--cc=trapexit@spawn.link \
/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®