]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cpuset: remove redundant CS_ONLINE flag
authorChen Ridong <chenridong@huawei.com>
Wed, 13 Aug 2025 08:29:01 +0000 (08:29 +0000)
committerTejun Heo <tj@kernel.org>
Wed, 13 Aug 2025 18:14:20 +0000 (08:14 -1000)
The CS_ONLINE flag was introduced prior to the CSS_ONLINE flag in the
cpuset subsystem. Currently, the flag setting sequence is as follows:

1. cpuset_css_online() sets CS_ONLINE
2. css->flags gets CSS_ONLINE set
...
3. cgroup->kill_css sets CSS_DYING
4. cpuset_css_offline() clears CS_ONLINE
5. css->flags clears CSS_ONLINE

The is_cpuset_online() check currently occurs between steps 1 and 3.
However, it would be equally safe to perform this check between steps 2
and 3, as CSS_ONLINE provides the same synchronization guarantee as
CS_ONLINE.

Since CS_ONLINE is redundant with CSS_ONLINE and provides no additional
synchronization benefits, we can safely remove it to simplify the code.

Signed-off-by: Chen Ridong <chenridong@huawei.com>
Acked-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/cgroup.h
kernel/cgroup/cpuset-internal.h
kernel/cgroup/cpuset.c

index b18fb5fcb38e239347c1be4b5af9f74f14c767c4..ae73dbb19165c88d5c1eaa68022cea27a4d13c59 100644 (file)
@@ -354,6 +354,11 @@ static inline bool css_is_dying(struct cgroup_subsys_state *css)
        return css->flags & CSS_DYING;
 }
 
+static inline bool css_is_online(struct cgroup_subsys_state *css)
+{
+       return css->flags & CSS_ONLINE;
+}
+
 static inline bool css_is_self(struct cgroup_subsys_state *css)
 {
        if (css == &css->cgroup->self) {
index 383963e28ac69c8937a84f5b176de2ce99d55564..75b3aef39231ddc875c28a5d4fc1eda142e5cf77 100644 (file)
@@ -38,7 +38,6 @@ enum prs_errcode {
 
 /* bits in struct cpuset flags field */
 typedef enum {
-       CS_ONLINE,
        CS_CPU_EXCLUSIVE,
        CS_MEM_EXCLUSIVE,
        CS_MEM_HARDWALL,
@@ -202,7 +201,7 @@ static inline struct cpuset *parent_cs(struct cpuset *cs)
 /* convenient tests for these bits */
 static inline bool is_cpuset_online(struct cpuset *cs)
 {
-       return test_bit(CS_ONLINE, &cs->flags) && !css_is_dying(&cs->css);
+       return css_is_online(&cs->css) && !css_is_dying(&cs->css);
 }
 
 static inline int is_cpu_exclusive(const struct cpuset *cs)
index 27adb04df675d4521ae1589632a1831892b16422..3466ebbf10164ab5775d13479fa02138a5be8545 100644 (file)
@@ -207,7 +207,7 @@ static inline void notify_partition_change(struct cpuset *cs, int old_prs)
  * parallel, we may leave an offline CPU in cpu_allowed or some other masks.
  */
 static struct cpuset top_cpuset = {
-       .flags = BIT(CS_ONLINE) | BIT(CS_CPU_EXCLUSIVE) |
+       .flags = BIT(CS_CPU_EXCLUSIVE) |
                 BIT(CS_MEM_EXCLUSIVE) | BIT(CS_SCHED_LOAD_BALANCE),
        .partition_root_state = PRS_ROOT,
        .relax_domain_level = -1,
@@ -3496,7 +3496,6 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
        cpus_read_lock();
        mutex_lock(&cpuset_mutex);
 
-       set_bit(CS_ONLINE, &cs->flags);
        if (is_spread_page(parent))
                set_bit(CS_SPREAD_PAGE, &cs->flags);
        if (is_spread_slab(parent))
@@ -3571,7 +3570,6 @@ static void cpuset_css_offline(struct cgroup_subsys_state *css)
                cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
 
        cpuset_dec();
-       clear_bit(CS_ONLINE, &cs->flags);
 
        mutex_unlock(&cpuset_mutex);
        cpus_read_unlock();