Re: [PATCH 2/2] cgroup: reset css on destruction

Vladimir Davydov
2016-03-01T16:56:44Z

On Tue, Mar 01, 2016 at 11:30:18AM -0500, Tejun Heo wrote:
> On Tue, Mar 01, 2016 at 02:13:13PM +0300, Vladimir Davydov wrote:
> > @@ -5138,6 +5138,8 @@ static void kill_css(struct cgroup_subsys_state *css)
> > * See seq_css() for details.
> > */
> > css_clear_dir(css, NULL);
> > + if (css->ss->css_reset)
> > + css->ss->css_reset(css);
>
> I think the better spot for this is in offline_css() right before
> ->css_offline() is called.

Okay, here it goes.
---
From: Vladimir Davydov <vdavydov@virtuozzo.com>
Subject: [PATCH] cgroup: reset css on destruction

An associated css can be around for quite a while after a cgroup
directory has been removed. In general, it makes sense to reset it to
defaults so as not to worry about any remnants. For instance, memory
cgroup needs to reset memory.low, otherwise pages charged to a dead
cgroup might never get reclaimed. There's ->css_reset callback, which
would fit perfectly for the purpose. Currently, it's only called when a
subsystem is disabled in the unified hierarchy and there are other
subsystems dependant on it. Let's call it on css destruction as well.

Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index cc40463e7b69..bb1900b70b01 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4876,6 +4876,9 @@ static void offline_css(struct cgroup_subsys_state *css)
if (!(css->flags & CSS_ONLINE))
return;

+ if (ss->css_reset)
+ ss->css_reset(css);
+
if (ss->css_offline)
ss->css_offline(css);