Skip to content

Commit 69dc801

Browse files
committed
Merge branch 'for-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup updates from Tejun Heo: "Two cpuset behavior changes: - cpuset on cgroup2 is changed to enable memory migration based on nodemask by default. - A notification is generated when cpuset partition state changes. All other patches are minor fixes and cleanups" * 'for-5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: cgroup: Avoid compiler warnings with no subsystems cgroup/cpuset: Avoid memory migration when nodemasks match cgroup/cpuset: Enable memory migration for cpuset v2 cgroup/cpuset: Enable event notification when partition state changes cgroup: cgroup-v1: clean up kernel-doc notation cgroup: Replace deprecated CPU-hotplug functions. cgroup/cpuset: Fix violation of cpuset locking rule cgroup/cpuset: Fix a partition bug with hotplug cgroup/cpuset: Miscellaneous code cleanup cgroup: remove cgroup_mount from comments
2 parents 81b0b29 + d20d30e commit 69dc801

File tree

4 files changed

+144
-64
lines changed

4 files changed

+144
-64
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,17 @@ Cpuset Interface Files
20562056
The value of "cpuset.mems" stays constant until the next update
20572057
and won't be affected by any memory nodes hotplug events.
20582058

2059+
Setting a non-empty value to "cpuset.mems" causes memory of
2060+
tasks within the cgroup to be migrated to the designated nodes if
2061+
they are currently using memory outside of the designated nodes.
2062+
2063+
There is a cost for this memory migration. The migration
2064+
may not be complete and some memory pages may be left behind.
2065+
So it is recommended that "cpuset.mems" should be set properly
2066+
before spawning new tasks into the cpuset. Even if there is
2067+
a need to change "cpuset.mems" with active tasks, it shouldn't
2068+
be done frequently.
2069+
20592070
cpuset.mems.effective
20602071
A read-only multiple values file which exists on all
20612072
cpuset-enabled cgroups.

