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 <haoxu@xxxxxxxxxxxxxxxxx> --- fs/io_uring.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 7cc458e0b636..fb7890077ede 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> @@ -7112,11 +7113,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) + if (sqd->sq_cpu != -1 && test_cpu_in_current_cpuset(sqd->sq_cpu)) set_cpus_allowed_ptr(current, cpumask_of(sqd->sq_cpu)); - else - set_cpus_allowed_ptr(current, cpu_online_mask); + current->flags |= PF_NO_SETAFFINITY; mutex_lock(&sqd->lock); @@ -8310,8 +8309,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; -- 2.24.4