Skip to content

Commit c4c9ceb

Browse files
Waiman-Longhtejun
authored andcommitted
cgroup/cpuset: Further optimize code if CONFIG_CPUSETS_V1 not set
Currently the cpuset code uses group_subsys_on_dfl() to check if we are running with cgroup v2. If CONFIG_CPUSETS_V1 isn't set, there is really no need to do this check and we can optimize out some of the unneeded v1 specific code paths. Introduce a new cpuset_v2() and use it to replace the cgroup_subsys_on_dfl() check to further optimize the code. Signed-off-by: Waiman Long <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent a040c35 commit c4c9ceb

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

kernel/cgroup/cpuset.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ static inline void dec_attach_in_progress(struct cpuset *cs)
293293
mutex_unlock(&cpuset_mutex);
294294
}
295295

296+
static inline bool cpuset_v2(void)
297+
{
298+
return !IS_ENABLED(CONFIG_CPUSETS_V1) ||
299+
cgroup_subsys_on_dfl(cpuset_cgrp_subsys);
300+
}
301+
296302
/*
297303
* Cgroup v2 behavior is used on the "cpus" and "mems" control files when
298304
* on default hierarchy or when the cpuset_v2_mode flag is set by mounting
@@ -303,7 +309,7 @@ static inline void dec_attach_in_progress(struct cpuset *cs)
303309
*/
304310
static inline bool is_in_v2_mode(void)
305311
{
306-
return cgroup_subsys_on_dfl(cpuset_cgrp_subsys) ||
312+
return cpuset_v2() ||
307313
(cpuset_cgrp_subsys.root->flags & CGRP_ROOT_CPUSET_V2_MODE);
308314
}
309315

@@ -738,7 +744,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
738744
int nslot; /* next empty doms[] struct cpumask slot */
739745
struct cgroup_subsys_state *pos_css;
740746
bool root_load_balance = is_sched_load_balance(&top_cpuset);
741-
bool cgrpv2 = cgroup_subsys_on_dfl(cpuset_cgrp_subsys);
747+
bool cgrpv2 = cpuset_v2();
742748
int nslot_update;
743749

744750
doms = NULL;
@@ -1198,7 +1204,7 @@ static void reset_partition_data(struct cpuset *cs)
11981204
{
11991205
struct cpuset *parent = parent_cs(cs);
12001206

1201-
if (!cgroup_subsys_on_dfl(cpuset_cgrp_subsys))
1207+
if (!cpuset_v2())
12021208
return;
12031209

12041210
lockdep_assert_held(&callback_lock);
@@ -2017,7 +2023,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
20172023
*/
20182024
if (!cp->partition_root_state && !force &&
20192025
cpumask_equal(tmp->new_cpus, cp->effective_cpus) &&
2020-
(!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) ||
2026+
(!cpuset_v2() ||
20212027
(is_sched_load_balance(parent) == is_sched_load_balance(cp)))) {
20222028
pos_css = css_rightmost_descendant(pos_css);
20232029
continue;
@@ -2091,8 +2097,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
20912097
* from parent if current cpuset isn't a valid partition root
20922098
* and their load balance states differ.
20932099
*/
2094-
if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
2095-
!is_partition_valid(cp) &&
2100+
if (cpuset_v2() && !is_partition_valid(cp) &&
20962101
(is_sched_load_balance(parent) != is_sched_load_balance(cp))) {
20972102
if (is_sched_load_balance(parent))
20982103
set_bit(CS_SCHED_LOAD_BALANCE, &cp->flags);
@@ -2108,8 +2113,7 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
21082113
*/
21092114
if (!cpumask_empty(cp->cpus_allowed) &&
21102115
is_sched_load_balance(cp) &&
2111-
(!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) ||
2112-
is_partition_valid(cp)))
2116+
(!cpuset_v2() || is_partition_valid(cp)))
21132117
need_rebuild_sched_domains = true;
21142118

21152119
rcu_read_lock();
@@ -2246,7 +2250,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
22462250

22472251
retval = validate_change(cs, trialcs);
22482252

2249-
if ((retval == -EINVAL) && cgroup_subsys_on_dfl(cpuset_cgrp_subsys)) {
2253+
if ((retval == -EINVAL) && cpuset_v2()) {
22502254
struct cgroup_subsys_state *css;
22512255
struct cpuset *cp;
22522256

@@ -2738,8 +2742,7 @@ int cpuset_update_flag(cpuset_flagbits_t bit, struct cpuset *cs,
27382742
spin_unlock_irq(&callback_lock);
27392743

27402744
if (!cpumask_empty(trialcs->cpus_allowed) && balance_flag_changed) {
2741-
if (!IS_ENABLED(CONFIG_CPUSETS_V1) ||
2742-
cgroup_subsys_on_dfl(cpuset_cgrp_subsys))
2745+
if (cpuset_v2())
27432746
cpuset_force_rebuild();
27442747
else
27452748
rebuild_sched_domains_locked();
@@ -2925,8 +2928,7 @@ static int cpuset_can_attach(struct cgroup_taskset *tset)
29252928
* migration permission derives from hierarchy ownership in
29262929
* cgroup_procs_write_permission()).
29272930
*/
2928-
if (!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) ||
2929-
(cpus_updated || mems_updated)) {
2931+
if (!cpuset_v2() || (cpus_updated || mems_updated)) {
29302932
ret = security_task_setscheduler(task);
29312933
if (ret)
29322934
goto out_unlock;
@@ -3040,8 +3042,7 @@ static void cpuset_attach(struct cgroup_taskset *tset)
30403042
* in effective cpus and mems. In that case, we can optimize out
30413043
* by skipping the task iteration and update.
30423044
*/
3043-
if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
3044-
!cpus_updated && !mems_updated) {
3045+
if (cpuset_v2() && !cpus_updated && !mems_updated) {
30453046
cpuset_attach_nodemask_to = cs->effective_mems;
30463047
goto out;
30473048
}
@@ -3391,7 +3392,7 @@ cpuset_css_alloc(struct cgroup_subsys_state *parent_css)
33913392
INIT_LIST_HEAD(&cs->remote_sibling);
33923393

33933394
/* Set CS_MEMORY_MIGRATE for default hierarchy */
3394-
if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys))
3395+
if (cpuset_v2())
33953396
__set_bit(CS_MEMORY_MIGRATE, &cs->flags);
33963397

33973398
return &cs->css;
@@ -3418,8 +3419,7 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
34183419
/*
34193420
* For v2, clear CS_SCHED_LOAD_BALANCE if parent is isolated
34203421
*/
3421-
if (cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
3422-
!is_sched_load_balance(parent))
3422+
if (cpuset_v2() && !is_sched_load_balance(parent))
34233423
clear_bit(CS_SCHED_LOAD_BALANCE, &cs->flags);
34243424

34253425
cpuset_inc();
@@ -3489,8 +3489,7 @@ static void cpuset_css_offline(struct cgroup_subsys_state *css)
34893489
if (is_partition_valid(cs))
34903490
update_prstate(cs, 0);
34913491

3492-
if (!cgroup_subsys_on_dfl(cpuset_cgrp_subsys) &&
3493-
is_sched_load_balance(cs))
3492+
if (!cpuset_v2() && is_sched_load_balance(cs))
34943493
cpuset_update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
34953494

34963495
cpuset_dec();

0 commit comments

Comments
 (0)