Skip to contentSkip to conversation

io-wq: move nr_running and worker_refs out of wqe->lock protection

PATCH Applied Hao Xu 2 participants 3 messages Aug 10, 2021 – Aug 18, 2021

Subsystems (2)
lore
Share & tools
lore

Hao Xu

author
#0 lore raw

PATCH 1/1 io-wq: move nr_running and worker_refs out of wqe->lock protection

We don't need to protect nr_running and worker_refs by wqe->lock, so narrow the range of raw_spin_lock_irq - raw_spin_unlock_irq

---
 fs/io-wq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/io-wq.c +4 -3
index 4ce83bb48021..8da9bb103916 100644
@@ -256,16 +256,17 @@ static void io_wqe_wake_worker(struct io_wqe *wqe, struct io_wqe_acct *acct)
 
 		raw_spin_lock_irq(&wqe->lock);
 		if (acct->nr_workers < acct->max_workers) {
-			atomic_inc(&acct->nr_running);
-			atomic_inc(&wqe->wq->worker_refs);
 			if (!acct->nr_workers)
 				first = true;
 			acct->nr_workers++;
 			do_create = true;
 		}
 		raw_spin_unlock_irq(&wqe->lock);
-		if (do_create)
+		if (do_create) {
+			atomic_inc(&acct->nr_running);
+			atomic_inc(&wqe->wq->worker_refs);
 			create_io_worker(wqe->wq, wqe, acct->index, first);
+		}
 	}
 }
 
Signature · 1 line
2.24.4
author
#1 lore raw

在 2021/8/10 下午8:55, Hao Xu 写道:
ping

Quoted 34 lines

We don't need to protect nr_running and worker_refs by wqe->lock, so narrow the range of raw_spin_lock_irq - raw_spin_unlock_irq

---
  fs/io-wq.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
fs/io-wq.c +4 -3
index 4ce83bb48021..8da9bb103916 100644
@@ -256,16 +256,17 @@ static void io_wqe_wake_worker(struct io_wqe *wqe, struct io_wqe_acct *acct)
 
  		raw_spin_lock_irq(&wqe->lock);
  		if (acct->nr_workers < acct->max_workers) {
-			atomic_inc(&acct->nr_running);
-			atomic_inc(&wqe->wq->worker_refs);
  			if (!acct->nr_workers)
  				first = true;
  			acct->nr_workers++;
  			do_create = true;
  		}
  		raw_spin_unlock_irq(&wqe->lock);
-		if (do_create)
+		if (do_create) {
+			atomic_inc(&acct->nr_running);
+			atomic_inc(&wqe->wq->worker_refs);
  			create_io_worker(wqe->wq, wqe, acct->index, first);
+		}
  	}
  }
 
maintainer Applied
#2 lore raw
In reply to Hao Xu
Quoted 2 lines · Hao Xu

We don't need to protect nr_running and worker_refs by wqe->lock, so narrow the range of raw_spin_lock_irq - raw_spin_unlock_irq

Applied, thanks.

Signature · 1 line
Jens Axboe