Skip to contentSkip to conversation

f2fs_io: support fadvice for read

PATCH In review Jaegeuk Kim via Linux-f2fs-devel 1 participant 2 messages Oct 11, 2024 – Oct 15, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs_io: support fadvice for read

This adds a way to boost read performance by giving fadvise.

---
 tools/f2fs_io/f2fs_io.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
tools/f2fs_io/f2fs_io.c +20 -7
index 8fbad3c8e563..5b67a92e0947 100644
@@ -833,12 +833,15 @@ static void do_write_advice(int argc, char **argv, const struct cmd_desc *cmd)
 
 #define read_desc "read data from file"
 #define read_help					\
-"f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]\n\n"	\
+"f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [advice] [print_nbytes] [file_path]\n\n"	\
 "Read data in file_path and print nbytes\n"		\
 "IO can be\n"						\
 "  buffered : buffered IO\n"				\
 "  dio      : direct IO\n"				\
 "  mmap     : mmap IO\n"				\
+"advice can be\n"					\
+" 1 : set sequential|willneed\n"			\
+" 0 : none\n"						\
 
 static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
 {
@@ -851,9 +854,9 @@ 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 fd;
+	int fd, advice;
 
-	if (argc != 7) {
+	if (argc != 8) {
 		fputs("Excess arguments\n\n", stderr);
 		fputs(cmd->cmd_help, stderr);
 		exit(1);
@@ -876,13 +879,22 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
 	else if (strcmp(argv[4], "buffered"))
 		die("Wrong IO type");
 
-	print_bytes = atoi(argv[5]);
+	print_bytes = atoi(argv[6]);
 	if (print_bytes > buf_size)
 		die("Print_nbytes should be less then chunk_size in kb");
 
 	print_buf = xmalloc(print_bytes);
 
-	fd = xopen(argv[6], O_RDONLY | flags, 0);
+	fd = xopen(argv[7], O_RDONLY | flags, 0);
+
+	advice = atoi(argv[5]);
+	if (advice) {
+		if (posix_fadvise(fd, 0, 4096, POSIX_FADV_SEQUENTIAL) != 0)
+			die_errno("fadvise failed");
+		if (posix_fadvise(fd, 0, 4096, POSIX_FADV_WILLNEED) != 0)
+			die_errno("fadvise failed");
+		printf("fadvise SEQUENTIAL|WILLNEED to a file: %s\n", argv[7]);
+	}
 
 	total_time = get_current_us();
 	if (do_mmap) {
@@ -912,8 +924,9 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
 		read_cnt = count * buf_size;
 		memcpy(print_buf, data, print_bytes);
 	}
-	printf("Read %"PRIu64" bytes total_time = %"PRIu64" us, print %u bytes:\n",
-		read_cnt, get_current_us() - total_time, 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,
+		((long double)read_cnt / (get_current_us() - total_time) * 1000/1024 * 1000/1024 ), print_bytes);
 	printf("%08"PRIx64" : ", offset);
 	for (i = 1; i <= print_bytes; i++) {
 		printf("%02x", print_buf[i - 1]);
Signature · 8 lines
2.47.0.rc1.288.g06298d1525-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 66 lines · On 2024/10/12 6:49, Jaegeuk Kim via Linux-f2fs-devel wrote:

This adds a way to boost read performance by giving fadvise.

---
  tools/f2fs_io/f2fs_io.c | 27 ++++++++++++++++++++-------
  1 file changed, 20 insertions(+), 7 deletions(-)
tools/f2fs_io/f2fs_io.c +17 -5
index 8fbad3c8e563..5b67a92e0947 100644
@@ -833,12 +833,15 @@ static void do_write_advice(int argc, char **argv, const struct cmd_desc *cmd)
 
  #define read_desc "read data from file"
  #define read_help					\
-"f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]\n\n"	\
+"f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [advice] [print_nbytes] [file_path]\n\n"	\
  "Read data in file_path and print nbytes\n"		\
  "IO can be\n"						\
  "  buffered : buffered IO\n"				\
  "  dio      : direct IO\n"				\
  "  mmap     : mmap IO\n"				\
+"advice can be\n"					\
+" 1 : set sequential|willneed\n"			\
+" 0 : none\n"						\
 
  static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
  {
@@ -851,9 +854,9 @@ 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 fd;
+	int fd, advice;
 
-	if (argc != 7) {
+	if (argc != 8) {
  		fputs("Excess arguments\n\n", stderr);
  		fputs(cmd->cmd_help, stderr);
  		exit(1);
@@ -876,13 +879,22 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
  	else if (strcmp(argv[4], "buffered"))
  		die("Wrong IO type");
 
-	print_bytes = atoi(argv[5]);
+	print_bytes = atoi(argv[6]);
  	if (print_bytes > buf_size)
  		die("Print_nbytes should be less then chunk_size in kb");
 
  	print_buf = xmalloc(print_bytes);
 
-	fd = xopen(argv[6], O_RDONLY | flags, 0);
+	fd = xopen(argv[7], O_RDONLY | flags, 0);
+
+	advice = atoi(argv[5]);
+	if (advice) {
+		if (posix_fadvise(fd, 0, 4096, POSIX_FADV_SEQUENTIAL) != 0)
+			die_errno("fadvise failed");
+		if (posix_fadvise(fd, 0, 4096, POSIX_FADV_WILLNEED) != 0)
+			die_errno("fadvise failed");
+		printf("fadvise SEQUENTIAL|WILLNEED to a file: %s\n", argv[7]);
+	}
 
  	total_time = get_current_us();
  	if (do_mmap) {

tools/f2fs_io/f2fs_io.c static void do_read(int argc, char **argv, const struct cmd_desc *cmd) · line 929

Quoted 8 lines
tools/f2fs_io/f2fs_io.c +3 -2
@@ -912,8 +924,9 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
  		read_cnt = count * buf_size;
  		memcpy(print_buf, data, print_bytes);
  	}
-	printf("Read %"PRIu64" bytes total_time = %"PRIu64" us, print %u bytes:\n",
-		read_cnt, get_current_us() - total_time, 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,
+		((long double)read_cnt / (get_current_us() - total_time) * 1000/1024 * 1000/1024 ), print_bytes);

((long double)read_cnt / (get_current_us() - total_time) / 1000 / 1000) ?

tools/f2fs_io/f2fs_io.c static void do_read(int argc, char **argv, const struct cmd_desc *cmd) · line 932

Quoted 3 lines
tools/f2fs_io/f2fs_io.c +0 -0
  	printf("%08"PRIx64" : ", offset);
  	for (i = 1; i <= print_bytes; i++) {
  		printf("%02x", print_buf[i - 1]);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel