* [f2fs-dev] [PATCH v2] f2fs: add iostat latency tracking for direct IO
@ 2026-05-08 13:59 liujinbao1
2026-05-09 9:20 ` Chao Yu via Linux-f2fs-devel
0 siblings, 1 reply; 3+ messages in thread
From: liujinbao1 @ 2026-05-08 13:59 UTC (permalink / raw)
To: jaegeuk; +Cc: jinbaoliu365, shengyong1, liujinbao1, linux-f2fs-devel
From: liujinbao1 <liujinbao1@xiaomi.com>
F2FS did not collect iostat latency for direct IO reads and writes,
hook iomap_dio_ops.submit_io to bind an iostat context and record the
submission timestamp. Replace bi_end_io with f2fs_dio_end_bio() to
collect IO latency on completion before calling back to the original
iomap_dio_bio_end_io(), to add iostat latency tracking support for
F2FS DIO.
Signed-off-by: shengyong1 <shengyong1@xiaomi.com>
Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com>
---
v2:
- add f2fs_dio_iostat_start() to avoid duplicated code
and CONFIG_F2FS_IOSTAT guard
---
fs/f2fs/file.c | 35 +++++++++++++++++++++++++++++++++++
fs/f2fs/iostat.c | 2 +-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 091a9db29228..d35e3cf158bf 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -4790,6 +4790,30 @@ static bool f2fs_should_use_dio(struct inode *inode, struct kiocb *iocb,
return true;
}
+#ifdef CONFIG_F2FS_IOSTAT
+static void f2fs_dio_end_bio(struct bio *bio)
+{
+ struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+ void *orig_bi_private = iostat_ctx->post_read_ctx;
+
+ iostat_update_and_unbind_ctx(bio);
+ bio->bi_private = orig_bi_private;
+ iomap_dio_bio_end_io(bio);
+}
+
+static void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi, struct bio *bio)
+{
+ void *bi_private = bio->bi_private;
+
+ iostat_alloc_and_bind_ctx(sbi, bio, bi_private);
+ iostat_update_submit_ctx(bio, DATA);
+ bio->bi_end_io = f2fs_dio_end_bio;
+}
+#else
+static inline void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi,
+ struct bio *bio) {}
+#endif
+
static int f2fs_dio_read_end_io(struct kiocb *iocb, ssize_t size, int error,
unsigned int flags)
{
@@ -4802,8 +4826,18 @@ static int f2fs_dio_read_end_io(struct kiocb *iocb, ssize_t size, int error,
return 0;
}
+static void f2fs_dio_read_submit_io(const struct iomap_iter *iter,
+ struct bio *bio, loff_t file_offset)
+{
+ struct f2fs_sb_info *sbi = F2FS_I_SB(iter->inode);
+
+ f2fs_dio_iostat_start(sbi, bio);
+ blk_crypto_submit_bio(bio);
+}
+
static const struct iomap_dio_ops f2fs_iomap_dio_read_ops = {
.end_io = f2fs_dio_read_end_io,
+ .submit_io = f2fs_dio_read_submit_io,
};
static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
@@ -5082,6 +5116,7 @@ static void f2fs_dio_write_submit_io(const struct iomap_iter *iter,
enum temp_type temp = f2fs_get_segment_temp(sbi, type);
bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, DATA, temp);
+ f2fs_dio_iostat_start(sbi, bio);
blk_crypto_submit_bio(bio);
}
diff --git a/fs/f2fs/iostat.c b/fs/f2fs/iostat.c
index ae265e3e9b2c..232fdec036c1 100644
--- a/fs/f2fs/iostat.c
+++ b/fs/f2fs/iostat.c
@@ -254,7 +254,7 @@ static inline void __update_iostat_latency(struct bio_iostat_ctx *iostat_ctx,
struct iostat_lat_info *io_lat = sbi->iostat_io_lat;
unsigned long flags;
- if (!sbi->iostat_enable)
+ if (!sbi->iostat_enable || iostat_ctx->submit_ts == 0)
return;
ts_diff = jiffies - iostat_ctx->submit_ts;
--
2.43.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: add iostat latency tracking for direct IO
2026-05-08 13:59 [f2fs-dev] [PATCH v2] f2fs: add iostat latency tracking for direct IO liujinbao1
@ 2026-05-09 9:20 ` Chao Yu via Linux-f2fs-devel
2026-05-13 13:57 ` liujinbao1
0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-05-09 9:20 UTC (permalink / raw)
To: liujinbao1, jaegeuk; +Cc: shengyong1, liujinbao1, linux-f2fs-devel
On 5/8/26 21:59, liujinbao1 wrote:
> From: liujinbao1 <liujinbao1@xiaomi.com>
>
> F2FS did not collect iostat latency for direct IO reads and writes,
> hook iomap_dio_ops.submit_io to bind an iostat context and record the
> submission timestamp. Replace bi_end_io with f2fs_dio_end_bio() to
> collect IO latency on completion before calling back to the original
> iomap_dio_bio_end_io(), to add iostat latency tracking support for
> F2FS DIO.
>
> Signed-off-by: shengyong1 <shengyong1@xiaomi.com>
> Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com>
> ---
> v2:
> - add f2fs_dio_iostat_start() to avoid duplicated code
> and CONFIG_F2FS_IOSTAT guard
> ---
> fs/f2fs/file.c | 35 +++++++++++++++++++++++++++++++++++
> fs/f2fs/iostat.c | 2 +-
> 2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 091a9db29228..d35e3cf158bf 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -4790,6 +4790,30 @@ static bool f2fs_should_use_dio(struct inode *inode, struct kiocb *iocb,
> return true;
> }
>
> +#ifdef CONFIG_F2FS_IOSTAT
> +static void f2fs_dio_end_bio(struct bio *bio)
> +{
> + struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
> + void *orig_bi_private = iostat_ctx->post_read_ctx;
> +
> + iostat_update_and_unbind_ctx(bio);
> + bio->bi_private = orig_bi_private;
> + iomap_dio_bio_end_io(bio);
> +}
> +
> +static void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi, struct bio *bio)
> +{
> + void *bi_private = bio->bi_private;
> +
> + iostat_alloc_and_bind_ctx(sbi, bio, bi_private);
> + iostat_update_submit_ctx(bio, DATA);
> + bio->bi_end_io = f2fs_dio_end_bio;
> +}
> +#else
> +static inline void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi,
> + struct bio *bio) {}
> +#endif
> +
> static int f2fs_dio_read_end_io(struct kiocb *iocb, ssize_t size, int error,
> unsigned int flags)
> {
> @@ -4802,8 +4826,18 @@ static int f2fs_dio_read_end_io(struct kiocb *iocb, ssize_t size, int error,
> return 0;
> }
>
> +static void f2fs_dio_read_submit_io(const struct iomap_iter *iter,
> + struct bio *bio, loff_t file_offset)
> +{
> + struct f2fs_sb_info *sbi = F2FS_I_SB(iter->inode);
> +
> + f2fs_dio_iostat_start(sbi, bio);
> + blk_crypto_submit_bio(bio);
> +}
> +
> static const struct iomap_dio_ops f2fs_iomap_dio_read_ops = {
> .end_io = f2fs_dio_read_end_io,
> + .submit_io = f2fs_dio_read_submit_io,
> };
>
> static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
> @@ -5082,6 +5116,7 @@ static void f2fs_dio_write_submit_io(const struct iomap_iter *iter,
> enum temp_type temp = f2fs_get_segment_temp(sbi, type);
>
> bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, DATA, temp);
> + f2fs_dio_iostat_start(sbi, bio);
> blk_crypto_submit_bio(bio);
> }
>
> diff --git a/fs/f2fs/iostat.c b/fs/f2fs/iostat.c
> index ae265e3e9b2c..232fdec036c1 100644
> --- a/fs/f2fs/iostat.c
> +++ b/fs/f2fs/iostat.c
> @@ -254,7 +254,7 @@ static inline void __update_iostat_latency(struct bio_iostat_ctx *iostat_ctx,
> struct iostat_lat_info *io_lat = sbi->iostat_io_lat;
> unsigned long flags;
>
> - if (!sbi->iostat_enable)
> + if (!sbi->iostat_enable || iostat_ctx->submit_ts == 0)
Which path we will see zeroed .submit_ts?
Thanks,
> return;
>
> ts_diff = jiffies - iostat_ctx->submit_ts;
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: add iostat latency tracking for direct IO
2026-05-09 9:20 ` Chao Yu via Linux-f2fs-devel
@ 2026-05-13 13:57 ` liujinbao1
0 siblings, 0 replies; 3+ messages in thread
From: liujinbao1 @ 2026-05-13 13:57 UTC (permalink / raw)
To: Chao Yu, jaegeuk; +Cc: shengyong1, liujinbao1, linux-f2fs-devel
在 2026/5/9 17:20, Chao Yu 写道:
> On 5/8/26 21:59, liujinbao1 wrote:
>> From: liujinbao1 <liujinbao1@xiaomi.com>
>>
>> F2FS did not collect iostat latency for direct IO reads and writes,
>> hook iomap_dio_ops.submit_io to bind an iostat context and record the
>> submission timestamp. Replace bi_end_io with f2fs_dio_end_bio() to
>> collect IO latency on completion before calling back to the original
>> iomap_dio_bio_end_io(), to add iostat latency tracking support for
>> F2FS DIO.
>>
>> Signed-off-by: shengyong1 <shengyong1@xiaomi.com>
>> Signed-off-by: liujinbao1 <liujinbao1@xiaomi.com>
>> ---
>> v2:
>> - add f2fs_dio_iostat_start() to avoid duplicated code
>> and CONFIG_F2FS_IOSTAT guard
>> ---
>> fs/f2fs/file.c | 35 +++++++++++++++++++++++++++++++++++
>> fs/f2fs/iostat.c | 2 +-
>> 2 files changed, 36 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index 091a9db29228..d35e3cf158bf 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -4790,6 +4790,30 @@ static bool f2fs_should_use_dio(struct inode
>> *inode, struct kiocb *iocb,
>> return true;
>> }
>> +#ifdef CONFIG_F2FS_IOSTAT
>> +static void f2fs_dio_end_bio(struct bio *bio)
>> +{
>> + struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
>> + void *orig_bi_private = iostat_ctx->post_read_ctx;
>> +
>> + iostat_update_and_unbind_ctx(bio);
>> + bio->bi_private = orig_bi_private;
>> + iomap_dio_bio_end_io(bio);
>> +}
>> +
>> +static void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi, struct
>> bio *bio)
>> +{
>> + void *bi_private = bio->bi_private;
>> +
>> + iostat_alloc_and_bind_ctx(sbi, bio, bi_private);
>> + iostat_update_submit_ctx(bio, DATA);
>> + bio->bi_end_io = f2fs_dio_end_bio;
>> +}
>> +#else
>> +static inline void f2fs_dio_iostat_start(struct f2fs_sb_info *sbi,
>> + struct bio *bio) {}
>> +#endif
>> +
>> static int f2fs_dio_read_end_io(struct kiocb *iocb, ssize_t size,
>> int error,
>> unsigned int flags)
>> {
>> @@ -4802,8 +4826,18 @@ static int f2fs_dio_read_end_io(struct kiocb
>> *iocb, ssize_t size, int error,
>> return 0;
>> }
>> +static void f2fs_dio_read_submit_io(const struct iomap_iter *iter,
>> + struct bio *bio, loff_t file_offset)
>> +{
>> + struct f2fs_sb_info *sbi = F2FS_I_SB(iter->inode);
>> +
>> + f2fs_dio_iostat_start(sbi, bio);
>> + blk_crypto_submit_bio(bio);
>> +}
>> +
>> static const struct iomap_dio_ops f2fs_iomap_dio_read_ops = {
>> .end_io = f2fs_dio_read_end_io,
>> + .submit_io = f2fs_dio_read_submit_io,
>> };
>> static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct
>> iov_iter *to)
>> @@ -5082,6 +5116,7 @@ static void f2fs_dio_write_submit_io(const
>> struct iomap_iter *iter,
>> enum temp_type temp = f2fs_get_segment_temp(sbi, type);
>> bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi, DATA, temp);
>> + f2fs_dio_iostat_start(sbi, bio);
>> blk_crypto_submit_bio(bio);
>> }
>> diff --git a/fs/f2fs/iostat.c b/fs/f2fs/iostat.c
>> index ae265e3e9b2c..232fdec036c1 100644
>> --- a/fs/f2fs/iostat.c
>> +++ b/fs/f2fs/iostat.c
>> @@ -254,7 +254,7 @@ static inline void __update_iostat_latency(struct
>> bio_iostat_ctx *iostat_ctx,
>> struct iostat_lat_info *io_lat = sbi->iostat_io_lat;
>> unsigned long flags;
>> - if (!sbi->iostat_enable)
>> + if (!sbi->iostat_enable || iostat_ctx->submit_ts == 0)
>
> Which path we will see zeroed .submit_ts?
>
> Thanks,
>
After careful investigation, this scenario should not exist. I will
modify the code.
thanks
>> return;
>> ts_diff = jiffies - iostat_ctx->submit_ts;
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-13 13:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-08 13:59 [f2fs-dev] [PATCH v2] f2fs: add iostat latency tracking for direct IO liujinbao1
2026-05-09 9:20 ` Chao Yu via Linux-f2fs-devel
2026-05-13 13:57 ` liujinbao1
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox