public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads
@ 2024-09-06  9:53 Felix Moessbauer
  2024-09-06  9:53 ` [PATCH][6.1][1/2] io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers Felix Moessbauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Felix Moessbauer @ 2024-09-06  9:53 UTC (permalink / raw)
  To: stable
  Cc: io-uring, cgroups, axboe, asml.silence, dqminh, longman,
	adriaan.schmidt, florian.bezdeka, Felix Moessbauer

Setting the PF_NO_SETAFFINITY flag creates problems in combination with
cpuset operations (see commit messages for details). To mitigate this, fixes have
been written to remove the flag from the poller threads, which landed in v6.3. We
need them in v6.1 as well.

Best regards,
Felix Moessbauer
Siemens AG

Jens Axboe (1):
  io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers

Michal Koutný (1):
  io_uring/sqpoll: Do not set PF_NO_SETAFFINITY on sqpoll threads

 io_uring/io-wq.c  | 16 +++++++++++-----
 io_uring/sqpoll.c |  1 -
 2 files changed, 11 insertions(+), 6 deletions(-)

-- 
2.39.2


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

* [PATCH][6.1][1/2] io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers
  2024-09-06  9:53 [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Felix Moessbauer
@ 2024-09-06  9:53 ` Felix Moessbauer
  2024-09-06  9:53 ` [PATCH][6.1][2/2] io_uring/sqpoll: Do not set PF_NO_SETAFFINITY on sqpoll threads Felix Moessbauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Felix Moessbauer @ 2024-09-06  9:53 UTC (permalink / raw)
  To: stable
  Cc: io-uring, cgroups, axboe, asml.silence, dqminh, longman,
	adriaan.schmidt, florian.bezdeka, Felix Moessbauer

From: Jens Axboe <[email protected]>

commit 01e68ce08a30db3d842ce7a55f7f6e0474a55f9a upstream.

Every now and then reports come in that are puzzled on why changing
affinity on the io-wq workers fails with EINVAL. This happens because they
set PF_NO_SETAFFINITY as part of their creation, as io-wq organizes
workers into groups based on what CPU they are running on.

However, this is purely an optimization and not a functional requirement.
We can allow setting affinity, and just lazily update our worker to wqe
mappings. If a given io-wq thread times out, it normally exits if there's
no more work to do. The exception is if it's the last worker available.
For the timeout case, check the affinity of the worker against group mask
and exit even if it's the last worker. New workers should be created with
the right mask and in the right location.

Reported-by:Daniel Dao <[email protected]>
Link: https://lore.kernel.org/io-uring/CA+wXwBQwgxB3_UphSny-yAP5b26meeOu1W4TwYVcD_+5gOhvPw@mail.gmail.com/
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Felix Moessbauer <[email protected]>
---
 io_uring/io-wq.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c
index 04503118cdc1..139cd49b2c27 100644
--- a/io_uring/io-wq.c
+++ b/io_uring/io-wq.c
@@ -628,7 +628,7 @@ static int io_wqe_worker(void *data)
 	struct io_wqe_acct *acct = io_wqe_get_acct(worker);
 	struct io_wqe *wqe = worker->wqe;
 	struct io_wq *wq = wqe->wq;
-	bool last_timeout = false;
+	bool exit_mask = false, last_timeout = false;
 	char buf[TASK_COMM_LEN];
 
 	worker->flags |= (IO_WORKER_F_UP | IO_WORKER_F_RUNNING);
@@ -644,8 +644,11 @@ static int io_wqe_worker(void *data)
 			io_worker_handle_work(worker);
 
 		raw_spin_lock(&wqe->lock);
-		/* timed out, exit unless we're the last worker */
-		if (last_timeout && acct->nr_workers > 1) {
+		/*
+		 * Last sleep timed out. Exit if we're not the last worker,
+		 * or if someone modified our affinity.
+		 */
+		if (last_timeout && (exit_mask || acct->nr_workers > 1)) {
 			acct->nr_workers--;
 			raw_spin_unlock(&wqe->lock);
 			__set_current_state(TASK_RUNNING);
@@ -664,7 +667,11 @@ static int io_wqe_worker(void *data)
 				continue;
 			break;
 		}
-		last_timeout = !ret;
+		if (!ret) {
+			last_timeout = true;
+			exit_mask = !cpumask_test_cpu(raw_smp_processor_id(),
+							wqe->cpu_mask);
+		}
 	}
 
 	if (test_bit(IO_WQ_BIT_EXIT, &wq->state))
@@ -716,7 +723,6 @@ static void io_init_new_worker(struct io_wqe *wqe, struct io_worker *worker,
 	tsk->worker_private = worker;
 	worker->task = tsk;
 	set_cpus_allowed_ptr(tsk, wqe->cpu_mask);
-	tsk->flags |= PF_NO_SETAFFINITY;
 
 	raw_spin_lock(&wqe->lock);
 	hlist_nulls_add_head_rcu(&worker->nulls_node, &wqe->free_list);
-- 
2.39.2


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

* [PATCH][6.1][2/2] io_uring/sqpoll: Do not set PF_NO_SETAFFINITY on sqpoll threads
  2024-09-06  9:53 [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Felix Moessbauer
  2024-09-06  9:53 ` [PATCH][6.1][1/2] io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers Felix Moessbauer
