History

cgroup: rstat: support cgroup1

Rstat currently only supports the default hierarchy in cgroup2. In order to replace memcg's private stats infrastructure - used in both cgroup1 and cgroup2 - with rstat, the latter needs to support cgroup1. The initialization and destruction callbacks for regular cgroups are already in place. Remove the cgroup_on_dfl() guards to handle cgroup1. The initialization of the root cgroup is currently hardcoded to only handle cgrp_dfl_root.cgrp. Move those callbacks to cgroup_setup_root() and cgroup_destroy_root() to handle the default root as well as the various cgroup1 roots we may set up during mounting. The linking of css to cgroups happens in code shared between cgroup1 and cgroup2 as well. Simply remove the cgroup_on_dfl() guard. Linkage of the root css to the root cgroup is a bit trickier: per default, the root css of a subsystem controller belongs to the default hierarchy (i.e. the cgroup2 root). When a controller is mounted in its cgroup1 version, the root css is stolen and moved to the cgroup1 root; on unmount, the css moves back to the default hierarchy. Annotate rebind_subsystems() to move the root css linkage along between roots.

Johannes Weiner committed 5 years ago

Commit a7df69b1 parent a18e6e62 files · +21 −15Browse files

Showing the changes to kernel (2 of 2 files). Show all

Unified · Split

2 files
  1. kernel/cgroup/cgroup.c +21 −13
  2. kernel/cgroup/rstat.c +0 −2
kernel/cgroup/cgroup.c+21−13
@@ -1339,6 +1339,7 @@ static void cgroup_destroy_root(struct cgroup_root *root) · 1338 unmodified lines
13391339
13401340 mutex_unlock(&cgroup_mutex);
13411341
1342+ cgroup_rstat_exit(cgrp);
13421343 kernfs_destroy_root(root->kf_root);
13431344 cgroup_free_root(root);
13441345 }
@@ -1751,6 +1752,12 @@ int rebind_subsystems(struct cgroup_root *dst_root, u16 ss_mask) · 406 unmodified lines
17511752 &dcgrp->e_csets[ss->id]);
17521753 spin_unlock_irq(&css_set_lock);
17531754
1755+ if (ss->css_rstat_flush) {
1756+ list_del_rcu(&css->rstat_css_node);
1757+ list_add_rcu(&css->rstat_css_node,
1758+ &dcgrp->rstat_css_list);
1759+ }
1760+
17541761 /* default hierarchy doesn't enable controllers by default */
17551762 dst_root->subsys_mask |= 1 << ssid;
17561763 if (dst_root == &cgrp_dfl_root) {
@@ -1971,10 +1978,14 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask) · 214 unmodified lines
19711978 if (ret)
19721979 goto destroy_root;
19731980
1974− ret = rebind_subsystems(root, ss_mask);
1981+ ret = cgroup_rstat_init(root_cgrp);
19751982 if (ret)
19761983 goto destroy_root;
19771984
1985+ ret = rebind_subsystems(root, ss_mask);
1986+ if (ret)
1987+ goto exit_stats;
1988+
19781989 ret = cgroup_bpf_inherit(root_cgrp);
19791990 WARN_ON_ONCE(ret);
19801991
@@ -2006,6 +2017,8 @@ int cgroup_setup_root(struct cgroup_root *root, u16 ss_mask) · 25 unmodified lines
20062017 ret = 0;
20072018 goto out;
20082019
2020+exit_stats:
2021+ cgroup_rstat_exit(root_cgrp);
20092022 destroy_root:
20102023 kernfs_destroy_root(root->kf_root);
20112024 root->kf_root = NULL;
@@ -4934,8 +4947,7 @@ static void css_free_rwork_fn(struct work_struct *work) · 2922 unmodified lines
49344947 cgroup_put(cgroup_parent(cgrp));
49354948 kernfs_put(cgrp->kn);
49364949 psi_cgroup_free(cgrp);
4937− if (cgroup_on_dfl(cgrp))
4938− cgroup_rstat_exit(cgrp);
4950+ cgroup_rstat_exit(cgrp);
49394951 kfree(cgrp);
49404952 } else {
49414953 /*
@@ -4976,8 +4988,7 @@ static void css_release_work_fn(struct work_struct *work) · 34 unmodified lines
49764988 /* cgroup release path */
49774989 TRACE_CGROUP_PATH(release, cgrp);
49784990
4979− if (cgroup_on_dfl(cgrp))
4980− cgroup_rstat_flush(cgrp);
4991+ cgroup_rstat_flush(cgrp);
49814992
49824993 spin_lock_irq(&css_set_lock);
49834994 for (tcgrp = cgroup_parent(cgrp); tcgrp;
@@ -5034,7 +5045,7 @@ static void init_and_link_css(struct cgroup_subsys_state *css, · 50 unmodified lines
50345045 css_get(css->parent);
50355046 }
50365047
5037− if (cgroup_on_dfl(cgrp) && ss->css_rstat_flush)
5048+ if (ss->css_rstat_flush)
50385049 list_add_rcu(&css->rstat_css_node, &cgrp->rstat_css_list);
50395050
50405051 BUG_ON(cgroup_css(cgrp, ss));
@@ -5159,11 +5170,9 @@ static struct cgroup *cgroup_create(struct cgroup *parent, const char *name, · 118 unmodified lines
51595170 if (ret)
51605171 goto out_free_cgrp;
51615172
5162− if (cgroup_on_dfl(parent)) {
5163− ret = cgroup_rstat_init(cgrp);
5164− if (ret)
5165− goto out_cancel_ref;
5166− }
5173+ ret = cgroup_rstat_init(cgrp);
5174+ if (ret)
5175+ goto out_cancel_ref;
51675176
51685177 /* create the directory */
51695178 kn = kernfs_create_dir(parent->kn, name, mode, cgrp);
@@ -5250,8 +5259,7 @@ out_psi_free: · 80 unmodified lines
52505259 out_kernfs_remove:
52515260 kernfs_remove(cgrp->kn);
52525261 out_stat_exit:
5253− if (cgroup_on_dfl(parent))
5254− cgroup_rstat_exit(cgrp);
5262+ cgroup_rstat_exit(cgrp);
52555263 out_cancel_ref:
52565264 percpu_ref_exit(&cgrp->self.refcnt);
52575265 out_free_cgrp:
kernel/cgroup/rstat.c+0−2
@@ -285,8 +285,6 @@ void __init cgroup_rstat_boot(void) · 284 unmodified lines
285285
286286 for_each_possible_cpu(cpu)
287287 raw_spin_lock_init(per_cpu_ptr(&cgroup_rstat_cpu_lock, cpu));
288−
289− BUG_ON(cgroup_rstat_init(&cgrp_dfl_root.cgrp));
290288 }
291289
292290 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t