From 259d17e8752041ee0311e098d9e64718cccd2f67 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 17 Dec 2021 13:42:40 -0700 Subject: [PATCH 1/2] io-wq: enable io_queue_worker_create() worker freeing on error Rather than pass back this information, pass in whether or not we should be kfree'ing the worker on error. Signed-off-by: Jens Axboe --- fs/io-wq.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/io-wq.c b/fs/io-wq.c index 5c4f582d6549..f261fb700cfc 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -336,9 +336,10 @@ static void create_worker_cb(struct callback_head *cb) io_worker_release(worker); } -static bool io_queue_worker_create(struct io_worker *worker, +static void io_queue_worker_create(struct io_worker *worker, struct io_wqe_acct *acct, - task_work_func_t func) + task_work_func_t func, + bool free_worker_on_error) { struct io_wqe *wqe = worker->wqe; struct io_wq *wq = wqe->wq; @@ -370,8 +371,7 @@ static bool io_queue_worker_create(struct io_worker *worker, */ if (test_bit(IO_WQ_BIT_EXIT, &wq->state)) io_wq_cancel_tw_create(wq); - io_worker_ref_put(wq); - return true; + goto fail_wq_put; } io_worker_ref_put(wq); clear_bit_unlock(0, &worker->create_state); @@ -379,8 +379,10 @@ static bool io_queue_worker_create(struct io_worker *worker, io_worker_release(worker); fail: atomic_dec(&acct->nr_running); +fail_wq_put: io_worker_ref_put(wq); - return false; + if (free_worker_on_error) + kfree(worker); } static void io_wqe_dec_running(struct io_worker *worker) @@ -396,7 +398,7 @@ static void io_wqe_dec_running(struct io_worker *worker) atomic_inc(&acct->nr_running); atomic_inc(&wqe->wq->worker_refs); raw_spin_unlock(&wqe->lock); - io_queue_worker_create(worker, acct, create_worker_cb); + io_queue_worker_create(worker, acct, create_worker_cb, false); raw_spin_lock(&wqe->lock); } } @@ -790,8 +792,7 @@ static void io_workqueue_create(struct work_struct *work) struct io_worker *worker = container_of(work, struct io_worker, work); struct io_wqe_acct *acct = io_wqe_get_acct(worker); - if (!io_queue_worker_create(worker, acct, create_worker_cont)) - kfree(worker); + io_queue_worker_create(worker, acct, create_worker_cont, true); } static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) -- 2.34.1