提交 1ee94df3 编写于 作者: J Jens Axboe 提交者: Cheng Jian

io-wq: make the io_wq ref counted

mainline inclusion
from mainline-5.6-rc1
commit 848f7e18
category: feature
bugzilla: https://bugzilla.openeuler.org/show_bug.cgi?id=27
CVE: NA
---------------------------

In preparation for sharing an io-wq across different users, add a
reference count that manages destruction of it.
Reviewed-by: NPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: Nyangerkun <yangerkun@huawei.com>
Reviewed-by: Nzhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
上级 c30349de
...@@ -114,6 +114,8 @@ struct io_wq { ...@@ -114,6 +114,8 @@ struct io_wq {
struct mm_struct *mm; struct mm_struct *mm;
refcount_t refs; refcount_t refs;
struct completion done; struct completion done;
refcount_t use_refs;
}; };
static bool io_worker_get(struct io_worker *worker) static bool io_worker_get(struct io_worker *worker)
...@@ -1074,6 +1076,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data) ...@@ -1074,6 +1076,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err;
} }
refcount_set(&wq->use_refs, 1);
reinit_completion(&wq->done); reinit_completion(&wq->done);
return wq; return wq;
} }
...@@ -1094,7 +1097,7 @@ static bool io_wq_worker_wake(struct io_worker *worker, void *data) ...@@ -1094,7 +1097,7 @@ static bool io_wq_worker_wake(struct io_worker *worker, void *data)
return false; return false;
} }
void io_wq_destroy(struct io_wq *wq) static void __io_wq_destroy(struct io_wq *wq)
{ {
int node; int node;
...@@ -1114,3 +1117,9 @@ void io_wq_destroy(struct io_wq *wq) ...@@ -1114,3 +1117,9 @@ void io_wq_destroy(struct io_wq *wq)
kfree(wq->wqes); kfree(wq->wqes);
kfree(wq); kfree(wq);
} }
void io_wq_destroy(struct io_wq *wq)
{
if (refcount_dec_and_test(&wq->use_refs))
__io_wq_destroy(wq);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册