[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221129041524.81235-2-frank.li@vivo.com>
Date: Tue, 29 Nov 2022 12:15:24 +0800
From: Yangtao Li <frank.li@...o.com>
To: jaegeuk@...nel.org, chao@...nel.org
Cc: linux-f2fs-devel@...ts.sourceforge.net,
linux-kernel@...r.kernel.org, Yangtao Li <frank.li@...o.com>
Subject: [PATCH 2/2] f2fs: add support for counting the average time of submit discard cmd
This patch adds support for counting the average time of submit discard
command, and we can see its value in debugfs.
Signed-off-by: Yangtao Li <frank.li@...o.com>
---
fs/f2fs/debug.c | 7 +++++--
fs/f2fs/f2fs.h | 5 +++++
fs/f2fs/segment.c | 18 ++++++++++++++++--
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index 733b1bd37404..eed3edfc5faf 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -109,6 +109,9 @@ static void update_general_status(struct f2fs_sb_info *sbi)
llist_empty(&SM_I(sbi)->fcc_info->issue_list);
}
if (SM_I(sbi)->dcc_info) {
+ struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
+
+ si->discard_avg = dcc->discard_time_avg;
si->nr_discarded =
atomic_read(&SM_I(sbi)->dcc_info->issued_discard);
si->nr_discarding =
@@ -510,8 +513,8 @@ static int stat_show(struct seq_file *s, void *v)
si->nr_wb_cp_data, si->nr_wb_data,
si->nr_flushing, si->nr_flushed,
si->flush_list_empty);
- seq_printf(s, "Discard: (%4d %4d)) cmd: %4d undiscard:%4u\n",
- si->nr_discarding, si->nr_discarded,
+ seq_printf(s, "Discard: (%4d %4d, avg:%4lldns)) cmd: %4d undiscard:%4u\n",
+ si->nr_discarding, si->nr_discarded, ktime_to_us(si->discard_avg),
si->nr_discard_cmd, si->undiscard_blks);
seq_printf(s, " - atomic IO: %4d (Max. %4d)\n",
si->aw_cnt, si->max_aw_cnt);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index eb8c27c4e5fc..5a99759d10ac 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -370,6 +370,8 @@ struct discard_cmd {
int error; /* bio error */
spinlock_t lock; /* for state/bio_ref updating */
unsigned short bio_ref; /* bio reference count */
+ struct discard_cmd_control *dcc; /* global discard cmd control */
+ ktime_t submit_start; /* submit start time */
};
enum {
@@ -414,6 +416,8 @@ struct discard_cmd_control {
unsigned int max_ordered_discard; /* maximum discard granularity issued by lba order */
unsigned int undiscard_blks; /* # of undiscard blocks */
unsigned int next_pos; /* next discard position */
+ spinlock_t discard_time_lock; /* for discard time statistics */
+ ktime_t discard_time_avg; /* issued discard cmd avg time */
atomic_t issued_discard; /* # of issued discard */
atomic_t queued_discard; /* # of queued discard */
atomic_t discard_cmd_cnt; /* # of cached cmd count */
@@ -3882,6 +3886,7 @@ struct f2fs_stat_info {
int nr_dio_read, nr_dio_write;
unsigned int io_skip_bggc, other_skip_bggc;
int nr_flushing, nr_flushed, flush_list_empty;
+ ktime_t discard_avg;
int nr_discarding, nr_discarded;
int nr_discard_cmd;
unsigned int undiscard_blks;
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 9486ca49ecb1..bc96b1afb308 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -931,6 +931,7 @@ static struct discard_cmd *__create_discard_cmd(struct f2fs_sb_info *sbi,
list_add_tail(&dc->list, pend_list);
spin_lock_init(&dc->lock);
dc->bio_ref = 0;
+ dc->dcc = dcc;
atomic_inc(&dcc->discard_cmd_cnt);
dcc->undiscard_blks += len;
@@ -1000,9 +1001,13 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi,
static void f2fs_submit_discard_endio(struct bio *bio)
{
struct discard_cmd *dc = (struct discard_cmd *)bio->bi_private;
+ struct discard_cmd_control *dcc = dc->dcc;
unsigned long flags;
+ ktime_t submit_time;
+ int nr_discarded;
spin_lock_irqsave(&dc->lock, flags);
+ submit_time = ktime_sub(ktime_get(), dc->submit_start);
if (!dc->error)
dc->error = blk_status_to_errno(bio->bi_status);
dc->bio_ref--;
@@ -1012,6 +1017,14 @@ static void f2fs_submit_discard_endio(struct bio *bio)
}
spin_unlock_irqrestore(&dc->lock, flags);
bio_put(bio);
+
+ spin_lock_irqsave(&dcc->discard_time_lock, flags);
+ nr_discarded = atomic_read(&dcc->issued_discard);
+ dcc->discard_time_avg = div_u64(ktime_add(nr_discarded * dcc->discard_time_avg,
+ submit_time),
+ nr_discarded + 1);
+ atomic_inc(&dcc->issued_discard);
+ spin_unlock_irqrestore(&dcc->discard_time_lock, flags);
}
static void __check_sit_bitmap(struct f2fs_sb_info *sbi,
@@ -1160,6 +1173,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
* right away
*/
spin_lock_irqsave(&dc->lock, flags);
+ dc->submit_start = ktime_get();
if (last)
dc->state = D_SUBMIT;
else
@@ -1179,8 +1193,6 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
bio->bi_opf |= flag;
submit_bio(bio);
- atomic_inc(&dcc->issued_discard);
-
f2fs_update_iostat(sbi, NULL, FS_DISCARD, 1);
lstart += len;
@@ -2070,9 +2082,11 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
INIT_LIST_HEAD(&dcc->wait_list);
INIT_LIST_HEAD(&dcc->fstrim_list);
mutex_init(&dcc->cmd_lock);
+ spin_lock_init(&dcc->discard_time_lock);
atomic_set(&dcc->issued_discard, 0);
atomic_set(&dcc->queued_discard, 0);
atomic_set(&dcc->discard_cmd_cnt, 0);
+ dcc->discard_time_avg = 0;
dcc->nr_discards = 0;
dcc->max_discards = MAIN_SEGS(sbi) << sbi->log_blocks_per_seg;
dcc->max_discard_request = DEF_MAX_DISCARD_REQUEST;
--
2.25.1
Powered by blists - more mailing lists