Commit 6afae633 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: wait discard IO completion without cmd_lock held

Wait discard IO completion outside cmd_lock to avoid long latency
of holding cmd_lock in IO busy scenario.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent e31b9821
...@@ -997,17 +997,34 @@ static void __wait_discard_cmd(struct f2fs_sb_info *sbi, bool wait_cond) ...@@ -997,17 +997,34 @@ static void __wait_discard_cmd(struct f2fs_sb_info *sbi, bool wait_cond)
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->wait_list); struct list_head *wait_list = &(dcc->wait_list);
struct discard_cmd *dc, *tmp; struct discard_cmd *dc, *tmp;
bool need_wait;
next:
need_wait = false;
mutex_lock(&dcc->cmd_lock); mutex_lock(&dcc->cmd_lock);
list_for_each_entry_safe(dc, tmp, wait_list, list) { list_for_each_entry_safe(dc, tmp, wait_list, list) {
if (!wait_cond || dc->state == D_DONE) { if (!wait_cond || (dc->state == D_DONE && !dc->ref)) {
if (dc->ref)
continue;
wait_for_completion_io(&dc->wait); wait_for_completion_io(&dc->wait);
__remove_discard_cmd(sbi, dc); __remove_discard_cmd(sbi, dc);
} else {
dc->ref++;
need_wait = true;
break;
} }
} }
mutex_unlock(&dcc->cmd_lock); mutex_unlock(&dcc->cmd_lock);
if (need_wait) {
wait_for_completion_io(&dc->wait);
mutex_lock(&dcc->cmd_lock);
f2fs_bug_on(sbi, dc->state != D_DONE);
dc->ref--;
if (!dc->ref)
__remove_discard_cmd(sbi, dc);
mutex_unlock(&dcc->cmd_lock);
goto next;
}
} }
/* This should be covered by global mutex, &sit_i->sentry_lock */ /* This should be covered by global mutex, &sit_i->sentry_lock */
......
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