[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <175798162669.391696.2292027654285998318.stgit@frogsfrogsfrogs>
Date: Mon, 15 Sep 2025 18:06:18 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: miklos@...redi.hu, neal@...pa.dev, linux-fsdevel@...r.kernel.org,
linux-ext4@...r.kernel.org, John@...ves.net, bernd@...ernd.com,
joannelkoong@...il.com
Subject: [PATCH 1/3] fuse2fs: enable caching of iomaps
From: Darrick J. Wong <djwong@...nel.org>
Cache the iomaps we generate in the kernel for better performance.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
fuse4fs/fuse4fs.c | 25 +++++++++++++++++++++++++
misc/fuse2fs.c | 24 ++++++++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index a7709a7e6fb699..6ab660b36d0472 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -284,6 +284,8 @@ struct fuse4fs {
#ifdef STATX_WRITE_ATOMIC
unsigned int awu_min, awu_max;
#endif
+ /* options set by fuse_opt_parse must be of type int */
+ int iomap_cache;
#endif
unsigned int blockmask;
unsigned long offset;
@@ -6373,6 +6375,24 @@ static void op_iomap_begin(fuse_req_t req, fuse_ino_t fino, uint64_t dontcare,
if (opflags & FUSE_IOMAP_OP_ATOMIC)
read.flags |= FUSE_IOMAP_F_ATOMIC_BIO;
+ /*
+ * Cache the mapping in the kernel so that we can reuse them for
+ * subsequent IO.
+ */
+ if (ff->iomap_cache) {
+ ret = fuse_lowlevel_notify_iomap_upsert(ff->fuse, fino, ino,
+ &read, NULL);
+ if (ret) {
+ ret = translate_error(fs, ino, -ret);
+ goto out_unlock;
+ } else {
+ /* Tell the kernel to retry from cache */
+ read.type = FUSE_IOMAP_TYPE_RETRY_CACHE;
+ read.dev = FUSE_IOMAP_DEV_NULL;
+ read.addr = FUSE_IOMAP_NULL_ADDR;
+ }
+ }
+
out_unlock:
fuse4fs_finish(ff, ret);
if (ret)
@@ -7183,6 +7203,10 @@ static struct fuse_opt fuse4fs_opts[] = {
FUSE4FS_OPT("timing", timing, 1),
#endif
FUSE4FS_OPT("noblkdev", noblkdev, 1),
+#ifdef HAVE_FUSE_IOMAP
+ FUSE4FS_OPT("iomap_cache", iomap_cache, 1),
+ FUSE4FS_OPT("noiomap_cache", iomap_cache, 0),
+#endif
#ifdef HAVE_FUSE_IOMAP
#ifdef MS_LAZYTIME
@@ -7517,6 +7541,7 @@ int main(int argc, char *argv[])
.iomap_want = FT_DEFAULT,
.iomap_state = IOMAP_UNKNOWN,
.iomap_dev = FUSE_IOMAP_DEV_NULL,
+ .iomap_cache = 1,
#endif
.translate_inums = 1,
.write_gdt_on_destroy = 1,
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 260d1b77e3f24b..14a1ceeea46a0b 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -277,6 +277,8 @@ struct fuse2fs {
#ifdef STATX_WRITE_ATOMIC
unsigned int awu_min, awu_max;
#endif
+ /* options set by fuse_opt_parse must be of type int */
+ int iomap_cache;
#endif
unsigned int blockmask;
unsigned long offset;
@@ -5942,6 +5944,23 @@ static int op_iomap_begin(const char *path, uint64_t nodeid, uint64_t attr_ino,
if (opflags & FUSE_IOMAP_OP_ATOMIC)
read->flags |= FUSE_IOMAP_F_ATOMIC_BIO;
+ /*
+ * Cache the mapping in the kernel so that we can reuse them for
+ * subsequent IO.
+ */
+ if (ff->iomap_cache) {
+ ret = fuse_fs_iomap_upsert(nodeid, attr_ino, read, NULL);
+ if (ret) {
+ ret = translate_error(fs, attr_ino, -ret);
+ goto out_unlock;
+ } else {
+ /* Tell the kernel to retry from cache */
+ read->type = FUSE_IOMAP_TYPE_RETRY_CACHE;
+ read->dev = FUSE_IOMAP_DEV_NULL;
+ read->addr = FUSE_IOMAP_NULL_ADDR;
+ }
+ }
+
out_unlock:
fuse2fs_finish(ff, ret);
return ret;
@@ -6744,6 +6763,10 @@ static struct fuse_opt fuse2fs_opts[] = {
FUSE2FS_OPT("timing", timing, 1),
#endif
FUSE2FS_OPT("noblkdev", noblkdev, 1),
+#ifdef HAVE_FUSE_IOMAP
+ FUSE2FS_OPT("iomap_cache", iomap_cache, 1),
+ FUSE2FS_OPT("noiomap_cache", iomap_cache, 0),
+#endif
#ifdef HAVE_FUSE_IOMAP
#ifdef MS_LAZYTIME
@@ -6978,6 +7001,7 @@ int main(int argc, char *argv[])
.iomap_want = FT_DEFAULT,
.iomap_state = IOMAP_UNKNOWN,
.iomap_dev = FUSE_IOMAP_DEV_NULL,
+ .iomap_cache = 1,
#endif
.write_gdt_on_destroy = 1,
};
Powered by blists - more mailing lists