aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChao Yu <yuchao0@huawei.com>2017-04-26 17:39:54 +0800
committerMoyster <oysterized@gmail.com>2017-05-21 18:43:23 +0200
commitddde1fbb01f91696ae48700932da22fb279339f2 (patch)
tree43c3a85c6ef20c026725a5dfcfdb08a4c8f600d7
parentbb0a81afc17c347ce89373af79025cd34419fa0f (diff)
f2fs: don't hold cmd_lock during waiting discard command
Previously, with protection of cmd_lock, we will wait for end io of discard command which potentially may lead long latency, making worse concurrency. So, in this patch, we try to add reference into discard entry to prevent the entry being released by other thread, then we can avoid holding global cmd_lock during waiting discard to finish. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/f2fs.h1
-rw-r--r--fs/f2fs/segment.c25
2 files changed, 21 insertions, 5 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index b306d333a..ae3a28b43 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -318,6 +318,7 @@ struct discard_cmd {
struct list_head list; /* command list */
struct completion wait; /* compleation */
struct block_device *bdev; /* bdev */
+ unsigned short ref; /* reference count */
int state; /* state */
int error; /* bio error */
};
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 993ef95f8..64b98afa8 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -747,6 +747,7 @@ static struct discard_cmd *__create_discard_cmd(struct f2fs_sb_info *sbi,
dc->lstart = lstart;
dc->start = start;
dc->len = len;
+ dc->ref = 0;
dc->state = D_PREP;
dc->error = 0;
init_completion(&dc->wait);
@@ -1145,6 +1146,8 @@ static void __wait_discard_cmd(struct f2fs_sb_info *sbi, bool wait_cond)
mutex_lock(&dcc->cmd_lock);
list_for_each_entry_safe(dc, tmp, wait_list, list) {
if (!wait_cond || dc->state == D_DONE) {
+ if (dc->ref)
+ continue;
wait_for_completion_io(&dc->wait);
__remove_discard_cmd(sbi, dc);
}
@@ -1157,17 +1160,29 @@ 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 *dc;
+ bool need_wait = false;
mutex_lock(&dcc->cmd_lock);
-
dc = (struct discard_cmd *)__lookup_rb_tree(&dcc->root, NULL, blkaddr);
if (dc) {
- if (dc->state != D_PREP)
- wait_for_completion_io(&dc->wait);
- __punch_discard_cmd(sbi, dc, blkaddr);
+ if (dc->state == D_PREP) {
+ __punch_discard_cmd(sbi, dc, blkaddr);
+ } else {
+ dc->ref++;
+ need_wait = true;
+ }
}
-
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);
+ }
}
/* This comes from f2fs_put_super */