* [PATCH] f2fs: skip direct I/O iostat work when disabled
@ 2026-05-27 5:45 Wenjie Qi
2026-06-10 0:33 ` Jaegeuk Kim
0 siblings, 1 reply; 2+ messages in thread
From: Wenjie Qi @ 2026-05-27 5:45 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, qiwenjie, qwjhust
F2FS iostat is optional and is disabled by default, but the direct
I/O submit path still allocates and binds a bio_iostat_ctx, updates
the submit timestamp, and replaces bi_end_io for every DIO bio even
when sbi->iostat_enable is false.
The end_io path also calls f2fs_update_iostat(), which returns
immediately when iostat is disabled. This adds avoidable per-bio
overhead to the default direct I/O hot path.
Skip DIO iostat context setup and the direct read/write byte updates
when iostat is disabled. If iostat is enabled through sysfs before
submission, the existing context allocation and latency accounting path
is still used.
QEMU benchmark on a 1GiB F2FS virtio-blk image, with iostat_enable=0,
4KiB O_DIRECT I/O over a 64MiB file, 50000 iterations per run:
baseline patched
direct_read median 65264.50 ns 55470.95 ns
direct_read recheck 65553.75 ns 55470.95 ns
direct_write median 68054.62 ns 56309.44 ns
direct_write recheck 66873.51 ns 56309.44 ns
Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
---
fs/f2fs/file.c | 9 +++++++--
fs/f2fs/iostat.h | 6 ++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 6edf0105dbc8..3ad8bd660b33 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4799,6 +4799,9 @@ static void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi, struct bio *bio)
{
void *bi_private = bio->bi_private;
+ if (!f2fs_iostat_enabled(sbi))
+ return;
+
iostat_alloc_and_bind_ctx(sbi, bio, bi_private);
iostat_update_submit_ctx(bio, DATA);
bio->bi_end_io = f2fs_dio_end_bio;
@@ -4816,7 +4819,8 @@ static int f2fs_dio_read_end_io(struct kiocb *iocb, ssize_t size, int error,
dec_page_count(sbi, F2FS_DIO_READ);
if (error)
return error;
- f2fs_update_iostat(sbi, NULL, APP_DIRECT_READ_IO, size);
+ if (f2fs_iostat_enabled(sbi))
+ f2fs_update_iostat(sbi, NULL, APP_DIRECT_READ_IO, size);
return 0;
}
@@ -5097,7 +5101,8 @@ static int f2fs_dio_write_end_io(struct kiocb *iocb, ssize_t size, int error,
if (error)
return error;
f2fs_update_time(sbi, REQ_TIME);
- f2fs_update_iostat(sbi, NULL, APP_DIRECT_IO, size);
+ if (f2fs_iostat_enabled(sbi))
+ f2fs_update_iostat(sbi, NULL, APP_DIRECT_IO, size);
return 0;
}
diff --git a/fs/f2fs/iostat.h b/fs/f2fs/iostat.h
index 2025225b5bed..d3ef787575be 100644
--- a/fs/f2fs/iostat.h
+++ b/fs/f2fs/iostat.h
@@ -44,6 +44,11 @@ struct bio_iostat_ctx {
struct bio_post_read_ctx *post_read_ctx;
};
+static inline bool f2fs_iostat_enabled(struct f2fs_sb_info *sbi)
+{
+ return sbi->iostat_enable;
+}
+
static inline void iostat_update_submit_ctx(struct bio *bio,
enum page_type type)
{
@@ -72,6 +77,7 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *in
enum iostat_type type, unsigned long long io_bytes) {}
static inline void f2fs_update_read_folio_count(struct f2fs_sb_info *sbi,
struct folio *folio) {}
+static inline bool f2fs_iostat_enabled(struct f2fs_sb_info *sbi) { return false; }
static inline void iostat_update_and_unbind_ctx(struct bio *bio) {}
static inline void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
struct bio *bio, struct bio_post_read_ctx *ctx) {}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] f2fs: skip direct I/O iostat work when disabled
2026-05-27 5:45 [PATCH] f2fs: skip direct I/O iostat work when disabled Wenjie Qi
@ 2026-06-10 0:33 ` Jaegeuk Kim
0 siblings, 0 replies; 2+ messages in thread
From: Jaegeuk Kim @ 2026-06-10 0:33 UTC (permalink / raw)
To: Wenjie Qi; +Cc: chao, linux-f2fs-devel, linux-kernel, qiwenjie
On 05/27, Wenjie Qi wrote:
> F2FS iostat is optional and is disabled by default, but the direct
> I/O submit path still allocates and binds a bio_iostat_ctx, updates
> the submit timestamp, and replaces bi_end_io for every DIO bio even
> when sbi->iostat_enable is false.
>
> The end_io path also calls f2fs_update_iostat(), which returns
> immediately when iostat is disabled. This adds avoidable per-bio
> overhead to the default direct I/O hot path.
>
> Skip DIO iostat context setup and the direct read/write byte updates
> when iostat is disabled. If iostat is enabled through sysfs before
> submission, the existing context allocation and latency accounting path
> is still used.
>
> QEMU benchmark on a 1GiB F2FS virtio-blk image, with iostat_enable=0,
> 4KiB O_DIRECT I/O over a 64MiB file, 50000 iterations per run:
>
> baseline patched
> direct_read median 65264.50 ns 55470.95 ns
> direct_read recheck 65553.75 ns 55470.95 ns
> direct_write median 68054.62 ns 56309.44 ns
> direct_write recheck 66873.51 ns 56309.44 ns
>
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
> ---
> fs/f2fs/file.c | 9 +++++++--
> fs/f2fs/iostat.h | 6 ++++++
> 2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 6edf0105dbc8..3ad8bd660b33 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -4799,6 +4799,9 @@ static void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi, struct bio *bio)
> {
> void *bi_private = bio->bi_private;
>
> + if (!f2fs_iostat_enabled(sbi))
> + return;
> +
> iostat_alloc_and_bind_ctx(sbi, bio, bi_private);
> iostat_update_submit_ctx(bio, DATA);
> bio->bi_end_io = f2fs_dio_end_bio;
> @@ -4816,7 +4819,8 @@ static int f2fs_dio_read_end_io(struct kiocb *iocb, ssize_t size, int error,
> dec_page_count(sbi, F2FS_DIO_READ);
> if (error)
> return error;
> - f2fs_update_iostat(sbi, NULL, APP_DIRECT_READ_IO, size);
> + if (f2fs_iostat_enabled(sbi))
> + f2fs_update_iostat(sbi, NULL, APP_DIRECT_READ_IO, size);
f2fs_update_iostat() checks sbi->iostat_enable?
> return 0;
> }
>
> @@ -5097,7 +5101,8 @@ static int f2fs_dio_write_end_io(struct kiocb *iocb, ssize_t size, int error,
> if (error)
> return error;
> f2fs_update_time(sbi, REQ_TIME);
> - f2fs_update_iostat(sbi, NULL, APP_DIRECT_IO, size);
> + if (f2fs_iostat_enabled(sbi))
> + f2fs_update_iostat(sbi, NULL, APP_DIRECT_IO, size);
> return 0;
> }
>
> diff --git a/fs/f2fs/iostat.h b/fs/f2fs/iostat.h
> index 2025225b5bed..d3ef787575be 100644
> --- a/fs/f2fs/iostat.h
> +++ b/fs/f2fs/iostat.h
> @@ -44,6 +44,11 @@ struct bio_iostat_ctx {
> struct bio_post_read_ctx *post_read_ctx;
> };
>
> +static inline bool f2fs_iostat_enabled(struct f2fs_sb_info *sbi)
> +{
> + return sbi->iostat_enable;
> +}
> +
> static inline void iostat_update_submit_ctx(struct bio *bio,
> enum page_type type)
> {
> @@ -72,6 +77,7 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *in
> enum iostat_type type, unsigned long long io_bytes) {}
> static inline void f2fs_update_read_folio_count(struct f2fs_sb_info *sbi,
> struct folio *folio) {}
> +static inline bool f2fs_iostat_enabled(struct f2fs_sb_info *sbi) { return false; }
> static inline void iostat_update_and_unbind_ctx(struct bio *bio) {}
> static inline void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
> struct bio *bio, struct bio_post_read_ctx *ctx) {}
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-10 0:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 5:45 [PATCH] f2fs: skip direct I/O iostat work when disabled Wenjie Qi
2026-06-10 0:33 ` Jaegeuk Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox