2022-12-12 06:02:29

by 李扬韬

[permalink] [raw]
Subject: [PATCH] f2fs: add iostat support for FS_DISCARD_IO

Just like other data we count uses the number of bytes as the basic
unit, but discard uses the number of cmds as the statistical unit. In
fact, the discard command contains the number of blocks. In order to
avoid breaking its usage of application, let's keeping FS_DISCARD
as it is, and add FS_DISCARD_IO to account discard bytes.

Suggested-by: Chao Yu <[email protected]>
Signed-off-by: Yangtao Li <[email protected]>
---
fs/f2fs/f2fs.h | 1 +
fs/f2fs/iostat.c | 5 +++++
fs/f2fs/segment.c | 2 +-
3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e8953c3dc81a..ef0043003bf8 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1193,6 +1193,7 @@ enum iostat_type {
FS_META_READ_IO, /* meta read IOs */

/* other */
+ FS_DISCARD_IO, /* discard IOs */
FS_DISCARD, /* discard */
NR_IO_TYPE,
};
diff --git a/fs/f2fs/iostat.c b/fs/f2fs/iostat.c
index 3166a8939ed4..3d2f0b69cdda 100644
--- a/fs/f2fs/iostat.c
+++ b/fs/f2fs/iostat.c
@@ -89,6 +89,8 @@ int __maybe_unused iostat_info_seq_show(struct seq_file *seq, void *offset)

/* print other IOs */
seq_puts(seq, "[OTHER]\n");
+ seq_printf(seq, "fs discard bytes: %-16llu\n",
+ sbi->rw_iostat[FS_DISCARD_IO]);
seq_printf(seq, "fs discard: %-16llu\n",
sbi->rw_iostat[FS_DISCARD]);

@@ -180,6 +182,9 @@ void f2fs_update_iostat(struct f2fs_sb_info *sbi, struct inode *inode,
spin_lock_irqsave(&sbi->iostat_lock, flags);
sbi->rw_iostat[type] += io_bytes;

+ if (type == FS_DISCARD_IO)
+ sbi->rw_iostat[FS_DISCARD]++;
+
if (type == APP_BUFFERED_IO || type == APP_DIRECT_IO)
sbi->rw_iostat[APP_WRITE_IO] += io_bytes;

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index dee712f7225f..bd02631f9681 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1187,7 +1187,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,

atomic_inc(&dcc->issued_discard);

- f2fs_update_iostat(sbi, NULL, FS_DISCARD, 1);
+ f2fs_update_iostat(sbi, NULL, FS_DISCARD_IO, len * F2FS_BLKSIZE);

lstart += len;
start += len;
--
2.25.1


2022-12-12 10:43:03

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH] f2fs: add iostat support for FS_DISCARD_IO

On 2022/12/12 13:47, Yangtao Li wrote:
> Just like other data we count uses the number of bytes as the basic
> unit, but discard uses the number of cmds as the statistical unit. In
> fact, the discard command contains the number of blocks. In order to
> avoid breaking its usage of application, let's keeping FS_DISCARD
> as it is, and add FS_DISCARD_IO to account discard bytes.
>
> Suggested-by: Chao Yu <[email protected]>
> Signed-off-by: Yangtao Li <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,

2022-12-12 23:54:51

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [PATCH] f2fs: add iostat support for FS_DISCARD_IO

Please check the previous comment.

On 12/12, Chao Yu wrote:
> On 2022/12/12 13:47, Yangtao Li wrote:
> > Just like other data we count uses the number of bytes as the basic
> > unit, but discard uses the number of cmds as the statistical unit. In
> > fact, the discard command contains the number of blocks. In order to
> > avoid breaking its usage of application, let's keeping FS_DISCARD
> > as it is, and add FS_DISCARD_IO to account discard bytes.
> >
> > Suggested-by: Chao Yu <[email protected]>
> > Signed-off-by: Yangtao Li <[email protected]>
>
> Reviewed-by: Chao Yu <[email protected]>
>
> Thanks,