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 2/3] f2fs_io: add read test with mlock2 and madvise
Date: Mon, 1 Dec 2025 20:46:19 +0000 [thread overview]
Message-ID: <20251201204620.905318-2-jaegeuk@kernel.org> (raw)
In-Reply-To: <20251201204620.905318-1-jaegeuk@kernel.org>
Add a method to read out pages into unevictable mapping by mmap(), mlock2(),
and madvise()
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
tools/f2fs_io/f2fs_io.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index bc2e014d3911..d5e103f7b833 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -938,6 +938,7 @@ static void do_write_advice(int argc, char **argv, const struct cmd_desc *cmd)
" dontcache: buffered IO + dontcache\n" \
" dio : direct IO\n" \
" mmap : mmap IO\n" \
+" madvise : mmap + mlock2 + madvise\n" \
" mlock : mmap + mlock\n" \
"advice can be\n" \
" 1 : set sequential|willneed\n" \
@@ -956,6 +957,7 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
int flags = 0;
int do_mmap = 0;
int do_mlock = 0;
+ int do_madvise = 0;
int do_dontcache = 0;
int fd, advice;
@@ -979,6 +981,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], "madvise"))
+ do_madvise = 1;
else if (!strcmp(argv[4], "mlock"))
do_mlock = 1;
else if (!strcmp(argv[4], "dontcache"))
@@ -1021,6 +1025,24 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
if (mlock(data, count * buf_size))
die_errno("mlock failed");
mlock_time_end = get_current_us();
+ read_cnt = count * buf_size;
+ memcpy(print_buf, data, print_bytes);
+ } else if (do_madvise) {
+ data = mmap(NULL, count * buf_size, PROT_READ,
+ MAP_SHARED, fd, offset);
+ if (data == MAP_FAILED)
+ die("Mmap failed");
+
+ mlock_time_start = get_current_us();
+ if (mlock2(data, count * buf_size, MLOCK_ONFAULT))
+ die_errno("mlock2 failed");
+ mlock_time_end = get_current_us();
+
+ io_time_start = get_current_us();
+ if (madvise(data, count * buf_size, MADV_POPULATE_READ) != 0)
+ die_errno("madvise failed");
+ io_time_end = get_current_us();
+
read_cnt = count * buf_size;
memcpy(print_buf, data, print_bytes);
} else if (do_mlock) {
@@ -1085,7 +1107,7 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
}
if (do_mmap) {
munmap(data, count * buf_size);
- } else if (do_mlock) {
+ } else if (do_mlock || do_madvise) {
munlock(data, count * buf_size);
munmap(data, count * buf_size);
}
--
2.52.0.107.ga0afd4fd5b-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2025-12-01 20:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 20:46 [f2fs-dev] [PATCH 1/3] f2fs_io: measure the start time explicitly Jaegeuk Kim via Linux-f2fs-devel
2025-12-01 20:46 ` Jaegeuk Kim via Linux-f2fs-devel [this message]
2025-12-01 21:29 ` [f2fs-dev] [PATCH 2/3] f2fs_io: add read test with mlock2 and madvise Chao Yu via Linux-f2fs-devel
2025-12-01 20:46 ` [f2fs-dev] [PATCH 3/3] f2fs_io: rename mlock to fadvise Jaegeuk Kim via Linux-f2fs-devel
2025-12-01 21:30 ` Chao Yu via Linux-f2fs-devel
2025-12-01 21:25 ` [f2fs-dev] [PATCH 1/3] f2fs_io: measure the start time explicitly 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=20251201204620.905318-2-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.