@ 2024-09-06  9:53 ` Felix Moessbauer
  2024-09-06 13:33 ` [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Jens Axboe
  2024-09-08 14:16 ` Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Felix Moessbauer @ 2024-09-06  9:53 UTC (permalink / raw)
  To: stable
  Cc: io-uring, cgroups, axboe, asml.silence, dqminh, longman,
	adriaan.schmidt, florian.bezdeka, Michal Koutný,
	Felix Moessbauer

From: Michal Koutný <[email protected]>

commit a5fc1441af7719e93dc7a638a960befb694ade89 upstream.

Users may specify a CPU where the sqpoll thread would run. This may
conflict with cpuset operations because of strict PF_NO_SETAFFINITY
requirement. That flag is unnecessary for polling "kernel" threads, see
the reasoning in commit 01e68ce08a30 ("io_uring/io-wq: stop setting
PF_NO_SETAFFINITY on io-wq workers"). Drop the flag on poll threads too.

Fixes: 01e68ce08a30 ("io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers")
Link: https://lore.kernel.org/all/20230314162559.pnyxdllzgw7jozgx@blackpad/
Signed-off-by: Michal Koutný <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Felix Moessbauer <[email protected]>
---
 io_uring/sqpoll.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index 11610a70573a..6ea21b503113 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -233,7 +233,6 @@ static int io_sq_thread(void *data)
 		set_cpus_allowed_ptr(current, cpumask_of(sqd->sq_cpu));
 	else
 		set_cpus_allowed_ptr(current, cpu_online_mask);
-	current->flags |= PF_NO_SETAFFINITY;
 
 	/*
 	 * Force audit context to get setup, in case we do prep side async
-- 
2.39.2


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

* Re: [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads
  2024-09-06  9:53 [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Felix Moessbauer
  2024-09-06  9:53 ` [PATCH][6.1][1/2] io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers Felix Moessbauer
  2024-09-06  9:53 ` [PATCH][6.1][2/2] io_uring/sqpoll: Do not set PF_NO_SETAFFINITY on sqpoll threads Felix Moessbauer
@ 2024-09-06 13:33 ` Jens Axboe
  2024-09-08 14:16 ` Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2024-09-06 13:33 UTC (permalink / raw)
  To: Felix Moessbauer, stable
  Cc: io-uring, cgroups, asml.silence, dqminh, longman, adriaan.schmidt,
	florian.bezdeka

On 9/6/24 3:53 AM, Felix Moessbauer wrote:
> Setting the PF_NO_SETAFFINITY flag creates problems in combination with
> cpuset operations (see commit messages for details). To mitigate this, fixes have
> been written to remove the flag from the poller threads, which landed in v6.3. We
> need them in v6.1 as well.

Putting these in 6.1-stable is fine imho.

-- 
Jens Axboe



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

* Re: [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads
  2024-09-06  9:53 [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Felix Moessbauer
                   ` (2 preceding siblings ...)
  2024-09-06 13:33 ` [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Jens Axboe
@ 2024-09-08 14:16 ` Greg KH
  3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2024-09-08 14:16 UTC (permalink / raw)
  To: Felix Moessbauer
  Cc: stable, io-uring, cgroups, axboe, asml.silence, dqminh, longman,
	adriaan.schmidt, florian.bezdeka

On Fri, Sep 06, 2024 at 11:53:19AM +0200, Felix Moessbauer wrote:
> Setting the PF_NO_SETAFFINITY flag creates problems in combination with
> cpuset operations (see commit messages for details). To mitigate this, fixes have
> been written to remove the flag from the poller threads, which landed in v6.3. We
> need them in v6.1 as well.

All queued up, thanks.

greg k-h

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

end of thread, other threads:[~2024-09-08 14:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-06  9:53 [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Felix Moessbauer
2024-09-06  9:53 ` [PATCH][6.1][1/2] io_uring/io-wq: stop setting PF_NO_SETAFFINITY on io-wq workers Felix Moessbauer
2024-09-06  9:53 ` [PATCH][6.1][2/2] io_uring/sqpoll: Do not set PF_NO_SETAFFINITY on sqpoll threads Felix Moessbauer
2024-09-06 13:33 ` [PATCH][6.1][0/2] io_uring: Do not set PF_NO_SETAFFINITY on poller threads Jens Axboe
2024-09-08 14:16 ` Greg KH

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