From: Hao Xu <haoxu-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
To: Jens Axboe <axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>,
Zefan Li <lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org>,
Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
Pavel Begunkov
<asml.silence-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: io-uring-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Joseph Qi
<joseph.qi-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
Subject: [PATCH 2/2] io_uring: consider cgroup setting when binding sqpoll cpu
Date: Wed, 1 Sep 2021 20:43:22 +0800 [thread overview]
Message-ID: <20210901124322.164238-3-haoxu@linux.alibaba.com> (raw)
In-Reply-To: <20210901124322.164238-1-haoxu-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
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-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
---
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
next prev parent reply other threads:[~2021-09-01 12:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-01 12:43 [PATCH v4 0/2] refactor sqthread cpu binding logic Hao Xu
[not found] ` <20210901124322.164238-1-haoxu-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
2021-09-01 12:43 ` [PATCH 1/2] cpuset: add a helper to check if cpu in cpuset of current task Hao Xu
2021-09-01 12:43 ` Hao Xu [this message]
[not found] ` <20210901124322.164238-3-haoxu-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
2021-09-01 16:41 ` [PATCH 2/2] io_uring: consider cgroup setting when binding sqpoll cpu Tejun Heo
2021-09-01 16:42 ` Tejun Heo
[not found] ` <YS+tPq1eiQLx4P3M-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2021-09-03 15:04 ` Hao Xu
[not found] ` <c49d9b26-1c74-316a-c933-e6964695a286-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
2021-09-07 16:54 ` Tejun Heo
[not found] ` <YTeZUnshr+mgf5GS-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2021-09-07 19:28 ` Hao Xu
2021-09-02 16:48 ` [PATCH v4 0/2] refactor sqthread cpu binding logic Michal Koutný
[not found] ` <20210902164808.GA10014-9OudH3eul5jcvrawFnH+a6VXKuFTiq87@public.gmane.org>
2021-09-02 18:00 ` Jens Axboe
[not found] ` <efd3c387-9c7c-c0d8-1306-f722da2a9ba1-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2021-09-09 12:34 ` Michal Koutný
2021-09-03 14:43 ` Hao Xu
-- strict thread matches above, loose matches on Subject: below --
2021-09-01 10:18 [PATCH v3 " Hao Xu
[not found] ` <20210901101833.69535-1-haoxu-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
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
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=20210901124322.164238-3-haoxu@linux.alibaba.com \
--to=haoxu-kpsofbns7gizrge5brqyagc/g2k4zdhf@public.gmane.org \
--cc=asml.silence-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
--cc=io-uring-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=joseph.qi-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org \
--cc=lizefan.x-EC8Uxl6Npydl57MIdRCFDg@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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