From nobody Sat Feb 7 23:11:08 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E184C0015E for ; Wed, 26 Jul 2023 11:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234076AbjGZLhV (ORCPT ); Wed, 26 Jul 2023 07:37:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234066AbjGZLhS (ORCPT ); Wed, 26 Jul 2023 07:37:18 -0400 X-Greylist: delayed 900 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 26 Jul 2023 04:37:16 PDT Received: from ida.iewc.co.za (ida.iewc.co.za [154.73.34.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768F51BF6 for ; Wed, 26 Jul 2023 04:37:16 -0700 (PDT) Received: from [154.73.32.4] (helo=plastiekpoot) by ida.iewc.co.za with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qOcFo-0007AC-D8; Wed, 26 Jul 2023 13:00:28 +0200 Received: from jkroon by plastiekpoot with local (Exim 4.96) (envelope-from ) id 1qOcFm-0000jk-0m; Wed, 26 Jul 2023 13:00:26 +0200 From: Jaco Kroon To: Miklos Szeredi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jaco Kroon Subject: [PATCH] fuse: enable larger read buffers for readdir. Date: Wed, 26 Jul 2023 12:59:37 +0200 Message-ID: <20230726105953.843-1-jaco@uls.co.za> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Jaco Kroon --- fs/fuse/Kconfig | 16 ++++++++++++++++ fs/fuse/readdir.c | 42 ++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig index 038ed0b9aaa5..0783f9ee5cd3 100644 --- a/fs/fuse/Kconfig +++ b/fs/fuse/Kconfig @@ -18,6 +18,22 @@ config FUSE_FS If you want to develop a userspace FS, or if you want to use a filesystem based on FUSE, answer Y or M. =20 +config FUSE_READDIR_ORDER + int + range 0 5 + default 5 + help + readdir performance varies greatly depending on the size of the read. + Larger buffers results in larger reads, thus fewer reads and higher + performance in return. + + You may want to reduce this value on seriously constrained memory + systems where 128KiB (assuming 4KiB pages) cache pages is not ideal. + + This value reprents the order of the number of pages to allocate (ie, + the shift value). A value of 0 is thus 1 page (4KiB) where 5 is 32 + pages (128KiB). + config CUSE tristate "Character device in Userspace support" depends on FUSE_FS diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c index dc603479b30e..98c62b623240 100644 --- a/fs/fuse/readdir.c +++ b/fs/fuse/readdir.c @@ -13,6 +13,12 @@ #include #include =20 +#define READDIR_PAGES_ORDER CONFIG_FUSE_READDIR_ORDER +#define READDIR_PAGES (1 << READDIR_PAGES_ORDER) +#define READDIR_PAGES_SIZE (PAGE_SIZE << READDIR_PAGES_ORDER) +#define READDIR_PAGES_MASK (READDIR_PAGES_SIZE - 1) +#define READDIR_PAGES_SHIFT (PAGE_SHIFT + READDIR_PAGES_ORDER) + static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ct= x) { struct fuse_conn *fc =3D get_fuse_conn(dir); @@ -52,10 +58,10 @@ static void fuse_add_dirent_to_cache(struct file *file, } version =3D fi->rdc.version; size =3D fi->rdc.size; - offset =3D size & ~PAGE_MASK; - index =3D size >> PAGE_SHIFT; + offset =3D size & ~READDIR_PAGES_MASK; + index =3D size >> READDIR_PAGES_SHIFT; /* Dirent doesn't fit in current page? Jump to next page. */ - if (offset + reclen > PAGE_SIZE) { + if (offset + reclen > READDIR_PAGES_SIZE) { index++; offset =3D 0; } @@ -83,7 +89,7 @@ static void fuse_add_dirent_to_cache(struct file *file, } memcpy(addr + offset, dirent, reclen); kunmap_local(addr); - fi->rdc.size =3D (index << PAGE_SHIFT) + offset + reclen; + fi->rdc.size =3D (index << READDIR_PAGES_SHIFT) + offset + reclen; fi->rdc.pos =3D dirent->off; unlock: spin_unlock(&fi->rdc.lock); @@ -104,7 +110,7 @@ static void fuse_readdir_cache_end(struct file *file, l= off_t pos) } =20 fi->rdc.cached =3D true; - end =3D ALIGN(fi->rdc.size, PAGE_SIZE); + end =3D ALIGN(fi->rdc.size, READDIR_PAGES_SIZE); spin_unlock(&fi->rdc.lock); =20 /* truncate unused tail of cache */ @@ -328,25 +334,25 @@ static int fuse_readdir_uncached(struct file *file, s= truct dir_context *ctx) struct fuse_mount *fm =3D get_fuse_mount(inode); struct fuse_io_args ia =3D {}; struct fuse_args_pages *ap =3D &ia.ap; - struct fuse_page_desc desc =3D { .length =3D PAGE_SIZE }; + struct fuse_page_desc desc =3D { .length =3D READDIR_PAGES_SIZE }; u64 attr_version =3D 0; bool locked; =20 - page =3D alloc_page(GFP_KERNEL); + page =3D alloc_pages(GFP_KERNEL, READDIR_PAGES_ORDER); if (!page) return -ENOMEM; =20 plus =3D fuse_use_readdirplus(inode, ctx); ap->args.out_pages =3D true; - ap->num_pages =3D 1; + ap->num_pages =3D READDIR_PAGES; ap->pages =3D &page; ap->descs =3D &desc; if (plus) { attr_version =3D fuse_get_attr_version(fm->fc); - fuse_read_args_fill(&ia, file, ctx->pos, PAGE_SIZE, + fuse_read_args_fill(&ia, file, ctx->pos, READDIR_PAGES_SIZE, FUSE_READDIRPLUS); } else { - fuse_read_args_fill(&ia, file, ctx->pos, PAGE_SIZE, + fuse_read_args_fill(&ia, file, ctx->pos, READDIR_PAGES_SIZE, FUSE_READDIR); } locked =3D fuse_lock_inode(inode); @@ -383,7 +389,7 @@ static enum fuse_parse_result fuse_parse_cache(struct f= use_file *ff, void *addr, unsigned int size, struct dir_context *ctx) { - unsigned int offset =3D ff->readdir.cache_off & ~PAGE_MASK; + unsigned int offset =3D ff->readdir.cache_off & ~READDIR_PAGES_MASK; enum fuse_parse_result res =3D FOUND_NONE; =20 WARN_ON(offset >=3D size); @@ -504,16 +510,16 @@ static int fuse_readdir_cached(struct file *file, str= uct dir_context *ctx) =20 WARN_ON(fi->rdc.size < ff->readdir.cache_off); =20 - index =3D ff->readdir.cache_off >> PAGE_SHIFT; + index =3D ff->readdir.cache_off >> READDIR_PAGES_SHIFT; =20 - if (index =3D=3D (fi->rdc.size >> PAGE_SHIFT)) - size =3D fi->rdc.size & ~PAGE_MASK; + if (index =3D=3D (fi->rdc.size >> READDIR_PAGES_SHIFT)) + size =3D fi->rdc.size & ~READDIR_PAGES_MASK; else - size =3D PAGE_SIZE; + size =3D READDIR_PAGES_SIZE; spin_unlock(&fi->rdc.lock); =20 /* EOF? */ - if ((ff->readdir.cache_off & ~PAGE_MASK) =3D=3D size) + if ((ff->readdir.cache_off & ~READDIR_PAGES_MASK) =3D=3D size) return 0; =20 page =3D find_get_page_flags(file->f_mapping, index, @@ -559,9 +565,9 @@ static int fuse_readdir_cached(struct file *file, struc= t dir_context *ctx) if (res =3D=3D FOUND_ALL) return 0; =20 - if (size =3D=3D PAGE_SIZE) { + if (size =3D=3D READDIR_PAGES_SIZE) { /* We hit end of page: skip to next page. */ - ff->readdir.cache_off =3D ALIGN(ff->readdir.cache_off, PAGE_SIZE); + ff->readdir.cache_off =3D ALIGN(ff->readdir.cache_off, READDIR_PAGES_SIZ= E); goto retry; } =20 --=20 2.41.0