From f432a69bfa99e599bea79ef695ccaea943ef0e62 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 23 Jan 2020 15:33:32 -0700 Subject: [PATCH] io-wq: make the io_wq ref counted to #26323588 commit 848f7e1887c46f21679c2c12b9e8022f17750721 upstream. In preparation for sharing an io-wq across different users, add a reference count that manages destruction of it. Reviewed-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Joseph Qi Acked-by: Xiaoguang Wang --- fs/io-wq.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/io-wq.c b/fs/io-wq.c index 171ba9409baf..36149e3cf3ed 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -114,6 +114,8 @@ struct io_wq { struct mm_struct *mm; refcount_t refs; struct completion done; + + refcount_t use_refs; }; 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) ret = -ENOMEM; goto err; } + refcount_set(&wq->use_refs, 1); reinit_completion(&wq->done); return wq; } @@ -1094,7 +1097,7 @@ static bool io_wq_worker_wake(struct io_worker *worker, void *data) return false; } -void io_wq_destroy(struct io_wq *wq) +static void __io_wq_destroy(struct io_wq *wq) { int node; @@ -1114,3 +1117,9 @@ void io_wq_destroy(struct io_wq *wq) kfree(wq->wqes); kfree(wq); } + +void io_wq_destroy(struct io_wq *wq) +{ + if (refcount_dec_and_test(&wq->use_refs)) + __io_wq_destroy(wq); +} -- GitLab