From: Waiman Long <longman@redhat.com>
To: Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
Waiman Long <longman@redhat.com>
Subject: [PATCH 2/2] cgroup/cpuset: Make percpu cpuset_rwsem operation depending on DYNMODS state
Date: Thu, 8 Dec 2022 14:56:34 -0500 [thread overview]
Message-ID: <20221208195634.2604362-3-longman@redhat.com> (raw)
In-Reply-To: <20221208195634.2604362-1-longman@redhat.com>
With commit 6a010a49b63a ("cgroup: Make !percpu threadgroup_rwsem
operations optional"), users can determine if they favor optimizing
for efficiently moving processes between cgroups frequently or for
a more static usage pattern where moving processes among cgroups are
relatively rare.
The percpu cpuset_rwsem is in the same boat as percpu_threadgroup_rwsem
since moving processes among cpusets will have the same latency impact
depending on whether percpu operation in cpuset_rwsem is disabled or not.
Ideally cpuset_bind() is the best place to check if the
cpuset_rwsem should have its reader fast path disabled like
percpu_threadgroup_rwsem so that it gets to be re-evaluated every
time the cpuset is rebound. Unfortunately, cgroup_favor_dynmods()
that sets the CGRP_ROOT_FAVOR_DYNMODS flag is called after the bind()
method call. Instead, the newly added cpuset_check_dynmods() function
is called at the first cpuset_css_online() call after a cpuset_bind()
call when the first child cpuset is created.
Signed-off-by: Waiman Long <longman@redhat.com>
---
kernel/cgroup/cpuset.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 800c65de5daa..daf8ca948176 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -255,6 +255,7 @@ typedef enum {
CS_SCHED_LOAD_BALANCE,
CS_SPREAD_PAGE,
CS_SPREAD_SLAB,
+ CS_FAVOR_DYNMODS, /* top_cpuset only */
} cpuset_flagbits_t;
/* convenient tests for these bits */
@@ -3049,6 +3050,27 @@ static struct cftype dfl_files[] = {
{ } /* terminate */
};
+static bool dynmods_checked __read_mostly;
+static void cpuset_check_dynmods(struct cgroup_root *root)
+{
+ bool favor_dynmods;
+
+ lockdep_assert_held(&cgroup_mutex);
+ percpu_rwsem_assert_held(&cpuset_rwsem);
+
+ /*
+ * Check the CGRP_ROOT_FAVOR_DYNMODS of the cgroup root to find out
+ * if we need to enable or disable reader fast path of cpuset_rwsem.
+ */
+ favor_dynmods = test_bit(CS_FAVOR_DYNMODS, &top_cpuset.flags);
+ if (favor_dynmods && !(root->flags & CGRP_ROOT_FAVOR_DYNMODS)) {
+ rcu_sync_exit(&cpuset_rwsem.rss);
+ clear_bit(CS_FAVOR_DYNMODS, &top_cpuset.flags);
+ } else if (!favor_dynmods && (root->flags & CGRP_ROOT_FAVOR_DYNMODS)) {
+ rcu_sync_enter(&cpuset_rwsem.rss);
+ set_bit(CS_FAVOR_DYNMODS, &top_cpuset.flags);
+ }
+}
/*
* cpuset_css_alloc - allocate a cpuset css
@@ -3099,6 +3121,14 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
cpus_read_lock();
percpu_down_write(&cpuset_rwsem);
+ /*
+ * Check dynmod state on the first css_online() call.
+ */
+ if (unlikely(!dynmods_checked)) {
+ cpuset_check_dynmods(cpuset_cgrp_subsys.root);
+ dynmods_checked = true;
+ }
+
set_bit(CS_ONLINE, &cs->flags);
if (is_spread_page(parent))
set_bit(CS_SPREAD_PAGE, &cs->flags);
@@ -3201,6 +3231,12 @@ static void cpuset_css_free(struct cgroup_subsys_state *css)
static void cpuset_bind(struct cgroup_subsys_state *root_css)
{
+ /*
+ * Reset dynmods_checked to be evaluated again in the next
+ * cpuset_css_online()
+ */
+ dynmods_checked = false;
+
percpu_down_write(&cpuset_rwsem);
spin_lock_irq(&callback_lock);
--
2.31.1
prev parent reply other threads:[~2022-12-08 19:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 19:56 [PATCH 0/2] cgroup/cpuset: Task migration optimization Waiman Long
2022-12-08 19:56 ` [PATCH 1/2] cgroup/cpuset: Use cpuset_rwsem read lock in cpuset_can_attach() Waiman Long
2022-12-08 19:56 ` Waiman Long [this message]
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=20221208195634.2604362-3-longman@redhat.com \
--to=longman@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=tj@kernel.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;
as well as URLs for NNTP newsgroup(s).