Skip to contentSkip to conversation

io-wq: Fix io_wq_worker_affinity()

PATCH Applied Peter Zijlstra 2 participants 2 messages Apr 8, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io-wq: Fix io_wq_worker_affinity()

Do not include private headers and do not frob in internals.

On top of that, while the previous code restores the affinity, it doesn't ensure the task actually moves there if it was running, leading to the fun situation that it can be observed running outside of its allowed mask for potentially significant time.

Use the proper API instead.

---
 fs/io-wq.c |   11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
fs/io-wq.c +2 -9
@@ -17,7 +17,6 @@
 #include <linux/cpu.h>
 #include <linux/tracehook.h>
 
-#include "../kernel/sched/sched.h"
 #include "io-wq.h"
 
 #define WORKER_IDLE_TIMEOUT	(5 * HZ)
@@ -1098,14 +1097,8 @@ void io_wq_put_and_exit(struct io_wq *wq
 
 static bool io_wq_worker_affinity(struct io_worker *worker, void *data)
 {
-	struct task_struct *task = worker->task;
-	struct rq_flags rf;
-	struct rq *rq;
-
-	rq = task_rq_lock(task, &rf);
-	do_set_cpus_allowed(task, cpumask_of_node(worker->wqe->node));
-	task->flags |= PF_NO_SETAFFINITY;
-	task_rq_unlock(rq, task, &rf);
+	set_cpus_allowed_ptr(worker->task, cpumask_of_node(worker->wqe->node));
+
 	return false;
 }
 
maintainer Applied
#1 lore raw
Quoted 9 lines · Peter Zijlstra

Do not include private headers and do not frob in internals.

On top of that, while the previous code restores the affinity, it doesn't ensure the task actually moves there if it was running, leading to the fun situation that it can be observed running outside of its allowed mask for potentially significant time.

Use the proper API instead.

Applied, thanks Peter.

Signature · 1 line
Jens Axboe