public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 1/1] io-wq: deduplicate destroying wq->manager
@ 2021-03-01 20:15 Pavel Begunkov
  2021-03-01 20:59 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Begunkov @ 2021-03-01 20:15 UTC (permalink / raw)
  To: Jens Axboe, io-uring

Add a helper io_wq_destroy_manager(), for killing an io-wq manager and
not repeating it three times.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io-wq.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/fs/io-wq.c b/fs/io-wq.c
index 9828722fdee9..c9d886d1a73c 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -1059,20 +1059,24 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data)
 	return ERR_PTR(ret);
 }
 
-static void io_wq_destroy(struct io_wq *wq)
+static void io_wq_destroy_manager(struct io_wq *wq)
 {
-	int node;
-
-	cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
-
-	set_bit(IO_WQ_BIT_EXIT, &wq->state);
 	if (wq->manager) {
 		wake_up_process(wq->manager);
 		wait_for_completion(&wq->exited);
 		put_task_struct(wq->manager);
 		wq->manager = NULL;
 	}
+}
+
+static void io_wq_destroy(struct io_wq *wq)
+{
+	int node;
+
+	cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node);
 
+	set_bit(IO_WQ_BIT_EXIT, &wq->state);
+	io_wq_destroy_manager(wq);
 	spin_lock_irq(&wq->hash->wait.lock);
 	for_each_node(node) {
 		struct io_wqe *wqe = wq->wqes[node];
@@ -1095,12 +1099,7 @@ void io_wq_put(struct io_wq *wq)
 void io_wq_put_and_exit(struct io_wq *wq)
 {
 	set_bit(IO_WQ_BIT_EXIT, &wq->state);
-	if (wq->manager) {
-		wake_up_process(wq->manager);
-		wait_for_completion(&wq->exited);
-		put_task_struct(wq->manager);
-		wq->manager = NULL;
-	}
+	io_wq_destroy_manager(wq);
 	io_wq_put(wq);
 }
 
@@ -1146,12 +1145,7 @@ void io_wq_unshare(struct io_wq *wq)
 {
 	refcount_inc(&wq->refs);
 	set_bit(IO_WQ_BIT_EXIT, &wq->state);
-	if (wq->manager) {
-		wake_up_process(wq->manager);
-		wait_for_completion(&wq->exited);
-		put_task_struct(wq->manager);
-		wq->manager = NULL;
-	}
+	io_wq_destroy_manager(wq);
 	clear_bit(IO_WQ_BIT_EXIT, &wq->state);
 	io_wq_put(wq);
 }
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-01 21:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-01 20:15 [PATCH 1/1] io-wq: deduplicate destroying wq->manager Pavel Begunkov
2021-03-01 20:59 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox