diff options
| author | Chen Ridong <chenridong@huawei.com> | 2025-09-17 06:04:44 +0000 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2025-09-17 08:35:17 -1000 |
| commit | b783a6265589783e297f8dc4647a31d870d8396e (patch) | |
| tree | fb4d1689e7fe3fed31877d6dcd0df4d986984d54 /kernel | |
| parent | cgroup/cpuset: Remove redundant rcu_read_lock/unlock() in spin_lock (diff) | |
| download | linux-b783a6265589783e297f8dc4647a31d870d8396e.tar.gz linux-b783a6265589783e297f8dc4647a31d870d8396e.zip | |
cpuset: move the root cpuset write check earlier
The 'cpus' or 'mems' lists of the top_cpuset cannot be modified.
This check can be moved before acquiring any locks as a common code
block to improve efficiency and maintainability.
Signed-off-by: Chen Ridong <chenridong@huawei.com>
Reviewed-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/cgroup/cpuset.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index caa885823eeb..12012ce62777 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -2338,10 +2338,6 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, bool force = false; int old_prs = cs->partition_root_state; - /* top_cpuset.cpus_allowed tracks cpu_active_mask; it's read-only */ - if (cs == &top_cpuset) - return -EACCES; - /* * An empty cpus_allowed is ok only if the cpuset has no tasks. * Since cpulist_parse() fails on an empty mask, we special case @@ -2803,15 +2799,6 @@ static int update_nodemask(struct cpuset *cs, struct cpuset *trialcs, int retval; /* - * top_cpuset.mems_allowed tracks node_stats[N_MEMORY]; - * it's read-only - */ - if (cs == &top_cpuset) { - retval = -EACCES; - goto done; - } - - /* * An empty mems_allowed is ok iff there are no tasks in the cpuset. * Since nodelist_parse() fails on an empty mask, we special case * that parsing. The validate_change() call ensures that cpusets @@ -3280,6 +3267,10 @@ ssize_t cpuset_write_resmask(struct kernfs_open_file *of, struct cpuset *trialcs; int retval = -ENODEV; + /* root is read-only */ + if (cs == &top_cpuset) + return -EACCES; + buf = strstrip(buf); cpuset_full_lock(); if (!is_cpuset_online(cs)) |
