aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2023-08-11 15:04:08 -0700
committerJaegeuk Kim <jaegeuk@kernel.org>2023-08-17 18:22:21 -0700
commit4338603fc4bd62c69580e4a6f5bb81de6c193bfb (patch)
tree1c82c92669bd3b97697a6f89652a843161503919
parent6ebf6f2967d0a5731af1767d5735f46e30fea0fc (diff)
downloadf2fs-tools-4338603fc4bd62c69580e4a6f5bb81de6c193bfb.tar.gz
f2fs-tools: f2fs_io: no memcpy for mmap read
This replaces the mmmap read flow to get the maximum performance. Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--tools/f2fs_io/f2fs_io.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 73ac700..51baded 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -684,6 +684,7 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
char *data;
char *print_buf = NULL;
unsigned bs, count, i, print_bytes;
+ u64 total_time = 0;
int flags = 0;
int do_mmap = 0;
int fd;
@@ -719,28 +720,29 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
fd = xopen(argv[6], O_RDONLY | flags, 0);
+ total_time = get_current_us();
if (do_mmap) {
data = mmap(NULL, count * buf_size, PROT_READ,
- MAP_SHARED, fd, offset);
+ MAP_SHARED | MAP_POPULATE, fd, offset);
if (data == MAP_FAILED)
die("Mmap failed");
}
-
- for (i = 0; i < count; i++) {
- if (do_mmap) {
- memcpy(buf, data + offset + buf_size * i, buf_size);
- ret = buf_size;
- } else {
+ if (!do_mmap) {
+ for (i = 0; i < count; i++) {
ret = pread(fd, buf, buf_size, offset + buf_size * i);
- }
- if (ret != buf_size)
- break;
+ if (ret != buf_size)
+ break;
- read_cnt += ret;
- if (i == 0)
- memcpy(print_buf, buf, print_bytes);
+ read_cnt += ret;
+ 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 and print %u bytes:\n", read_cnt, print_bytes);
+ printf("Read %"PRIu64" bytes total_time = %"PRIu64" us, print %u bytes:\n",
+ read_cnt, get_current_us() - total_time, print_bytes);
printf("%08"PRIx64" : ", offset);
for (i = 1; i <= print_bytes; i++) {
printf("%02x", print_buf[i - 1]);