[PATCH 09/10] fuse2fs: skip the gdt write in op_destroy if syncfs is working

Darrick J. Wong
2025-09-16T01:05:47Z

As an umount-time performance enhancement, don't bother to write the
group descriptor tables in op_destroy if we know that op_syncfs will do
it for us. That only happens if iomap is enabled.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
fuse4fs/fuse4fs.c | 19 ++++++++++++++++---
misc/fuse2fs.c | 19 ++++++++++++++++---
2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/fuse4fs/fuse4fs.c b/fuse4fs/fuse4fs.c
index 25c19c0f0deca0..4f5618e64a93c3 100644
--- a/fuse4fs/fuse4fs.c
+++ b/fuse4fs/fuse4fs.c
@@ -268,6 +268,7 @@ struct fuse4fs {
int noblkdev;
int translate_inums;
int iomap_passthrough_options;
+ int write_gdt_on_destroy;

enum fuse4fs_opstate opstate;
int logfd;
@@ -1475,9 +1476,11 @@ static void op_destroy(void *userdata)
if (fs->super->s_error_count)
fs->super->s_state |= EXT2_ERROR_FS;
ext2fs_mark_super_dirty(fs);
- err = ext2fs_set_gdt_csum(fs);
- if (err)
- translate_error(fs, 0, err);
+ if (ff->write_gdt_on_destroy) {
+ err = ext2fs_set_gdt_csum(fs);
+ if (err)
+ translate_error(fs, 0, err);
+ }

err = ext2fs_flush2(fs, 0);
if (err)
@@ -5803,6 +5806,15 @@ static void op_syncfs(fuse_req_t req, fuse_ino_t ino)
}
}

+ /*
+ * When iomap is enabled, the kernel will call syncfs right before
+ * calling the destroy method. If any syncfs succeeds, then we know
+ * that there will be a last syncfs and that it will write the GDT, so
+ * destroy doesn't need to waste time doing that.
+ */
+ if (fuse4fs_iomap_enabled(ff))
+ ff->write_gdt_on_destroy = 0;
+
out_unlock:
fuse4fs_finish(ff, ret);
fuse_reply_err(req, -ret);
@@ -7497,6 +7509,7 @@ int main(int argc, char *argv[])
.iomap_dev = FUSE_IOMAP_DEV_NULL,
#endif
.translate_inums = 1,
+ .write_gdt_on_destroy = 1,
};
errcode_t err;
FILE *orig_stderr = stderr;
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index d4f1825dd695ad..b193e0b2c06b69 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -261,6 +261,7 @@ struct fuse2fs {
int unmount_in_destroy;
int noblkdev;
int iomap_passthrough_options;
+ int write_gdt_on_destroy;

enum fuse2fs_opstate opstate;
int logfd;
@@ -1301,9 +1302,11 @@ static void op_destroy(void *p EXT2FS_ATTR((unused)))
if (fs->super->s_error_count)
fs->super->s_state |= EXT2_ERROR_FS;
ext2fs_mark_super_dirty(fs);
- err = ext2fs_set_gdt_csum(fs);
- if (err)
- translate_error(fs, 0, err);
+ if (ff->write_gdt_on_destroy) {
+ err = ext2fs_set_gdt_csum(fs);
+ if (err)
+ translate_error(fs, 0, err);
+ }

err = ext2fs_flush2(fs, 0);
if (err)
@@ -5360,6 +5363,15 @@ static int op_syncfs(const char *path)
}
}

+ /*
+ * When iomap is enabled, the kernel will call syncfs right before
+ * calling the destroy method. If any syncfs succeeds, then we know
+ * that there will be a last syncfs and that it will write the GDT, so
+ * destroy doesn't need to waste time doing that.
+ */
+ if (fuse2fs_iomap_enabled(ff))
+ ff->write_gdt_on_destroy = 0;
+
out_unlock:
fuse2fs_finish(ff, ret);
return ret;
@@ -6944,6 +6956,7 @@ int main(int argc, char *argv[])
.iomap_state = IOMAP_UNKNOWN,
.iomap_dev = FUSE_IOMAP_DEV_NULL,
#endif
+ .write_gdt_on_destroy = 1,
};
errcode_t err;
FILE *orig_stderr = stderr;