From: Jaegeuk Kim via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH 1/3] f2fs_io: add mlock to measure the read speed
Date: Thu, 18 Sep 2025 04:53:14 +0000 [thread overview]
Message-ID: <20250918045316.714102-1-jaegeuk@kernel.org> (raw)
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
tools/f2fs_io/f2fs_io.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index b9bf9bc5f797..2d64eda81706 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -931,6 +931,7 @@ static void do_write_advice(int argc, char **argv, const struct cmd_desc *cmd)
" buffered : buffered IO\n" \
" dio : direct IO\n" \
" mmap : mmap IO\n" \
+" mlock : mmap + mlock\n" \
"advice can be\n" \
" 1 : set sequential|willneed\n" \
" 0 : none\n" \
@@ -946,6 +947,7 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
u64 total_time = 0;
int flags = 0;
int do_mmap = 0;
+ int do_mlock = 0;
int fd, advice;
if (argc != 8) {
@@ -968,6 +970,8 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
flags |= O_DIRECT;
else if (!strcmp(argv[4], "mmap"))
do_mmap = 1;
+ else if (!strcmp(argv[4], "mlock"))
+ do_mlock = 1;
else if (strcmp(argv[4], "buffered"))
die("Wrong IO type");
@@ -993,11 +997,24 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
total_time = get_current_us();
if (do_mmap) {
data = mmap(NULL, count * buf_size, PROT_READ,
- MAP_SHARED | MAP_POPULATE, fd, offset);
+ MAP_SHARED | MAP_POPULATE, fd, offset);
if (data == MAP_FAILED)
die("Mmap failed");
- }
- if (!do_mmap) {
+
+ read_cnt = count * buf_size;
+ memcpy(print_buf, data, print_bytes);
+ } else if (do_mlock) {
+ data = mmap(NULL, count * buf_size, PROT_READ,
+ MAP_SHARED, fd, offset);
+ if (data == MAP_FAILED)
+ die("Mmap failed");
+ if (posix_fadvise(fd, offset, count * buf_size,
+ POSIX_FADV_WILLNEED) != 0)
+ die_errno("fadvise failed");
+ if (mlock(data, count * buf_size))
+ die_errno("mlock failed");
+ read_cnt = count * buf_size;
+ } else {
for (i = 0; i < count; i++) {
ret = pread(fd, buf, buf_size, offset + buf_size * i);
if (ret != buf_size) {
@@ -1014,9 +1031,6 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
if (i == 0)
memcpy(print_buf, buf, print_bytes);
}
- } else {
- read_cnt = count * buf_size;
- memcpy(print_buf, data, print_bytes);
}
printf("Read %"PRIu64" bytes total_time = %"PRIu64" us, BW = %.Lf MB/s print %u bytes:\n",
read_cnt, get_current_us() - total_time,
@@ -1029,6 +1043,12 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
else if (i % 2 == 0)
printf(" ");
}
+ if (do_mmap) {
+ munmap(data, count * buf_size);
+ } else if (do_mlock) {
+ munlock(data, count * buf_size);
+ munmap(data, count * buf_size);
+ }
printf("\n");
exit(0);
}
--
2.51.0.470.ga7dc726c21-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:[~2025-09-18 4:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 4:53 Jaegeuk Kim via Linux-f2fs-devel [this message]
2025-09-18 4:53 ` [f2fs-dev] [PATCH 2/3] f2fs_io: add dontcache to measure RWF_DONTCACHE speed Jaegeuk Kim via Linux-f2fs-devel
2025-09-23 9:38 ` Chao Yu via Linux-f2fs-devel
2025-09-18 4:53 ` [f2fs-dev] [PATCH 3/3] f2fs_io: let's try to get contigous memory if possible Jaegeuk Kim via Linux-f2fs-devel
2025-09-23 9:36 ` [f2fs-dev] [PATCH 1/3] f2fs_io: add mlock to measure the read speed Chao Yu via Linux-f2fs-devel
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=20250918045316.714102-1-jaegeuk@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=jaegeuk@kernel.org \
/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.