All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs_io: support gc_range command
@ 2023-06-01 10:30 Chao Yu
  0 siblings, 0 replies; only message in thread
From: Chao Yu @ 2023-06-01 10:30 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

This patch supports a new sub-command 'gc_range' in f2fs_io to trigger
gc to move blocks in specified range via F2FS_IOC_GARBAGE_COLLECT_RANGE
ioctl.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 man/f2fs_io.8           |  3 +++
 tools/f2fs_io/f2fs_io.c | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/man/f2fs_io.8 b/man/f2fs_io.8
index b25f807..c5eadde 100644
--- a/man/f2fs_io.8
+++ b/man/f2fs_io.8
@@ -144,6 +144,9 @@ Trigger precache extents
 .TP
 \fBmove_range\fR \fI[src_path] [dst_path] [src_start] [dst_start] [length]\fR
 Move a range of data blocks from source file to destination file
+.TP
+\fBgc_range\fR \fI[sync_mode] [start in 4kb] [length in 4kb] [file]\fR
+Trigger gc to move data blocks from specified address range
 .SH AUTHOR
 This version of
 .B f2fs_io
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index ea9143b..b8102b5 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1419,6 +1419,40 @@ static void do_move_range(int argc, char **argv, const struct cmd_desc *cmd)
 	exit(0);
 }
 
+#define gc_range_desc "trigger filesystem gc_range"
+#define gc_range_help "f2fs_io gc_range [sync_mode] [start] [length] [file_path]\n\n"\
+"  sync_mode : 0: asynchronous, 1: synchronous\n"			\
+"  start     : start offset of defragment region, unit: 4kb\n"	\
+"  length    : bytes number of defragment region, unit: 4kb\n"	\
+
+static void do_gc_range(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	struct f2fs_gc_range range;
+	int ret, fd;
+
+	if (argc != 5) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	range.sync = atoi(argv[1]);
+	range.start = (u64)atoi(argv[2]);
+	range.len = (u64)atoi(argv[3]);
+
+	fd = xopen(argv[4], O_RDWR, 0);
+
+	ret = ioctl(fd, F2FS_IOC_GARBAGE_COLLECT_RANGE, &range);
+	if (ret < 0) {
+		die_errno("F2FS_IOC_GARBAGE_COLLECT_RANGE failed");
+	}
+
+	printf("trigger %s gc_range [%lu, %lu] ret=%d\n",
+		range.sync ? "synchronous" : "asynchronous",
+		range.start, range.len, ret);
+	exit(0);
+}
+
 #define CMD_HIDDEN 	0x0001
 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
 #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -1454,6 +1488,7 @@ const struct cmd_desc cmd_list[] = {
 	CMD(checkpoint),
 	CMD(precache_extents),
 	CMD(move_range),
+	CMD(gc_range),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 
-- 
2.40.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-01 10:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-01 10:30 [f2fs-dev] [PATCH] f2fs_io: support gc_range command Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.