From: Daeho Jeong <daeho43@gmail.com>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Daeho Jeong <daehojeong@google.com>
Subject: [f2fs-dev] [PATCH] f2fs_io: add randread
Date: Wed, 27 May 2020 12:33:13 +0900 [thread overview]
Message-ID: <20200527033313.22391-1-daeho43@gmail.com> (raw)
From: Daeho Jeong <daehojeong@google.com>
I've added a new command to evaluate random read.
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
tools/f2fs_io/f2fs_io.c | 64 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index d1889ff..30544c1 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -551,6 +551,69 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define randread_desc "random read data from file"
+#define randread_help \
+"f2fs_io randread [chunk_size in 4kb] [count] [IO] [file_path]\n\n" \
+"Do random read data in file_path\n" \
+"IO can be\n" \
+" buffered : buffered IO\n" \
+" dio : direct IO\n" \
+
+static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ u64 buf_size = 0, ret = 0, read_cnt = 0;
+ u64 idx, end_idx, aligned_size;
+ char *buf = NULL;
+ unsigned bs, count, i;
+ int flags = 0;
+ int fd;
+ time_t t;
+ struct stat stbuf;
+
+ if (argc != 5) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ bs = atoi(argv[1]);
+ if (bs > 1024)
+ die("Too big chunk size - limit: 4MB");
+ buf_size = bs * 4096;
+
+ buf = aligned_xalloc(4096, buf_size);
+
+ count = atoi(argv[2]);
+ if (!strcmp(argv[3], "dio"))
+ flags |= O_DIRECT;
+ else if (strcmp(argv[3], "buffered"))
+ die("Wrong IO type");
+
+ fd = xopen(argv[4], O_RDONLY | flags, 0);
+
+ if (fstat(fd, &stbuf) != 0)
+ die_errno("fstat of source file failed");
+
+ aligned_size = (u64)stbuf.st_size & ~((u64)(4096 - 1));
+ if (aligned_size < buf_size)
+ die("File is too small to random read");
+ end_idx = (u64)(aligned_size - buf_size) / (u64)4096 + 1;
+
+ srand((unsigned) time(&t));
+
+ for (i = 0; i < count; i++) {
+ idx = rand() % end_idx;
+
+ ret = pread(fd, buf, buf_size, 4096 * idx);
+ if (ret != buf_size)
+ break;
+
+ read_cnt += ret;
+ }
+ printf("Read %"PRIu64" bytes\n", read_cnt);
+ exit(0);
+}
+
struct file_ext {
__u32 f_pos;
__u32 start_blk;
@@ -841,6 +904,7 @@ const struct cmd_desc cmd_list[] = {
CMD(fallocate),
CMD(write),
CMD(read),
+ CMD(randread),
CMD(fiemap),
CMD(gc_urgent),
CMD(defrag_file),
--
2.27.0.rc0.183.gde8f92d652-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2020-05-27 3:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 3:33 Daeho Jeong [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-05-27 22:52 [f2fs-dev] [PATCH] f2fs_io: add randread Daeho Jeong
2020-06-08 1:54 ` Chao Yu
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=20200527033313.22391-1-daeho43@gmail.com \
--to=daeho43@gmail.com \
--cc=daehojeong@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).