cgroup, blkcg, memcg: make blkcg depend on memcg on unified hierarchy
Subsystems (6)
Tejun Heo
maintainerPATCH 1/1 cgroup, blkcg, memcg: make blkcg depend on memcg on unified hierarchy
Hello, guys.
Currently, the blkio subsystem attributes all of writeback IOs to the root. One of the issues is that there's no way to tell who originated a writeback IO from block layer. Those IOs are usually issued asynchronously from a task which didn't have anything to do with actually generating the dirty pages. The memory subsystem, when enabled, already keeps track of the ownership of each dirty page and it's desirable for blkio to piggyback instead of adding its own per-page tag.
This can be achieved on the unified hierarchy without too much difficulty. This patchset implements a dependency mechanism in the cgroup such that a subsystem can depends on other subsystems. If available, the depended-upon subsystems are enabled together implicitly when the subsystem is turned on. Implicitly enabled subsystems are invisible and the dependencies are transparent to userland.
This patchset implements the dependency mechanism in cgroup core and make blkcg depend on memcg. This doesn't actually solve the writeback problem yet but is an important step.
This patchset contains the following six patches.
0001-cgroup-reorganize-cgroup_subtree_control_write.patch 0002-cgroup-introduce-cgroup-subtree_control.patch 0003-cgroup-make-interface-files-visible-iff-enabled-on-c.patch 0004-cgroup-implement-cgroup_subsys-css_reset.patch 0005-cgroup-implement-cgroup_subsys-depends_on.patch 0006-blkcg-memcg-make-blkcg-depend-on-memcg-on-the-defaul.patch
0001-0005 gradually implement the dependency mechanism.
0006 makes blkcg depend on memcg.
This patchset is on top of a497c3ba1d97 ("Linux 3.16-rc2") and available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git review-cgroup-dependency
diffstat follows. Thanks.
Documentation/cgroups/cgroups.txt | 14 + Documentation/cgroups/unified-hierarchy.txt | 23 ++- block/blk-cgroup.c | 7 include/linux/cgroup.h | 20 ++ kernel/cgroup.c | 201 ++++++++++++++++++++++------ mm/memcontrol.c | 24 +++ 6 files changed, 243 insertions(+), 46 deletions(-)
--
tejun
Tejun Heo
maintainerPATCH 1/6 cgroup: reorganize cgroup_subtree_control_write()
Make the following two reorganizations to cgroup_subtree_control_write(). These are to prepare for future changes and shouldn't cause any functional difference.
* Move availability above css offlining wait.
* Move cgrp->child_subsys_mask update above new css creation.
--- kernel/cgroup.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
kernel/cgroup.c +17 -17
@@ -2613,6 +2613,14 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,continue ; } +/* unavailable or not enabled on the parent? */ +if (!(cgrp_dfl_root.subsys_mask & (1 << ssid)) || + (cgroup_parent (cgrp) && + !(cgroup_parent (cgrp)->child_subsys_mask & (1 << ssid)))) { + ret = -ENOENT ; + goto out_unlock; + } +/* * Because css offlining is asynchronous, userland * might try to re-enable the same controller while
@@ -2635,14 +2643,6 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,return restart_syscall (); } - -/* unavailable or not enabled on the parent? */ -if (!(cgrp_dfl_root.subsys_mask & (1 << ssid)) || - (cgroup_parent (cgrp) && - !(cgroup_parent (cgrp)->child_subsys_mask & (1 << ssid)))) { - ret = -ENOENT ; - goto out_unlock; - } }else if (disable & (1 << ssid)) {if (!(cgrp->child_subsys_mask & (1 << ssid))) { disable &= ~(1 << ssid);
@@ -2673,12 +2673,10 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of, goto out_unlock; } -/* -* Create csses for enables and update child_subsys_mask. This -* changes cgroup_e_css() results which in turn makes the -* subsequent cgroup_update_dfl_csses() associate all tasks in the -* subtree to the updated csses. -*/ + cgrp->child_subsys_mask |= enable; + cgrp->child_subsys_mask &= ~disable; + +/* create new csses */ for_each_subsys (ss, ssid) {if (!(enable & (1 << ssid)))continue ;
@@ -2690,9 +2688,11 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of, } } - cgrp->child_subsys_mask |= enable; - cgrp->child_subsys_mask &= ~disable; - +/* +* At this point, cgroup_e_css() results reflect the new csses +* making the following cgroup_update_dfl_csses() properly update +* css associations of all tasks in the subtree. +*/ ret =cgroup_update_dfl_csses (cgrp);if (ret) goto err_undo_css;
Signature · 1 line
1.9.3
Tejun Heo
maintainerPATCH 2/6 cgroup: introduce cgroup->subtree_control
In reply to Tejun Heocgroup is implementing support for subsystem dependency which would require a way to enable a subsystem even when it's not directly configured through "cgroup.subtree_control".
Previously, cgroup->child_subsys_mask directly reflected "cgroup.subtree_control" and the enabled subsystems in the child cgroups. This patch adds cgroup->subtree_control which "cgroup.subtree_control" operates on. cgroup->child_subsys_mask is now calculated from cgroup->subtree_control by cgroup_refresh_child_subsys_mask(), which sets it identical to cgroup->subtree_control for now.
This will allow using cgroup->child_subsys_mask for all the enabled subsystems including the implicit ones and ->subtree_control for tracking the explicitly requested ones. This patch keeps the two masks identical and doesn't introduce any behavior changes.
--- include/linux/cgroup.h | 8 +++++++- kernel/cgroup.c | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 36 insertions(+), 18 deletions(-)
include/linux/cgroup.h +7 -1
@@ -203,7 +203,13 @@ struct cgroup {struct kernfs_node *kn;/* cgroup kernfs entry */ struct kernfs_node *populated_kn;/* kn for "cgroup.subtree_populated" */ -/* the bitmask of subsystems enabled on the child cgroups */ +/* +* The bitmask of subsystems enabled on the child cgroups. +* ->subtree_control is the one configured through +* "cgroup.subtree_control" while ->child_subsys_mask is the +* effective one which may have more subsystems enabled. +*/ +unsigned int subtree_control;unsigned int child_subsys_mask;/* Private pointers for each registered subsystem */
kernel/cgroup.c +29 -17
122 lines not on this page · raw message
Signature · 1 line
1.9.3
Tejun Heo
maintainerPATCH 3/6 cgroup: make interface files visible iff enabled on cgroup->subtree_control
In reply to Tejun Heocgroup is implementing support for subsystem dependency which would require a way to enable a subsystem even when it's not directly configured through "cgroup.subtree_control".
The preceding patch distinguished cgroup->subtree_control and ->child_subsys_mask where the former is the subsystems explicitly configured by the userland and the latter is all enabled subsystems currently is equal to the former but will include subsystems implicitly enabled through dependency.
Subsystems which are enabled due to dependency shouldn't be visible to userland. This patch updates cgroup_subtree_control_write() and create_css() such that interface files are not created for implicitly enabled subsytems.
* @visible paramter is added to create_css(). Interface files are created only when true.
* If an already implicitly enabled subsystem is turned on through "cgroup.subtree_control", the existing css should be used. css draining is skipped.
* cgroup_subtree_control_write() computes the new target cgroup->child_subsys_mask and create/kill or show/hide csses accordingly.
As the two subsystem masks are still kept identical, this patch doesn't introduce any behavior changes.
--- include/linux/cgroup.h | 2 ++ kernel/cgroup.c | 78 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 14 deletions(-)
include/linux/cgroup.h +2 -0
@@ -208,6 +208,8 @@ struct cgroup {* ->subtree_control is the one configured through * "cgroup.subtree_control" while ->child_subsys_mask is the * effective one which may have more subsystems enabled. +* Controller knobs are made available iff it's enabled in +* ->subtree_control. */ unsigned int subtree_control;unsigned int child_subsys_mask;
kernel/cgroup.c +64 -14
149 lines not on this page · raw message
Signature · 1 line
1.9.3
Tejun Heo
maintainerPATCH 4/6 cgroup: implement cgroup_subsys->css_reset()
In reply to Tejun Heocgroup is implementing support for subsystem dependency which would require a way to enable a subsystem even when it's not directly configured through "cgroup.subtree_control".
The previous patches added support for explicitly and implicitly enabled subsystems and showing/hiding their interface files. An explicitly enabled subsystem may become implicitly enabled if it's turned off through "cgroup.subtree_control" but there are subsystems depending on it. In such cases, the subsystem, as it's turned off when seen from userland, shouldn't enforce any resource control. Also, the subsystem may be explicitly turned on later again and its interface files should be as close to the intial state as possible.
This patch adds cgroup_subsys->css_reset() which is invoked when a css is hidden. The callback should disable resource control and reset the state to the vanilla state.
--- Documentation/cgroups/cgroups.txt | 14 ++++++++++++++ include/linux/cgroup.h | 1 + kernel/cgroup.c | 16 ++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-)
Documentation/cgroups/cgroups.txt +14 -0
@@ -599,6 +599,20 @@ fork. If this method returns 0 (success) then this should remain valid while the caller holds cgroup_mutex and it is ensured that either attach() or cancel_attach() will be called in future. +void css_reset(struct cgroup_subsys_state *css) +(cgroup_mutex held by caller) + +An optional operation which should restore @css's configuration to the +initial state. This is currently only used on the unified hierarchy +when a subsystem is disabled on a cgroup through +"cgroup.subtree_control" but should remain enabled because other +subsystems depend on it. cgroup core makes such a css invisible by +removing the associated interface files and invokes this callback so +that the hidden subsystem can return to the initial neutral state. +This prevents unexpected resource control from a hidden css and +ensures that the configuration is in the initial state when it is made +visible again later. + void cancel_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) (cgroup_mutex held by caller)
include/linux/cgroup.h +1 -0
@@ -642,6 +642,7 @@ struct cgroup_subsys {int (*css_online)(struct cgroup_subsys_state *css);void (*css_offline)(struct cgroup_subsys_state *css);void (*css_free)(struct cgroup_subsys_state *css); +void (*css_reset)(struct cgroup_subsys_state *css);int (*can_attach)(struct cgroup_subsys_state *css,struct cgroup_taskset *tset);
kernel/cgroup.c +12 -4
@@ -2740,17 +2740,25 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,/* * All tasks are migrated out of disabled csses. Kill or hide * them. A css is hidden when the userland requests it to be -* disabled while other subsystems are still depending on it. +* disabled while other subsystems are still depending on it. The +* css must not actively control resources and be in the vanilla +* state if it's made visible again later. Controllers which may +* be depended upon should provide ->css_reset() for this purpose. */ for_each_subsys (ss, ssid) {if (!(disable & (1 << ssid)))continue ;cgroup_for_each_live_child (child, cgrp) { -if (css_disable & (1 << ssid)) -kill_css (cgroup_css (child, ss)); -else +struct cgroup_subsys_state *css =cgroup_css (child, ss); + +if (css_disable & (1 << ssid)) { +kill_css (css); + }else {cgroup_clear_dir (child,1 << ssid); +if (ss->css_reset) + ss->css_reset (css); + } } }
Signature · 1 line
1.9.3
Tejun Heo
maintainerPATCH 5/6 cgroup: implement cgroup_subsys->depends_on
In reply to Tejun HeoCurrently, the blkio subsystem attributes all of writeback IOs to the root. One of the issues is that there's no way to tell who originated a writeback IO from block layer. Those IOs are usually issued asynchronously from a task which didn't have anything to do with actually generating the dirty pages. The memory subsystem, when enabled, already keeps track of the ownership of each dirty page and it's desirable for blkio to piggyback instead of adding its own per-page tag.
blkio piggybacking on memory is an implementation detail which preferably should be handled automatically without requiring explicit userland action. To achieve that, this patch implements cgroup_subsys->depends_on which contains the mask of subsystems which should be enabled together when the subsystem is enabled.
The previous patches already implemented the support for enabled but invisible subsystems and cgroup_subsys->depends_on can be easily implemented by updating cgroup_refresh_child_subsys_mask() so that it calculates cgroup->child_subsys_mask considering cgroup_subsys->depends_on of the explicitly enabled subsystems.
Documentation/cgroups/unified-hierarchy.txt is updated to explain that subsystems may not become immediately available after being unused from userland and that dependency could be a factor in it. As subsystems may already keep residual references, this doesn't significantly change how subsystem rebinding can be used.
--- Documentation/cgroups/unified-hierarchy.txt | 23 ++++++++++++-- include/linux/cgroup.h | 9 ++++++ kernel/cgroup.c | 49 ++++++++++++++++++++++++++++- 3 files changed, 77 insertions(+), 4 deletions(-)
Documentation/cgroups/unified-hierarchy.txt +20 -3
@@ -97,9 +97,26 @@ change soon. All controllers which are not bound to other hierarchies are automatically bound to unified hierarchy and show up at the root of it. Controllers which are enabled only in the root of unified -hierarchy can be bound to other hierarchies at any time. This allows -mixing unified hierarchy with the traditional multiple hierarchies in -a fully backward compatible way. +hierarchy can be bound to other hierarchies. This allows mixing +unified hierarchy with the traditional multiple hierarchies in a fully +backward compatible way. + +A controller can be moved across hierarchies only after the controller +is no longer referenced in its current hierarchy. Because per-cgroup +controller states are destroyed asynchronously and controllers may +have lingering references, a controller may not show up immediately on +the unified hierarchy after the final umount of the previous +hierarchy. Similarly, a controller should be fully disabled to be +moved out of the unified hierarchy and it may take some time for the +disabled controller to become available for other hierarchies; +furthermore, due to dependencies among controllers, other controllers +may need to be disabled too. + +While useful for development and manual configurations, dynamically +moving controllers between the unified and other hierarchies is +strongly discouraged for production use. It is recommended to decide +the hierarchies and controller associations before starting using the +controllers. 2-2. cgroup.subtree_control
include/linux/cgroup.h +9 -0
@@ -693,6 +693,15 @@ struct cgroup_subsys {/* base cftypes, automatically registered with subsys itself */ struct cftype *base_cftypes; + +/* +* A subsystem may depend on other subsystems. When such subsystem +* is enabled on a cgroup, the depended-upon subsystems are enabled +* together if available. Subsystems enabled due to dependency are +* not visible to userland until explicitly enabled. The following +* specifies the mask of subsystems that this one depends on. +*/ +unsigned int depends_on; };#define SUBSYS (_x) extern struct cgroup_subsys _x ## _cgrp_subsys;
kernel/cgroup.c +48 -1
57 lines not on this page · raw message
Signature · 1 line
1.9.3
Tejun Heo
maintainerPATCH 6/6 blkcg, memcg: make blkcg depend on memcg on the default hierarchy
In reply to Tejun HeoCurrently, the blkio subsystem attributes all of writeback IOs to the root. One of the issues is that there's no way to tell who originated a writeback IO from block layer. Those IOs are usually issued asynchronously from a task which didn't have anything to do with actually generating the dirty pages. The memory subsystem, when enabled, already keeps track of the ownership of each dirty page and it's desirable for blkio to piggyback instead of adding its own per-page tag.
cgroup now has a mechanism to express such dependency - cgroup_subsys->depends_on. This patch declares that blkcg depends on memcg so that memcg is enabled automatically on the default hierarchy when available. Future changes will make blkcg map the memcg tag to find out the cgroup to blame for writeback IOs.
As this means that a memcg may be made invisible, this patch also implements css_reset() for memcg which resets its basic configurations. This implementation will probably need to be expanded to cover other states which are used in the default hierarchy.
--- block/blk-cgroup.c | 7 +++++++ mm/memcontrol.c | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
block/blk-cgroup.c +7 -0
@@ -925,6 +925,13 @@ struct cgroup_subsys blkio_cgrp_subsys = { .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, .base_cftypes = blkcg_files, + +/* +* This ensures that, if available, memcg is automatically enabled +* together on the default hierarchy so that the owner cgroup can +* be retrieved from writeback pages. +*/ + .depends_on = 1 << memory_cgrp_id, };EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);
mm/memcontrol.c +24 -0
@@ -6407,6 +6407,29 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)__mem_cgroup_free (memcg); } +/** +* mem_cgroup_css_reset - reset the states of a mem_cgroup +* @css: the target css +* +* Reset the states of the mem_cgroup associated with @css. This is +* invoked when the userland requests disabling on the default hierarchy +* but the memcg is pinned through dependency. The memcg should stop +* applying policies and should revert to the vanilla state as it may be +* made visible again. +* +* The current implementation only resets the essential configurations. +* This needs to be expanded to cover all the visible parts. +*/ +static void mem_cgroup_css_reset (struct cgroup_subsys_state *css) +{ +struct mem_cgroup *memcg =mem_cgroup_from_css (css); + +mem_cgroup_resize_limit (memcg,ULLONG_MAX ); +mem_cgroup_resize_memsw_limit (memcg,ULLONG_MAX ); +memcg_update_kmem_limit (memcg,ULLONG_MAX ); +res_counter_set_soft_limit (&memcg->res,ULLONG_MAX ); +} +#ifdef CONFIG_MMU /* Handlers for move charge at task migration. */ #define PRECHARGE_COUNT_AT_ONCE 256
@@ -7019,6 +7042,7 @@ struct cgroup_subsys memory_cgrp_subsys = { .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline, .css_free = mem_cgroup_css_free, + .css_reset = mem_cgroup_css_reset, .can_attach = mem_cgroup_can_attach, .cancel_attach = mem_cgroup_cancel_attach, .attach = mem_cgroup_move_task,
Signature · 1 line
1.9.3
Tejun Heo
maintainerPATCH v2 6/6 blkcg, memcg: make blkcg depend on memcg on the default hierarchy
From 8e67ad03ab03839456816e922c57a7ab3bcf5474 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Sat, 28 Jun 2014 07:47:57 -0400
Currently, the blkio subsystem attributes all of writeback IOs to the root. One of the issues is that there's no way to tell who originated a writeback IO from block layer. Those IOs are usually issued asynchronously from a task which didn't have anything to do with actually generating the dirty pages. The memory subsystem, when enabled, already keeps track of the ownership of each dirty page and it's desirable for blkio to piggyback instead of adding its own per-page tag.
cgroup now has a mechanism to express such dependency - cgroup_subsys->depends_on. This patch declares that blkcg depends on memcg so that memcg is enabled automatically on the default hierarchy when available. Future changes will make blkcg map the memcg tag to find out the cgroup to blame for writeback IOs.
As this means that a memcg may be made invisible, this patch also implements css_reset() for memcg which resets its basic configurations. This implementation will probably need to be expanded to cover other states which are used in the default hierarchy.
v2: blkcg's dependency on memcg is wrapped with CONFIG_MEMCG to avoid
build failure. Reported by kbuild test robot.
--- block/blk-cgroup.c | 8 ++++++++ mm/memcontrol.c | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
block/blk-cgroup.c +8 -0
@@ -925,6 +925,14 @@ struct cgroup_subsys blkio_cgrp_subsys = { .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, .base_cftypes = blkcg_files, +#ifdef CONFIG_MEMCG +/* +* This ensures that, if available, memcg is automatically enabled +* together on the default hierarchy so that the owner cgroup can +* be retrieved from writeback pages. +*/ + .depends_on =1 << memory_cgrp_id, +#endif };EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);
mm/memcontrol.c +24 -0
@@ -6407,6 +6407,29 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)__mem_cgroup_free (memcg); } +/** +* mem_cgroup_css_reset - reset the states of a mem_cgroup +* @css: the target css +* +* Reset the states of the mem_cgroup associated with @css. This is +* invoked when the userland requests disabling on the default hierarchy +* but the memcg is pinned through dependency. The memcg should stop +* applying policies and should revert to the vanilla state as it may be +* made visible again. +* +* The current implementation only resets the essential configurations. +* This needs to be expanded to cover all the visible parts. +*/ +static void mem_cgroup_css_reset (struct cgroup_subsys_state *css) +{ +struct mem_cgroup *memcg =mem_cgroup_from_css (css); + +mem_cgroup_resize_limit (memcg,ULLONG_MAX ); +mem_cgroup_resize_memsw_limit (memcg,ULLONG_MAX ); +memcg_update_kmem_limit (memcg,ULLONG_MAX ); +res_counter_set_soft_limit (&memcg->res,ULLONG_MAX ); +} +#ifdef CONFIG_MMU /* Handlers for move charge at task migration. */ #define PRECHARGE_COUNT_AT_ONCE 256
@@ -7019,6 +7042,7 @@ struct cgroup_subsys memory_cgrp_subsys = { .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline, .css_free = mem_cgroup_css_free, + .css_reset = mem_cgroup_css_reset, .can_attach = mem_cgroup_can_attach, .cancel_attach = mem_cgroup_cancel_attach, .attach = mem_cgroup_move_task,
Signature · 1 line
1.9.3
Re: [PATCH v2 6/6] blkcg, memcg: make blkcg depend on memcg on the default hierarchy
Quoted 19 lines · Tejun Heo
Quoted 1 line
From
8e67ad03ab03839456816e922c57a7ab3bcf5474Mon Sep 17 00:00:00 2001From: Tejun Heo <[email protected]>
Date: Sat, 28 Jun 2014 07:47:57 -0400Currently, the blkio subsystem attributes all of writeback IOs to the root. One of the issues is that there's no way to tell who originated a writeback IO from block layer. Those IOs are usually issued asynchronously from a task which didn't have anything to do with actually generating the dirty pages. The memory subsystem, when enabled, already keeps track of the ownership of each dirty page and it's desirable for blkio to piggyback instead of adding its own per-page tag.
cgroup now has a mechanism to express such dependency -
cgroup_subsys->depends_on. This patch declares that blkcg depends on memcg so that memcg is enabled automatically on the default hierarchy when available. Future changes will make blkcg map the memcg tag to find out the cgroup to blame for writeback IOs.
Quoted 8 lines
As this means that a memcg may be made invisible, this patch also implements
css_reset()for memcg which resets its basic configurations. This implementation will probably need to be expanded to cover other states which are used in the default hierarchy.v2: blkcg's dependency on memcg is wrapped with
CONFIG_MEMCGto avoid
build failure. Reported by kbuild test robot.
Hi Tejun,
I have couple questions about new semantics. Following is my understanding. Is it right?
- So after this change one can not use blkio controller on unified hiearchy if memory controller is mounted on some other hierarchy and is not available for mounting unified hiearchy.
- If blkio controller is enabled on unified hiearchy (memory controller implicitly enabled), then one can't mount memory controller on other hierarchies without first disabling blkio controller on unified hiearchy.
I think this change makes sense. memory controller already knows which cgroup dirtied the page and making use of same data by forcing memory and blkio to be mounted together should work.
There are some cases where people don't want to use blkio because of overhead, and in that case, they can simply not enable blkio controller on children (which memory controller can still be enabled on children).
Thanks
Vivek
Quoted 73 lines
Signed-off-by Tejun Heo <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vivek Goyal <[email protected]>Cc Jens Axboe <[email protected]>--- block/blk-cgroup.c | 8 ++++++++ mm/memcontrol.c | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)block/blk-cgroup.c +8
-0@@ -925,6 +925,14 @@ struct cgroup_subsys blkio_cgrp_subsys = { .css_free = blkcg_css_free, .can_attach = blkcg_can_attach, .base_cftypes = blkcg_files, +#ifdef CONFIG_MEMCG +/* +* This ensures that, if available, memcg is automatically enabled +* together on the default hierarchy so that the owner cgroup can +* be retrieved from writeback pages. +*/ + .depends_on =1 << memory_cgrp_id, +#endif };EXPORT_SYMBOL_GPL (blkio_cgrp_subsys);mm/memcontrol.c +24
-0@@ -6407,6 +6407,29 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)__mem_cgroup_free (memcg); } +/** +* mem_cgroup_css_reset - reset the states of a mem_cgroup +* @css: the target css +* +* Reset the states of the mem_cgroup associated with @css. This is +* invoked when the userland requests disabling on the default hierarchy +* but the memcg is pinned through dependency. The memcg should stop +* applying policies and should revert to the vanilla state as it may be +* made visible again. +* +* The current implementation only resets the essential configurations. +* This needs to be expanded to cover all the visible parts. +*/ +static void mem_cgroup_css_reset (struct cgroup_subsys_state *css) +{ +struct mem_cgroup *memcg =mem_cgroup_from_css (css); + +mem_cgroup_resize_limit (memcg,ULLONG_MAX ); +mem_cgroup_resize_memsw_limit (memcg,ULLONG_MAX ); +memcg_update_kmem_limit (memcg,ULLONG_MAX ); +res_counter_set_soft_limit (&memcg->res,ULLONG_MAX ); +} +#ifdef CONFIG_MMU /* Handlers for move charge at task migration. */ #define PRECHARGE_COUNT_AT_ONCE 256@@ -7019,6 +7042,7 @@ struct cgroup_subsys memory_cgrp_subsys = { .css_online = mem_cgroup_css_online, .css_offline = mem_cgroup_css_offline, .css_free = mem_cgroup_css_free, + .css_reset = mem_cgroup_css_reset, .can_attach = mem_cgroup_can_attach, .cancel_attach = mem_cgroup_cancel_attach, .attach = mem_cgroup_move_task,Signature · 1 line
1.9.3
Tejun Heo
maintainerRe: [PATCH v2 6/6] blkcg, memcg: make blkcg depend on memcg on the default hierarchy
Hello, Vivek.
Quoted 6 lines · Vivek Goyal
I have couple questions about new semantics. Following is my understanding. Is it right?
- So after this change one can not use blkio controller on unified hiearchy if memory controller is mounted on some other hierarchy and is not available for mounting unified hiearchy.
Hmmm? No, the only behavior which changes is when both blkcg and memcg are mounted on the unified hierarchy. Nothing else changes. The dependency behavior kicks in iff memcg is available on the unified hierarchy.
Quoted 3 lines
- If blkio controller is enabled on unified hiearchy (memory controller implicitly enabled), then one can't mount memory controller on other hierarchies without first disabling blkio controller on unified hiearchy.
Yes, blkio needs to be disabled to the root for memcg to be able to become free. This is an extra restriction but I don't think it's anything drastic. Once a controller starts being actively used on any hierarchy, nothing has been guaranteed about when the controller would become free again even if the whole hierarchy is reduced to the root.
Thanks.
Signature · 1 line
tejun
Re: [PATCH v2 6/6] blkcg, memcg: make blkcg depend on memcg on the default hierarchy
Quoted 6 lines · Tejun Heo
Hello, Vivek.
Quoted 3 lines · Vivek Goyal
I have couple questions about new semantics. Following is my understanding. Is it right?
Quoted 8 lines
Quoted 3 lines
- So after this change one can not use blkio controller on unified hiearchy if memory controller is mounted on some other hierarchy and is not available for mounting unified hiearchy.
Hmmm? No, the only behavior which changes is when both blkcg and memcg are mounted on the unified hierarchy. Nothing else changes. The dependency behavior kicks in iff memcg is available on the unified hierarchy.
Ok, good to know that dependency kicks in only if controlle being depended on is available on the hierarchy.
Quoted 10 lines
Quoted 4 lines
- If blkio controller is enabled on unified hiearchy (memory controller implicitly enabled), then one can't mount memory controller on other hierarchies without first disabling blkio controller on unified hiearchy.
Yes, blkio needs to be disabled to the root for memcg to be able to become free. This is an extra restriction but I don't think it's anything drastic. Once a controller starts being actively used on any hierarchy, nothing has been guaranteed about when the controller would become free again even if the whole hierarchy is reduced to the root.
Agreed. Thanks for the clarification.
Thanks
Vivek
Hi Tejun,
Quoted 10 lines · Tejun Heo
Hello, guys.
Currently, the blkio subsystem attributes all of writeback IOs to the root. One of the issues is that there's no way to tell who originated a writeback IO from block layer. Those IOs are usually issued asynchronously from a task which didn't have anything to do with actually generating the dirty pages. The memory subsystem, when enabled, already keeps track of the ownership of each dirty page and it's desirable for blkio to piggyback instead of adding its own per-page tag.
It's great to see this being worked on!
Quoted 33 lines
This can be achieved on the unified hierarchy without too much difficulty. This patchset implements a dependency mechanism in the cgroup such that a subsystem can depends on other subsystems. If available, the depended-upon subsystems are enabled together implicitly when the subsystem is turned on. Implicitly enabled subsystems are invisible and the dependencies are transparent to userland.
This patchset implements the dependency mechanism in cgroup core and make blkcg depend on memcg. This doesn't actually solve the writeback problem yet but is an important step.
This patchset contains the following six patches.
0001-cgroup-reorganize-cgroup_subtree_control_write.patch 0002-cgroup-introduce-cgroup-subtree_control.patch 0003-cgroup-make-interface-files-visible-iff-enabled-on-c.patch 0004-cgroup-implement-cgroup_subsys-css_reset.patch 0005-cgroup-implement-cgroup_subsys-depends_on.patch 0006-blkcg-memcg-make-blkcg-depend-on-memcg-on-the-defaul.patch
0001-0005 gradually implement the dependency mechanism.
0006 makes blkcg depend on memcg.
This patchset is on top of
a497c3ba1d97("Linux 3.16-rc2") and available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.gitreview-cgroup-dependencydiffstat follows. Thanks.
Quoted 8 lines
Documentation/cgroups/cgroups.txt | 14 + Documentation/cgroups/unified-hierarchy.txt | 23 ++- block/blk-cgroup.c | 7 include/linux/cgroup.h | 20 ++ kernel/cgroup.c | 201 ++++++++++++++++++++++------ mm/memcontrol.c | 24 +++ 6 files changed, 243 insertions(+), 46 deletions(-)
Quoted 23 lines · Tejun Heo
Hello, guys.
Currently, the blkio subsystem attributes all of writeback IOs to the root. One of the issues is that there's no way to tell who originated a writeback IO from block layer. Those IOs are usually issued asynchronously from a task which didn't have anything to do with actually generating the dirty pages. The memory subsystem, when enabled, already keeps track of the ownership of each dirty page and it's desirable for blkio to piggyback instead of adding its own per-page tag.
This can be achieved on the unified hierarchy without too much difficulty. This patchset implements a dependency mechanism in the cgroup such that a subsystem can depends on other subsystems. If available, the depended-upon subsystems are enabled together implicitly when the subsystem is turned on. Implicitly enabled subsystems are invisible and the dependencies are transparent to userland.
This patchset implements the dependency mechanism in cgroup core and make blkcg depend on memcg. This doesn't actually solve the writeback problem yet but is an important step.
Quoted 8 lines
This patchset contains the following six patches.
0001-cgroup-reorganize-cgroup_subtree_control_write.patch 0002-cgroup-introduce-cgroup-subtree_control.patch 0003-cgroup-make-interface-files-visible-iff-enabled-on-c.patch 0004-cgroup-implement-cgroup_subsys-css_reset.patch 0005-cgroup-implement-cgroup_subsys-depends_on.patch 0006-blkcg-memcg-make-blkcg-depend-on-memcg-on-the-defaul.patch
These look good to me.
We can update memcg's ->css_reset() as we re-populate the interface in the default hierarchy.
Applied to cgroup/for-3.17.
Thanks.
Signature · 1 line
tejun