Commit 4e6a8d9b authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: relax async discard commands more

This patch relaxes async discard commands to avoid waiting its end_io during
checkpoint.
Instead of waiting them during checkpoint, it will be done when actually reusing
them.

Test on initial partition of nvme drive.

 # time fstrim /mnt/test

Before : 6.158s
After : 4.822s
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent bb95d9ab
...@@ -1254,7 +1254,6 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1254,7 +1254,6 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
f2fs_bug_on(sbi, prefree_segments(sbi)); f2fs_bug_on(sbi, prefree_segments(sbi));
flush_sit_entries(sbi, cpc); flush_sit_entries(sbi, cpc);
clear_prefree_segments(sbi, cpc); clear_prefree_segments(sbi, cpc);
f2fs_wait_all_discard_bio(sbi);
unblock_operations(sbi); unblock_operations(sbi);
goto out; goto out;
} }
...@@ -1273,12 +1272,10 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ...@@ -1273,12 +1272,10 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
/* unlock all the fs_lock[] in do_checkpoint() */ /* unlock all the fs_lock[] in do_checkpoint() */
err = do_checkpoint(sbi, cpc); err = do_checkpoint(sbi, cpc);
if (err) { if (err)
release_discard_addrs(sbi); release_discard_addrs(sbi);
} else { else
clear_prefree_segments(sbi, cpc); clear_prefree_segments(sbi, cpc);
f2fs_wait_all_discard_bio(sbi);
}
unblock_operations(sbi); unblock_operations(sbi);
stat_inc_cp_count(sbi->stat_info); stat_inc_cp_count(sbi->stat_info);
......
...@@ -183,6 +183,8 @@ struct discard_entry { ...@@ -183,6 +183,8 @@ struct discard_entry {
struct bio_entry { struct bio_entry {
struct list_head list; struct list_head list;
block_t lstart;
block_t len;
struct bio *bio; struct bio *bio;
struct completion event; struct completion event;
int error; int error;
...@@ -2111,7 +2113,7 @@ void destroy_flush_cmd_control(struct f2fs_sb_info *, bool); ...@@ -2111,7 +2113,7 @@ void destroy_flush_cmd_control(struct f2fs_sb_info *, bool);
void invalidate_blocks(struct f2fs_sb_info *, block_t); void invalidate_blocks(struct f2fs_sb_info *, block_t);
bool is_checkpointed_data(struct f2fs_sb_info *, block_t); bool is_checkpointed_data(struct f2fs_sb_info *, block_t);
void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t); void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
void f2fs_wait_all_discard_bio(struct f2fs_sb_info *); void f2fs_wait_discard_bio(struct f2fs_sb_info *, block_t);
void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *); void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *);
void release_discard_addrs(struct f2fs_sb_info *); void release_discard_addrs(struct f2fs_sb_info *);
int npages_for_summary_flush(struct f2fs_sb_info *, bool); int npages_for_summary_flush(struct f2fs_sb_info *, bool);
......
...@@ -625,20 +625,23 @@ static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno) ...@@ -625,20 +625,23 @@ static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno)
} }
static struct bio_entry *__add_bio_entry(struct f2fs_sb_info *sbi, static struct bio_entry *__add_bio_entry(struct f2fs_sb_info *sbi,
struct bio *bio) struct bio *bio, block_t lstart, block_t len)
{ {
struct list_head *wait_list = &(SM_I(sbi)->wait_list); struct list_head *wait_list = &(SM_I(sbi)->wait_list);
struct bio_entry *be = f2fs_kmem_cache_alloc(bio_entry_slab, GFP_NOFS); struct bio_entry *be = f2fs_kmem_cache_alloc(bio_entry_slab, GFP_NOFS);
INIT_LIST_HEAD(&be->list); INIT_LIST_HEAD(&be->list);
be->bio = bio; be->bio = bio;
be->lstart = lstart;
be->len = len;
init_completion(&be->event); init_completion(&be->event);
list_add_tail(&be->list, wait_list); list_add_tail(&be->list, wait_list);
return be; return be;
} }
void f2fs_wait_all_discard_bio(struct f2fs_sb_info *sbi) /* This should be covered by global mutex, &sit_i->sentry_lock */
void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
{ {
struct list_head *wait_list = &(SM_I(sbi)->wait_list); struct list_head *wait_list = &(SM_I(sbi)->wait_list);
struct bio_entry *be, *tmp; struct bio_entry *be, *tmp;
...@@ -647,7 +650,15 @@ void f2fs_wait_all_discard_bio(struct f2fs_sb_info *sbi) ...@@ -647,7 +650,15 @@ void f2fs_wait_all_discard_bio(struct f2fs_sb_info *sbi)
struct bio *bio = be->bio; struct bio *bio = be->bio;
int err; int err;
wait_for_completion_io(&be->event); if (!completion_done(&be->event)) {
if ((be->lstart <= blkaddr &&
blkaddr < be->lstart + be->len) ||
blkaddr == NULL_ADDR)
wait_for_completion_io(&be->event);
else
continue;
}
err = be->error; err = be->error;
if (err == -EOPNOTSUPP) if (err == -EOPNOTSUPP)
err = 0; err = 0;
...@@ -675,6 +686,7 @@ static int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, ...@@ -675,6 +686,7 @@ static int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi,
struct block_device *bdev, block_t blkstart, block_t blklen) struct block_device *bdev, block_t blkstart, block_t blklen)
{ {
struct bio *bio = NULL; struct bio *bio = NULL;
block_t lblkstart = blkstart;
int err; int err;
trace_f2fs_issue_discard(sbi->sb, blkstart, blklen); trace_f2fs_issue_discard(sbi->sb, blkstart, blklen);
...@@ -689,14 +701,14 @@ static int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi, ...@@ -689,14 +701,14 @@ static int __f2fs_issue_discard_async(struct f2fs_sb_info *sbi,
SECTOR_FROM_BLOCK(blklen), SECTOR_FROM_BLOCK(blklen),
GFP_NOFS, 0, &bio); GFP_NOFS, 0, &bio);
if (!err && bio) { if (!err && bio) {
struct bio_entry *be = __add_bio_entry(sbi, bio); struct bio_entry *be = __add_bio_entry(sbi, bio,
lblkstart, blklen);
bio->bi_private = be; bio->bi_private = be;
bio->bi_end_io = f2fs_submit_bio_wait_endio; bio->bi_end_io = f2fs_submit_bio_wait_endio;
bio->bi_opf |= REQ_SYNC; bio->bi_opf |= REQ_SYNC;
submit_bio(bio); submit_bio(bio);
} }
return err; return err;
} }
...@@ -1575,6 +1587,8 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, ...@@ -1575,6 +1587,8 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
*new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); *new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
f2fs_wait_discard_bio(sbi, *new_blkaddr);
/* /*
* __add_sum_entry should be resided under the curseg_mutex * __add_sum_entry should be resided under the curseg_mutex
* because, this function updates a summary entry in the * because, this function updates a summary entry in the
......
...@@ -770,6 +770,9 @@ static void f2fs_put_super(struct super_block *sb) ...@@ -770,6 +770,9 @@ static void f2fs_put_super(struct super_block *sb)
write_checkpoint(sbi, &cpc); write_checkpoint(sbi, &cpc);
} }
/* be sure to wait for any on-going discard commands */
f2fs_wait_discard_bio(sbi, NULL_ADDR);
/* write_checkpoint can update stat informaion */ /* write_checkpoint can update stat informaion */
f2fs_destroy_stats(sbi); f2fs_destroy_stats(sbi);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment