Skip to contentSkip to conversation

io-wq: Remove duplicate code in io_workqueue_create()

PATCH In review Bixuan Cui 3 participants 3 messages Sep 11, 2021 – Sep 15, 2021

Subsystems (2)
lore
Share & tools
lore

Bixuan Cui

author
#0 lore raw

PATCH 1/1 io-wq: Remove duplicate code in io_workqueue_create()

While task_work_add() in io_workqueue_create() is true, then duplicate code is executed:

  -> clear_bit_unlock(0, &worker->create_state);
  -> io_worker_release(worker);
  -> atomic_dec(&acct->nr_running);
  -> io_worker_ref_put(wq);
  -> return false;

  -> clear_bit_unlock(0, &worker->create_state); // back to io_workqueue_create()
  -> io_worker_release(worker);
  -> kfree(worker);

The io_worker_release() and clear_bit_unlock() are executed twice.

Fixes 3146cba99aa2 ("io-wq: make worker creation resilient against signals")
---
 fs/io-wq.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
fs/io-wq.c +4 -5
index 6c55362c1f99..95d0eaed7c00 100644
@@ -329,8 +329,10 @@ static bool io_queue_worker_create(struct io_worker *worker,
 
 	init_task_work(&worker->create_work, func);
 	worker->create_index = acct->index;
-	if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL))
+	if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) {
+		clear_bit_unlock(0, &worker->create_state);
 		return true;
+	}
 	clear_bit_unlock(0, &worker->create_state);
 fail_release:
 	io_worker_release(worker);
@@ -723,11 +725,8 @@ 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)) {
-		clear_bit_unlock(0, &worker->create_state);
-		io_worker_release(worker);
+	if (!io_queue_worker_create(worker, acct, create_worker_cont))
 		kfree(worker);
-	}
 }
 
 static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 41 lines · Bixuan Cui

While task_work_add() in io_workqueue_create() is true, then duplicate code is executed:

   -> clear_bit_unlock(0, &worker->create_state);
   -> io_worker_release(worker);
   -> atomic_dec(&acct->nr_running);
   -> io_worker_ref_put(wq);
   -> return false;

   -> clear_bit_unlock(0, &worker->create_state); // back to io_workqueue_create()
   -> io_worker_release(worker);
   -> kfree(worker);

The io_worker_release() and clear_bit_unlock() are executed twice.

Fixes 3146cba99aa2 ("io-wq: make worker creation resilient against signals")
---
  fs/io-wq.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
fs/io-wq.c +3 -1
index 6c55362c1f99..95d0eaed7c00 100644
@@ -329,8 +329,10 @@ static bool io_queue_worker_create(struct io_worker *worker,
 
  	init_task_work(&worker->create_work, func);
  	worker->create_index = acct->index;
-	if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL))
+	if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) {
+		clear_bit_unlock(0, &worker->create_state);
  		return true;
+	}
  	clear_bit_unlock(0, &worker->create_state);
  fail_release:
  	io_worker_release(worker);
@@ -723,11 +725,8 @@ 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);

fs/io-wq.c static void io_workqueue_create(struct work_struct *work) · line 732

Quoted 10 lines
fs/io-wq.c +1 -4
 
-	if (!io_queue_worker_create(worker, acct, create_worker_cont)) {
-		clear_bit_unlock(0, &worker->create_state);
-		io_worker_release(worker);
+	if (!io_queue_worker_create(worker, acct, create_worker_cont))
  		kfree(worker);
-	}
  }
 
  static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)

AFAIK, this looks reasonable for me.

maintainer
#2 lore raw
Quoted 50 lines · Hao Xu
Quoted 49 lines · Bixuan Cui

While task_work_add() in io_workqueue_create() is true, then duplicate code is executed:

   -> clear_bit_unlock(0, &worker->create_state);
   -> io_worker_release(worker);
   -> atomic_dec(&acct->nr_running);
   -> io_worker_ref_put(wq);
   -> return false;

   -> clear_bit_unlock(0, &worker->create_state); // back to io_workqueue_create()
   -> io_worker_release(worker);
   -> kfree(worker);

The io_worker_release() and clear_bit_unlock() are executed twice.

Fixes 3146cba99aa2 ("io-wq: make worker creation resilient against signals")
---
  fs/io-wq.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
fs/io-wq.c +4 -5
index 6c55362c1f99..95d0eaed7c00 100644
@@ -329,8 +329,10 @@ static bool io_queue_worker_create(struct io_worker *worker,
 
  	init_task_work(&worker->create_work, func);
  	worker->create_index = acct->index;
-	if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL))
+	if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) {
+		clear_bit_unlock(0, &worker->create_state);
  		return true;
+	}
  	clear_bit_unlock(0, &worker->create_state);
  fail_release:
  	io_worker_release(worker);
@@ -723,11 +725,8 @@ 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)) {
-		clear_bit_unlock(0, &worker->create_state);
-		io_worker_release(worker);
+	if (!io_queue_worker_create(worker, acct, create_worker_cont))
  		kfree(worker);
-	}
  }
 
Quoted 3 lines

fs/io-wq.c static void io_workqueue_create(struct work_struct *work) · line 732

Quoted 2 lines
fs/io-wq.c +0 -0
  static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)

AFAIK, this looks reasonable for me.

I took that as a reviewed-by, let me know if that isn't correct.

Signature · 1 line
Jens Axboe