Commit 22d375dd authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: split discard_cmd_list

Split discard_cmd_list to discard_{pend,wait}_list, so while sending/waiting
discard command, we can avoid traversing unneeded entries in original list.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent c6f82fe9
...@@ -210,7 +210,8 @@ struct discard_cmd_control { ...@@ -210,7 +210,8 @@ struct discard_cmd_control {
struct task_struct *f2fs_issue_discard; /* discard thread */ struct task_struct *f2fs_issue_discard; /* discard thread */
struct list_head discard_entry_list; /* 4KB discard entry list */ struct list_head discard_entry_list; /* 4KB discard entry list */
int nr_discards; /* # of discards in the list */ int nr_discards; /* # of discards in the list */
struct list_head discard_cmd_list; /* discard cmd list */ struct list_head discard_pend_list; /* store pending entries */
struct list_head discard_wait_list; /* store on-flushing entries */
wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */
struct mutex cmd_lock; struct mutex cmd_lock;
int max_discards; /* max. discards to be issued */ int max_discards; /* max. discards to be issued */
......
...@@ -677,7 +677,7 @@ static void __add_discard_cmd(struct f2fs_sb_info *sbi, ...@@ -677,7 +677,7 @@ static void __add_discard_cmd(struct f2fs_sb_info *sbi,
block_t start, block_t len) block_t start, block_t len)
{ {
struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
struct list_head *cmd_list = &(dcc->discard_cmd_list); struct list_head *pend_list = &(dcc->discard_pend_list);
struct discard_cmd *dc; struct discard_cmd *dc;
dc = f2fs_kmem_cache_alloc(discard_cmd_slab, GFP_NOFS); dc = f2fs_kmem_cache_alloc(discard_cmd_slab, GFP_NOFS);
...@@ -691,7 +691,7 @@ static void __add_discard_cmd(struct f2fs_sb_info *sbi, ...@@ -691,7 +691,7 @@ static void __add_discard_cmd(struct f2fs_sb_info *sbi,
init_completion(&dc->wait); init_completion(&dc->wait);
mutex_lock(&dcc->cmd_lock); mutex_lock(&dcc->cmd_lock);
list_add_tail(&dc->list, cmd_list); list_add_tail(&dc->list, pend_list);
mutex_unlock(&dcc->cmd_lock); mutex_unlock(&dcc->cmd_lock);
atomic_inc(&dcc->discard_cmd_cnt); atomic_inc(&dcc->discard_cmd_cnt);
...@@ -747,6 +747,7 @@ static void __submit_discard_cmd(struct f2fs_sb_info *sbi, ...@@ -747,6 +747,7 @@ static void __submit_discard_cmd(struct f2fs_sb_info *sbi,
bio->bi_end_io = f2fs_submit_discard_endio; bio->bi_end_io = f2fs_submit_discard_endio;
bio->bi_opf |= REQ_SYNC; bio->bi_opf |= REQ_SYNC;
submit_bio(bio); submit_bio(bio);
list_move_tail(&dc->list, &dcc->discard_wait_list);
} }
} else { } else {
__remove_discard_cmd(sbi, dc); __remove_discard_cmd(sbi, dc);
...@@ -793,31 +794,37 @@ static void __punch_discard_cmd(struct f2fs_sb_info *sbi, ...@@ -793,31 +794,37 @@ static void __punch_discard_cmd(struct f2fs_sb_info *sbi,
void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
{ {
struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
struct list_head *wait_list = &(dcc->discard_cmd_list); struct list_head *pend_list = &(dcc->discard_pend_list);
struct list_head *wait_list = &(dcc->discard_wait_list);
struct discard_cmd *dc, *tmp; struct discard_cmd *dc, *tmp;
struct blk_plug plug; struct blk_plug plug;
mutex_lock(&dcc->cmd_lock); mutex_lock(&dcc->cmd_lock);
blk_start_plug(&plug); if (blkaddr == NULL_ADDR)
goto release_discard;
list_for_each_entry_safe(dc, tmp, wait_list, list) {
if (blkaddr == NULL_ADDR) { list_for_each_entry_safe(dc, tmp, pend_list, list) {
__submit_discard_cmd(sbi, dc); if (dc->lstart <= blkaddr && blkaddr < dc->lstart + dc->len)
continue; __punch_discard_cmd(sbi, dc, blkaddr);
} }
list_for_each_entry_safe(dc, tmp, wait_list, list) {
if (dc->lstart <= blkaddr && blkaddr < dc->lstart + dc->len) { if (dc->lstart <= blkaddr && blkaddr < dc->lstart + dc->len) {
if (dc->state == D_SUBMIT) if (dc->state == D_SUBMIT)
wait_for_completion_io(&dc->wait); wait_for_completion_io(&dc->wait);
__punch_discard_cmd(sbi, dc, blkaddr); __punch_discard_cmd(sbi, dc, blkaddr);
} }
} }
blk_finish_plug(&plug);
release_discard:
/* this comes from f2fs_put_super */ /* this comes from f2fs_put_super */
if (blkaddr == NULL_ADDR) { if (blkaddr == NULL_ADDR) {
blk_start_plug(&plug);
list_for_each_entry_safe(dc, tmp, pend_list, list)
__submit_discard_cmd(sbi, dc);
blk_finish_plug(&plug);
list_for_each_entry_safe(dc, tmp, wait_list, list) { list_for_each_entry_safe(dc, tmp, wait_list, list) {
wait_for_completion_io(&dc->wait); wait_for_completion_io(&dc->wait);
__remove_discard_cmd(sbi, dc); __remove_discard_cmd(sbi, dc);
...@@ -831,7 +838,8 @@ static int issue_discard_thread(void *data) ...@@ -831,7 +838,8 @@ static int issue_discard_thread(void *data)
struct f2fs_sb_info *sbi = data; struct f2fs_sb_info *sbi = data;
struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
wait_queue_head_t *q = &dcc->discard_wait_queue; wait_queue_head_t *q = &dcc->discard_wait_queue;
struct list_head *cmd_list = &dcc->discard_cmd_list; struct list_head *pend_list = &dcc->discard_pend_list;
struct list_head *wait_list = &dcc->discard_wait_list;
struct discard_cmd *dc, *tmp; struct discard_cmd *dc, *tmp;
struct blk_plug plug; struct blk_plug plug;
int iter = 0; int iter = 0;
...@@ -842,13 +850,17 @@ static int issue_discard_thread(void *data) ...@@ -842,13 +850,17 @@ static int issue_discard_thread(void *data)
blk_start_plug(&plug); blk_start_plug(&plug);
mutex_lock(&dcc->cmd_lock); mutex_lock(&dcc->cmd_lock);
list_for_each_entry_safe(dc, tmp, cmd_list, list) { list_for_each_entry_safe(dc, tmp, pend_list, list) {
f2fs_bug_on(sbi, dc->state != D_PREP);
if (is_idle(sbi)) if (is_idle(sbi))
__submit_discard_cmd(sbi, dc); __submit_discard_cmd(sbi, dc);
if (dc->state == D_PREP && iter++ > DISCARD_ISSUE_RATE) if (iter++ > DISCARD_ISSUE_RATE)
break; break;
}
list_for_each_entry_safe(dc, tmp, wait_list, list) {
if (dc->state == D_DONE) if (dc->state == D_DONE)
__remove_discard_cmd(sbi, dc); __remove_discard_cmd(sbi, dc);
} }
...@@ -859,8 +871,8 @@ static int issue_discard_thread(void *data) ...@@ -859,8 +871,8 @@ static int issue_discard_thread(void *data)
iter = 0; iter = 0;
congestion_wait(BLK_RW_SYNC, HZ/50); congestion_wait(BLK_RW_SYNC, HZ/50);
wait_event_interruptible(*q, wait_event_interruptible(*q, kthread_should_stop() ||
kthread_should_stop() || !list_empty(&dcc->discard_cmd_list)); !list_empty(pend_list) || !list_empty(wait_list));
goto repeat; goto repeat;
} }
...@@ -1152,7 +1164,8 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi) ...@@ -1152,7 +1164,8 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
return -ENOMEM; return -ENOMEM;
INIT_LIST_HEAD(&dcc->discard_entry_list); INIT_LIST_HEAD(&dcc->discard_entry_list);
INIT_LIST_HEAD(&dcc->discard_cmd_list); INIT_LIST_HEAD(&dcc->discard_pend_list);
INIT_LIST_HEAD(&dcc->discard_wait_list);
mutex_init(&dcc->cmd_lock); mutex_init(&dcc->cmd_lock);
atomic_set(&dcc->issued_discard, 0); atomic_set(&dcc->issued_discard, 0);
atomic_set(&dcc->issing_discard, 0); atomic_set(&dcc->issing_discard, 0);
......
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