[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1730190466-13015-1-git-send-email-zhiguo.niu@unisoc.com>
Date: Tue, 29 Oct 2024 16:27:46 +0800
From: Zhiguo Niu <zhiguo.niu@...soc.com>
To: <jaegeuk@...nel.org>, <chao@...nel.org>
CC: <linux-f2fs-devel@...ts.sourceforge.net>, <linux-kernel@...r.kernel.org>,
<niuzhiguo84@...il.com>, <zhiguo.niu@...soc.com>, <ke.wang@...soc.com>,
<Hao_hao.Wang@...soc.com>
Subject: [PATCH V2] f2fs-io: unify default block size
F2FS_BLKSIZE and 4096 are both used in f2fs_io for
IO/buffer size, but F2FS_BLKSIZE may confuse user becasue
it may be 4KB, 16KB, so use macro F2FS_DEFAULT_BLKSIZE
to unify F2FS_BLKSIZE and 4096 in f2fs_io, also adjust
"-c" parameters in mkfs man, to be consistent with commit
c35fa8cd75ac ("mkfs.f2fs: change -c option description").
Signed-off-by: Zhiguo Niu <zhiguo.niu@...soc.com>
---
V2: unify default block size in f2fs_io.c
---
man/mkfs.f2fs.8 | 2 +-
tools/f2fs_io/f2fs_io.c | 37 ++++++++++++++++++++-----------------
tools/f2fs_io/f2fs_io.h | 2 +-
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index de885be..8b3b0cc 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -122,7 +122,7 @@ block size matches the page size.
The default value is 4096.
.TP
.BI \-c " device-list"
-Build f2fs with these additional comma separated devices, so that the user can
+Build f2fs with these additional devices, so that the user can
see all the devices as one big volume.
Supports up to 7 devices except meta device.
.TP
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 95f575f..837f8a9 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -209,7 +209,7 @@ static void do_set_verity(int argc, char **argv, const struct cmd_desc *cmd)
struct fsverity_enable_arg args = {.version = 1};
args.hash_algorithm = FS_VERITY_HASH_ALG_SHA256;
- args.block_size = 4096;
+ args.block_size = F2FS_DEFAULT_BLKSIZE;
if (argc != 2) {
fputs("Excess arguments\n\n", stderr);
@@ -659,11 +659,11 @@ static void do_write_with_advice(int argc, char **argv,
if (bs > 1024)
die("Too big chunk size - limit: 4MB");
- buf_size = bs * 4096;
+ buf_size = bs * F2FS_DEFAULT_BLKSIZE;
offset = atoi(argv[2]) * buf_size;
- buf = aligned_xalloc(4096, buf_size);
+ buf = aligned_xalloc(F2FS_DEFAULT_BLKSIZE, buf_size);
count = atoi(argv[3]);
if (!strcmp(argv[4], "zero"))
@@ -874,11 +874,11 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
bs = atoi(argv[1]);
if (bs > 1024)
die("Too big chunk size - limit: 4MB");
- buf_size = bs * 4096;
+ buf_size = bs * F2FS_DEFAULT_BLKSIZE;
offset = atoi(argv[2]) * buf_size;
- buf = aligned_xalloc(4096, buf_size);
+ buf = aligned_xalloc(F2FS_DEFAULT_BLKSIZE, buf_size);
count = atoi(argv[3]);
if (!strcmp(argv[4], "dio"))
@@ -898,9 +898,11 @@ static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
advice = atoi(argv[5]);
if (advice) {
- if (posix_fadvise(fd, 0, 4096, POSIX_FADV_SEQUENTIAL) != 0)
+ if (posix_fadvise(fd, 0, F2FS_DEFAULT_BLKSIZE,
+ POSIX_FADV_SEQUENTIAL) != 0)
die_errno("fadvise failed");
- if (posix_fadvise(fd, 0, 4096, POSIX_FADV_WILLNEED) != 0)
+ if (posix_fadvise(fd, 0, F2FS_DEFAULT_BLKSIZE,
+ POSIX_FADV_WILLNEED) != 0)
die_errno("fadvise failed");
printf("fadvise SEQUENTIAL|WILLNEED to a file: %s\n", argv[7]);
}
@@ -976,9 +978,9 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
bs = atoi(argv[1]);
if (bs > 1024)
die("Too big chunk size - limit: 4MB");
- buf_size = bs * 4096;
+ buf_size = bs * F2FS_DEFAULT_BLKSIZE;
- buf = aligned_xalloc(4096, buf_size);
+ buf = aligned_xalloc(F2FS_DEFAULT_BLKSIZE, buf_size);
count = atoi(argv[2]);
if (!strcmp(argv[3], "dio"))
@@ -991,17 +993,17 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
if (fstat(fd, &stbuf) != 0)
die_errno("fstat of source file failed");
- aligned_size = (u64)stbuf.st_size & ~((u64)(4096 - 1));
+ aligned_size = (u64)stbuf.st_size & ~((u64)(F2FS_DEFAULT_BLKSIZE - 1));
if (aligned_size < buf_size)
die("File is too small to random read");
- end_idx = (u64)(aligned_size - buf_size) / (u64)4096 + 1;
+ end_idx = (u64)(aligned_size - buf_size) / (u64)F2FS_DEFAULT_BLKSIZE + 1;
srand((unsigned) time(&t));
for (i = 0; i < count; i++) {
idx = rand() % end_idx;
- ret = pread(fd, buf, buf_size, 4096 * idx);
+ ret = pread(fd, buf, buf_size, F2FS_DEFAULT_BLKSIZE * idx);
if (ret != buf_size)
break;
@@ -1031,15 +1033,16 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
}
memset(fm, 0, sizeof(struct fiemap));
- start = (u64)atoi(argv[1]) * F2FS_BLKSIZE;
- length = (u64)atoi(argv[2]) * F2FS_BLKSIZE;
+ start = (u64)atoi(argv[1]) * F2FS_DEFAULT_BLKSIZE;
+ length = (u64)atoi(argv[2]) * F2FS_DEFAULT_BLKSIZE;
fm->fm_start = start;
fm->fm_length = length;
fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
printf("Fiemap: offset = %"PRIu64" len = %"PRIu64"\n",
- start / F2FS_BLKSIZE, length / F2FS_BLKSIZE);
+ start / F2FS_DEFAULT_BLKSIZE,
+ length / F2FS_DEFAULT_BLKSIZE);
if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
die_errno("FIEMAP failed");
@@ -1219,9 +1222,9 @@ static void do_copy(int argc, char **argv, const struct cmd_desc *cmd)
if (ret < 0)
die_errno("sendfile failed");
} else {
- char *buf = aligned_xalloc(4096, 4096);
+ char *buf = aligned_xalloc(F2FS_DEFAULT_BLKSIZE, F2FS_DEFAULT_BLKSIZE);
- while ((ret = xread(src_fd, buf, 4096)) > 0)
+ while ((ret = xread(src_fd, buf, F2FS_DEFAULT_BLKSIZE)) > 0)
full_write(dst_fd, buf, ret);
free(buf);
}
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index e55db5f..14c9dc1 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -48,7 +48,7 @@ typedef u16 __be16;
typedef u32 __be32;
#endif
-#define F2FS_BLKSIZE 4096
+#define F2FS_DEFAULT_BLKSIZE 4096
#define NEW_ADDR 0xFFFFFFFF
#ifndef FS_IOC_GETFLAGS
--
1.9.1
Powered by blists - more mailing lists