From: Hao Xu <[email protected]>
To: Jens Axboe <[email protected]>, Zefan Li <[email protected]>,
Tejun Heo <[email protected]>, Johannes Weiner <[email protected]>,
Pavel Begunkov <[email protected]>
Cc: [email protected], [email protected],
Joseph Qi <[email protected]>
Subject: Re: [PATCH 2/2] io_uring: consider cgroup setting when binding sqpoll cpu
Date: Wed, 1 Sep 2021 20:31:26 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
在 2021/9/1 下午6:18, Hao Xu 写道:
> Since sqthread is userspace like thread now, it should respect cgroup
> setting, thus we should consider current allowed cpuset when doing
> cpu binding for sqthread.
>
> Signed-off-by: Hao Xu <[email protected]>
> ---
> fs/io_uring.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 7cc458e0b636..414dfedf79a7 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -79,6 +79,7 @@
> #include <linux/pagemap.h>
> #include <linux/io_uring.h>
> #include <linux/tracehook.h>
> +#include <linux/cpuset.h>
>
> #define CREATE_TRACE_POINTS
> #include <trace/events/io_uring.h>
> @@ -7102,6 +7103,14 @@ static bool io_sqd_handle_event(struct io_sq_data *sqd)
> return did_sig || test_bit(IO_SQ_THREAD_SHOULD_STOP, &sqd->state);
> }
>
> +static inline int io_sq_bind_cpu(int cpu)
> +{
> + if (test_cpu_in_current_cpuset(cpu))
> + set_cpus_allowed_ptr(current, cpumask_of(cpu));
> +
> + return 0;
Ah, no need to return value anymore, even no need to have this function
here. I'll resend a new version.
> +}
> +
> static int io_sq_thread(void *data)
> {
> struct io_sq_data *sqd = data;
> @@ -7112,11 +7121,9 @@ static int io_sq_thread(void *data)
>
> snprintf(buf, sizeof(buf), "iou-sqp-%d", sqd->task_pid);
> set_task_comm(current, buf);
> -
> if (sqd->sq_cpu != -1)
> - set_cpus_allowed_ptr(current, cpumask_of(sqd->sq_cpu));
> - else
> - set_cpus_allowed_ptr(current, cpu_online_mask);
> + io_sq_bind_cpu(sqd->sq_cpu);
> +
> current->flags |= PF_NO_SETAFFINITY;
>
> mutex_lock(&sqd->lock);
> @@ -8310,8 +8317,10 @@ static int io_sq_offload_create(struct io_ring_ctx *ctx,
> int cpu = p->sq_thread_cpu;
>
> ret = -EINVAL;
> - if (cpu >= nr_cpu_ids || !cpu_online(cpu))
> + if (cpu >= nr_cpu_ids || !cpu_online(cpu) ||
> + !test_cpu_in_current_cpuset(cpu))
> goto err_sqpoll;
> +
> sqd->sq_cpu = cpu;
> } else {
> sqd->sq_cpu = -1;
>
next prev parent reply other threads:[~2021-09-01 12:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-01 10:18 [PATCH v3 0/2] refactor sqthread cpu binding logic Hao Xu
2021-09-01 10:18 ` [PATCH 1/2] cpuset: add a helper to check if cpu in cpuset of current task Hao Xu
2021-09-01 10:18 ` [PATCH 2/2] io_uring: consider cgroup setting when binding sqpoll cpu Hao Xu
2021-09-01 12:31 ` Hao Xu [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-09-01 12:43 [PATCH v4 0/2] refactor sqthread cpu binding logic Hao Xu
2021-09-01 12:43 ` [PATCH 2/2] io_uring: consider cgroup setting when binding sqpoll cpu Hao Xu
2021-09-01 16:41 ` Tejun Heo
2021-09-01 16:42 ` Tejun Heo
2021-09-03 15:04 ` Hao Xu
2021-09-07 16:54 ` Tejun Heo
2021-09-07 19:28 ` Hao Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bd6e3eef-b4ba-b185-f8bc-23f8b5886235@linux.alibaba.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox