All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] f2fs_io: support gc_range command
Date: Thu,  1 Jun 2023 18:30:54 +0800	[thread overview]
Message-ID: <20230601103054.1761833-1-chao@kernel.org> (raw)

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

                 reply	other threads:[~2023-06-01 10:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230601103054.1761833-1-chao@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.