From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH 1/3] f2fs_io: add mmap read operation
Date: Mon, 20 Jul 2020 17:38:32 -0700 [thread overview]
Message-ID: <20200721003834.2754992-1-jaegeuk@kernel.org> (raw)
This patch adds an option, mmap, when reading data.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
tools/f2fs_io/f2fs_io.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 30544c1..6266454 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -489,15 +489,18 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
"IO can be\n" \
" buffered : buffered IO\n" \
" dio : direct IO\n" \
+" mmap : mmap IO\n" \
static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
{
u64 buf_size = 0, ret = 0, read_cnt = 0;
u64 offset;
char *buf = NULL;
+ char *data;
char *print_buf = NULL;
unsigned bs, count, i, print_bytes;
int flags = 0;
+ int do_mmap = 0;
int fd;
if (argc != 7) {
@@ -518,6 +521,8 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
count = atoi(argv[3]);
if (!strcmp(argv[4], "dio"))
flags |= O_DIRECT;
+ else if (!strcmp(argv[4], "mmap"))
+ do_mmap = 1;
else if (strcmp(argv[4], "buffered"))
die("Wrong IO type");
@@ -529,8 +534,20 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
fd = xopen(argv[6], O_RDONLY | flags, 0);
+ if (do_mmap) {
+ data = mmap(NULL, count * buf_size, PROT_READ,
+ MAP_SHARED, fd, offset);
+ if (data == MAP_FAILED)
+ die("Mmap failed");
+ }
+
for (i = 0; i < count; i++) {
- ret = pread(fd, buf, buf_size, offset + buf_size * i);
+ if (do_mmap) {
+ memcpy(buf, data + offset + buf_size * i, buf_size);
+ ret = buf_size;
+ } else {
+ ret = pread(fd, buf, buf_size, offset + buf_size * i);
+ }
if (ret != buf_size)
break;
--
2.28.0.rc0.105.gf9edc3c819-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-07-21 0:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-21 0:38 Jaegeuk Kim [this message]
2020-07-21 0:38 ` [f2fs-dev] [PATCH 2/3] mkfs.f2fs: should initialize sparse file in Windows Jaegeuk Kim
2020-07-21 0:38 ` [f2fs-dev] [PATCH 3/3] mkfs.f2fs: add casefolding and project quota config Jaegeuk Kim
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=20200721003834.2754992-1-jaegeuk@kernel.org \
--to=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 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).