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

Darrick J. Wong
2025-08-21T01:23:16Z

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>
---
misc/fuse2fs.c | 19 ++++++++++++++++---
misc/fuse4fs.c | 19 ++++++++++++++++---
2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 62aca0ab56ec07..f5d68cc549ad69 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -269,6 +269,7 @@ struct fuse2fs {
uint8_t unmount_in_destroy;
uint8_t noblkdev;
uint8_t iomap_passthrough_options;
+ uint8_t write_gdt_on_destroy;

enum fuse2fs_opstate opstate;
int logfd;
@@ -1309,9 +1310,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)
@@ -5443,6 +5446,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;
@@ -7088,6 +7100,7 @@ int main(int argc, char *argv[])
.iomap_dev = FUSE_IOMAP_DEV_NULL,
.iomap_cache = 1,
#endif
+ .write_gdt_on_destroy = 1,
};
errcode_t err;
FILE *orig_stderr = stderr;
diff --git a/misc/fuse4fs.c b/misc/fuse4fs.c
index e01b83e271415c..6f03c6a0933a3d 100644
--- a/misc/fuse4fs.c
+++ b/misc/fuse4fs.c
@@ -265,6 +265,7 @@ struct fuse4fs {
uint8_t noblkdev;
uint8_t iomap_passthrough_options;
uint8_t translate_inums;
+ uint8_t write_gdt_on_destroy;

enum fuse4fs_opstate opstate;
int logfd;
@@ -1472,9 +1473,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)
@@ -5736,6 +5739,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);
@@ -7472,6 +7484,7 @@ int main(int argc, char *argv[])
.iomap_cache = 1,
#endif
.translate_inums = 1,
+ .write_gdt_on_destroy = 1,
};
errcode_t err;
FILE *orig_stderr = stderr;