Skip to content

Commit 56805c1

Browse files
Chen Ridonghtejun
authored andcommitted
cpuset: add cpuset1_online_css helper for v1-specific operations
This commit introduces the cpuset1_online_css helper to centralize v1-specific handling during cpuset online. It performs operations such as updating the CS_SPREAD_PAGE, CS_SPREAD_SLAB, and CGRP_CPUSET_CLONE_CHILDREN flags, which are unique to the cpuset v1 control group interface. The helper is now placed in cpuset-v1.c to maintain clear separation between v1 and v2 logic. Signed-off-by: Chen Ridong <chenridong@huawei.com> Reviewed-by: Waiman Long <longman@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 14c11e1 commit 56805c1

3 files changed

Lines changed: 51 additions & 38 deletions

File tree

kernel/cgroup/cpuset-internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ void cpuset1_hotplug_update_tasks(struct cpuset *cs,
293293
struct cpumask *new_cpus, nodemask_t *new_mems,
294294
bool cpus_updated, bool mems_updated);
295295
int cpuset1_validate_change(struct cpuset *cur, struct cpuset *trial);
296+
void cpuset1_online_css(struct cgroup_subsys_state *css);
296297
#else
297298
static inline void fmeter_init(struct fmeter *fmp) {}
298299
static inline void cpuset1_update_task_spread_flags(struct cpuset *cs,
@@ -303,6 +304,7 @@ static inline void cpuset1_hotplug_update_tasks(struct cpuset *cs,
303304
bool cpus_updated, bool mems_updated) {}
304305
static inline int cpuset1_validate_change(struct cpuset *cur,
305306
struct cpuset *trial) { return 0; }
307+
static inline void cpuset1_online_css(struct cgroup_subsys_state *css) {}
306308
#endif /* CONFIG_CPUSETS_V1 */
307309

308310
#endif /* __CPUSET_INTERNAL_H */

kernel/cgroup/cpuset-v1.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,54 @@ static int cpuset_write_u64(struct cgroup_subsys_state *css, struct cftype *cft,
499499
return retval;
500500
}
501501

502+
void cpuset1_online_css(struct cgroup_subsys_state *css)
503+
{
504+
struct cpuset *tmp_cs;
505+
struct cgroup_subsys_state *pos_css;
506+
struct cpuset *cs = css_cs(css);
507+
struct cpuset *parent = parent_cs(cs);
508+
509+
lockdep_assert_cpus_held();
510+
lockdep_assert_cpuset_lock_held();
511+
512+
if (is_spread_page(parent))
513+
set_bit(CS_SPREAD_PAGE, &cs->flags);
514+
if (is_spread_slab(parent))
515+
set_bit(CS_SPREAD_SLAB, &cs->flags);
516+
517+
if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags))
518+
return;
519+
520+
/*
521+
* Clone @parent's configuration if CGRP_CPUSET_CLONE_CHILDREN is
522+
* set. This flag handling is implemented in cgroup core for
523+
* historical reasons - the flag may be specified during mount.
524+
*
525+
* Currently, if any sibling cpusets have exclusive cpus or mem, we
526+
* refuse to clone the configuration - thereby refusing the task to
527+
* be entered, and as a result refusing the sys_unshare() or
528+
* clone() which initiated it. If this becomes a problem for some
529+
* users who wish to allow that scenario, then this could be
530+
* changed to grant parent->cpus_allowed-sibling_cpus_exclusive
531+
* (and likewise for mems) to the new cgroup.
532+
*/
533+
rcu_read_lock();
534+
cpuset_for_each_child(tmp_cs, pos_css, parent) {
535+
if (is_mem_exclusive(tmp_cs) || is_cpu_exclusive(tmp_cs)) {
536+
rcu_read_unlock();
537+
return;
538+
}
539+
}
540+
rcu_read_unlock();
541+
542+
cpuset_callback_lock_irq();
543+
cs->mems_allowed = parent->mems_allowed;
544+
cs->effective_mems = parent->mems_allowed;
545+
cpumask_copy(cs->cpus_allowed, parent->cpus_allowed);
546+
cpumask_copy(cs->effective_cpus, parent->cpus_allowed);
547+
cpuset_callback_unlock_irq();
548+
}
549+
502550
/*
503551
* for the common functions, 'private' gives the type of file
504552
*/

kernel/cgroup/cpuset.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,17 +3616,11 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
36163616
{
36173617
struct cpuset *cs = css_cs(css);
36183618
struct cpuset *parent = parent_cs(cs);
3619-
struct cpuset *tmp_cs;
3620-
struct cgroup_subsys_state *pos_css;
36213619

36223620
if (!parent)
36233621
return 0;
36243622

36253623
cpuset_full_lock();
3626-
if (is_spread_page(parent))
3627-
set_bit(CS_SPREAD_PAGE, &cs->flags);
3628-
if (is_spread_slab(parent))
3629-
set_bit(CS_SPREAD_SLAB, &cs->flags);
36303624
/*
36313625
* For v2, clear CS_SCHED_LOAD_BALANCE if parent is isolated
36323626
*/
@@ -3641,39 +3635,8 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
36413635
cs->effective_mems = parent->effective_mems;
36423636
}
36433637
spin_unlock_irq(&callback_lock);
3638+
cpuset1_online_css(css);
36443639

3645-
if (!test_bit(CGRP_CPUSET_CLONE_CHILDREN, &css->cgroup->flags))
3646-
goto out_unlock;
3647-
3648-
/*
3649-
* Clone @parent's configuration if CGRP_CPUSET_CLONE_CHILDREN is
3650-
* set. This flag handling is implemented in cgroup core for
3651-
* historical reasons - the flag may be specified during mount.
3652-
*
3653-
* Currently, if any sibling cpusets have exclusive cpus or mem, we
3654-
* refuse to clone the configuration - thereby refusing the task to
3655-
* be entered, and as a result refusing the sys_unshare() or
3656-
* clone() which initiated it. If this becomes a problem for some
3657-
* users who wish to allow that scenario, then this could be
3658-
* changed to grant parent->cpus_allowed-sibling_cpus_exclusive
3659-
* (and likewise for mems) to the new cgroup.
3660-
*/
3661-
rcu_read_lock();
3662-
cpuset_for_each_child(tmp_cs, pos_css, parent) {
3663-
if (is_mem_exclusive(tmp_cs) || is_cpu_exclusive(tmp_cs)) {
3664-
rcu_read_unlock();
3665-
goto out_unlock;
3666-
}
3667-
}
3668-
rcu_read_unlock();
3669-
3670-
spin_lock_irq(&callback_lock);
3671-
cs->mems_allowed = parent->mems_allowed;
3672-
cs->effective_mems = parent->mems_allowed;
3673-
cpumask_copy(cs->cpus_allowed, parent->cpus_allowed);
3674-
cpumask_copy(cs->effective_cpus, parent->cpus_allowed);
3675-
spin_unlock_irq(&callback_lock);
3676-
out_unlock:
36773640
cpuset_full_unlock();
36783641
return 0;
36793642
}

0 commit comments

Comments
 (0)