kernel/cgroup/cgroup-v1.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ bool cgroup1_ssid_disabled(int ssid)
5050
* cgroup_attach_task_all - attach task 'tsk' to all cgroups of task 'from'
5151
* @from: attach to all cgroups of a given task
5252
* @tsk: the task to be attached
53+
*
54+
* Return: %0 on success or a negative errno code on failure
5355
*/
5456
int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
5557
{
@@ -80,7 +82,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
8082
EXPORT_SYMBOL_GPL(cgroup_attach_task_all);
8183

8284
/**
83-
* cgroup_trasnsfer_tasks - move tasks from one cgroup to another
85+
* cgroup_transfer_tasks - move tasks from one cgroup to another
8486
* @to: cgroup to which the tasks will be moved
8587
* @from: cgroup in which the tasks currently reside
8688
*
@@ -89,6 +91,8 @@ EXPORT_SYMBOL_GPL(cgroup_attach_task_all);
8991
* is guaranteed to be either visible in the source cgroup after the
9092
* parent's migration is complete or put into the target cgroup. No task
9193
* can slip out of migration through forking.
94+
*
95+
* Return: %0 on success or a negative errno code on failure
9296
*/
9397
int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from)
9498
{
@@ -682,6 +686,8 @@ int proc_cgroupstats_show(struct seq_file *m, void *v)
682686
*
683687
* Build and fill cgroupstats so that taskstats can export it to user
684688
* space.
689+
*
690+
* Return: %0 on success or a negative errno code on failure
685691
*/
686692
int cgroupstats_build(struct cgroupstats *stats, struct dentry *dentry)
687693
{

kernel/cgroup/cgroup.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@
6767
/* let's not notify more than 100 times per second */
6868
#define CGROUP_FILE_NOTIFY_MIN_INTV DIV_ROUND_UP(HZ, 100)
6969

70+
/*
71+
* To avoid confusing the compiler (and generating warnings) with code
72+
* that attempts to access what would be a 0-element array (i.e. sized
73+
* to a potentially empty array when CGROUP_SUBSYS_COUNT == 0), this
74+
* constant expression can be added.
75+
*/
76+
#define CGROUP_HAS_SUBSYS_CONFIG (CGROUP_SUBSYS_COUNT > 0)
77+
7078
/*
7179
* cgroup_mutex is the master lock. Any modification to cgroup or its
7280
* hierarchy must be performed while holding it.
@@ -248,7 +256,7 @@ static int cgroup_addrm_files(struct cgroup_subsys_state *css,
248256
*/
249257
bool cgroup_ssid_enabled(int ssid)
250258
{
251-
if (CGROUP_SUBSYS_COUNT == 0)
259+
if (!CGROUP_HAS_SUBSYS_CONFIG)
252260
return false;
253261

254262
return static_key_enabled(cgroup_subsys_enabled_key[ssid]);
@@ -472,7 +480,7 @@ static u16 cgroup_ss_mask(struct cgroup *cgrp)
472480
static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp,
473481
struct cgroup_subsys *ss)
474482
{
475-
if (ss)
483+
if (CGROUP_HAS_SUBSYS_CONFIG && ss)
476484
return rcu_dereference_check(cgrp->subsys[ss->id],
477485
lockdep_is_held(&cgroup_mutex));
478486
else
@@ -550,6 +558,9 @@ struct cgroup_subsys_state *cgroup_e_css(struct cgroup *cgrp,
550558
{
551559
struct cgroup_subsys_state *css;
552560

561+
if (!CGROUP_HAS_SUBSYS_CONFIG)
562+
return NULL;
563+
553564
do {
554565
css = cgroup_css(cgrp, ss);
555566

@@ -577,6 +588,9 @@ struct cgroup_subsys_state *cgroup_get_e_css(struct cgroup *cgrp,
577588
{
578589
struct cgroup_subsys_state *css;
579590

591+
if (!CGROUP_HAS_SUBSYS_CONFIG)
592+
return NULL;
593+
580594
rcu_read_lock();
581595

582596
do {
@@ -647,7 +661,7 @@ struct cgroup_subsys_state *of_css(struct kernfs_open_file *of)
647661
* the matching css from the cgroup's subsys table is guaranteed to
648662
* be and stay valid until the enclosing operation is complete.
649663
*/
650-
if (cft->ss)
664+
if (CGROUP_HAS_SUBSYS_CONFIG && cft->ss)
651665
return rcu_dereference_raw(cgrp->subsys[cft->ss->id]);
652666
else
653667
return &cgrp->self;
@@ -695,7 +709,7 @@ EXPORT_SYMBOL_GPL(of_css);
695709
*/
696710
#define do_each_subsys_mask(ss, ssid, ss_mask) do { \
697711
unsigned long __ss_mask = (ss_mask); \
698-
if (!CGROUP_SUBSYS_COUNT) { /* to avoid spurious gcc warning */ \
712+
if (!CGROUP_HAS_SUBSYS_CONFIG) { \
699713
(ssid) = 0; \
700714
break; \
701715
} \
@@ -2169,7 +2183,6 @@ static void cgroup_kill_sb(struct super_block *sb)
21692183
/*
21702184
* If @root doesn't have any children, start killing it.
21712185
* This prevents new mounts by disabling percpu_ref_tryget_live().
2172-
* cgroup_mount() may wait for @root's release.
21732186
*
21742187
* And don't kill the default root.
21752188
*/
@@ -2373,7 +2386,7 @@ struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset,
23732386
struct css_set *cset = tset->cur_cset;
23742387
struct task_struct *task = tset->cur_task;
23752388

2376-
while (&cset->mg_node != tset->csets) {
2389+
while (CGROUP_HAS_SUBSYS_CONFIG && &cset->mg_node != tset->csets) {
23772390
if (!task)
23782391
task = list_first_entry(&cset->mg_tasks,
23792392
struct task_struct, cg_list);
@@ -4644,7 +4657,7 @@ void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags,
46444657
it->ss = css->ss;
46454658
it->flags = flags;
46464659

4647-
if (it->ss)
4660+
if (CGROUP_HAS_SUBSYS_CONFIG && it->ss)
46484661
it->cset_pos = &css->cgroup->e_csets[css->ss->id];
46494662
else
46504663
it->cset_pos = &css->cgroup->cset_links;

0 commit comments

Comments
 (0)