Skip to content

Commit 5defefc

Browse files
author
Jaegeuk Kim
committed
f2fs_io: measure atomic operation latency with random write
If we give a negative offset, let's do random writes. > f2fs_io write 1 -400 10 rand atomic_commit ./test conducts 10 random writes by picking addresses between 0 and 400 * 4KB. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 15b275c commit 5defefc

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

tools/f2fs_io/f2fs_io.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@ static void do_write_with_advice(int argc, char **argv,
710710
const struct cmd_desc *cmd, bool with_advice)
711711
{
712712
u64 buf_size = 0, inc_num = 0, written = 0;
713-
u64 offset;
713+
u64 offset, offset_byte;
714+
bool random_offset = false;
714715
char *buf = NULL;
715716
unsigned bs, count, i;
716717
int flags = 0;
@@ -727,7 +728,10 @@ static void do_write_with_advice(int argc, char **argv,
727728

728729
buf_size = bs * F2FS_DEFAULT_BLKSIZE;
729730

730-
offset = atoi(argv[2]) * buf_size;
731+
if (atoi(argv[2]) < 0)
732+
random_offset = true;
733+
else
734+
offset = atoi(argv[2]) * buf_size;
731735

732736
buf = aligned_xalloc(F2FS_DEFAULT_BLKSIZE, buf_size);
733737
count = atoi(argv[3]);
@@ -812,10 +816,16 @@ static void do_write_with_advice(int argc, char **argv,
812816
else if (!strcmp(argv[4], "rand"))
813817
*(int *)buf = rand();
814818

819+
if (random_offset)
820+
offset_byte = (rand() % -offset) * buf_size;
821+
else
822+
offset_byte = offset + buf_size * i;
823+
815824
/* write data */
816825
max_time_t = get_current_us();
817-
ret = pwrite(fd, buf, buf_size, offset + buf_size * i);
826+
ret = pwrite(fd, buf, buf_size, offset_byte);
818827
max_time_t = get_current_us() - max_time_t;
828+
819829
if (max_time < max_time_t)
820830
max_time = max_time_t;
821831
if (ret != buf_size)
@@ -844,7 +854,7 @@ static void do_write_with_advice(int argc, char **argv,
844854
}
845855
}
846856

847-
printf("Written %"PRIu64" bytes with pattern=%s, total_time=%"PRIu64" us, max_latency=%"PRIu64" us\n",
857+
printf("Written %"PRIu64" bytes with pattern = %s, total_time = %"PRIu64" us, max_latency = %"PRIu64" us\n",
848858
written, argv[4],
849859
get_current_us() - total_time,
850860
max_time);
@@ -855,6 +865,8 @@ static void do_write_with_advice(int argc, char **argv,
855865
#define write_help \
856866
"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path] {delay}\n\n" \
857867
"Write given patten data in file_path\n" \
868+
"Offset can be a negative number which\n" \
869+
" indicates random write range for atomic operations.\n" \
858870
"pattern can be\n" \
859871
" zero : zeros\n" \
860872
" inc_num : incrementing numbers\n" \

0 commit comments

Comments
 (0)