* [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg()
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
@ 2013-04-03 9:11 ` Li Zefan
2013-04-03 12:58 ` Glauber Costa
[not found] ` <515BF249.50607-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-03 9:12 ` [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache Li Zefan
` (7 subsequent siblings)
8 siblings, 2 replies; 48+ messages in thread
From: Li Zefan @ 2013-04-03 9:11 UTC (permalink / raw)
To: linux-mm
Cc: LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
Use css_get/css_put instead of mem_cgroup_get/put.
Note, if at the same time someone is moving @current to a different
cgroup and removing the old cgroup, css_tryget() may return false,
and sock->sk_cgrp won't be initialized.
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
mm/memcontrol.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 23d0f6e..43ca91d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -536,15 +536,15 @@ void sock_update_memcg(struct sock *sk)
*/
if (sk->sk_cgrp) {
BUG_ON(mem_cgroup_is_root(sk->sk_cgrp->memcg));
- mem_cgroup_get(sk->sk_cgrp->memcg);
+ css_get(&sk->sk_cgrp->memcg->css);
return;
}
rcu_read_lock();
memcg = mem_cgroup_from_task(current);
cg_proto = sk->sk_prot->proto_cgroup(memcg);
- if (!mem_cgroup_is_root(memcg) && memcg_proto_active(cg_proto)) {
- mem_cgroup_get(memcg);
+ if (!mem_cgroup_is_root(memcg) &&
+ memcg_proto_active(cg_proto) && css_tryget(&memcg->css)) {
sk->sk_cgrp = cg_proto;
}
rcu_read_unlock();
@@ -558,7 +558,7 @@ void sock_release_memcg(struct sock *sk)
struct mem_cgroup *memcg;
WARN_ON(!sk->sk_cgrp->memcg);
memcg = sk->sk_cgrp->memcg;
- mem_cgroup_put(memcg);
+ css_put(&sk->sk_cgrp->memcg->css);
}
}
--
1.8.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg()
2013-04-03 9:11 ` [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg() Li Zefan
@ 2013-04-03 12:58 ` Glauber Costa
2013-04-03 15:29 ` Michal Hocko
[not found] ` <515BF249.50607-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
1 sibling, 1 reply; 48+ messages in thread
From: Glauber Costa @ 2013-04-03 12:58 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
On 04/03/2013 01:11 PM, Li Zefan wrote:
> Use css_get/css_put instead of mem_cgroup_get/put.
>
> Note, if at the same time someone is moving @current to a different
> cgroup and removing the old cgroup, css_tryget() may return false,
> and sock->sk_cgrp won't be initialized.
>
> Signed-off-by: Li Zefan <lizefan@huawei.com>
> ---
> mm/memcontrol.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 23d0f6e..43ca91d 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -536,15 +536,15 @@ void sock_update_memcg(struct sock *sk)
> */
> if (sk->sk_cgrp) {
> BUG_ON(mem_cgroup_is_root(sk->sk_cgrp->memcg));
> - mem_cgroup_get(sk->sk_cgrp->memcg);
> + css_get(&sk->sk_cgrp->memcg->css);
> return;
> }
>
> rcu_read_lock();
> memcg = mem_cgroup_from_task(current);
> cg_proto = sk->sk_prot->proto_cgroup(memcg);
> - if (!mem_cgroup_is_root(memcg) && memcg_proto_active(cg_proto)) {
> - mem_cgroup_get(memcg);
> + if (!mem_cgroup_is_root(memcg) &&
> + memcg_proto_active(cg_proto) && css_tryget(&memcg->css)) {
> sk->sk_cgrp = cg_proto;
> }
What happens if this tryget fails ? Won't we leak a reference here? We
will put regardless when the socket is released, and this may go
negative. No?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg()
2013-04-03 12:58 ` Glauber Costa
@ 2013-04-03 15:29 ` Michal Hocko
[not found] ` <20130403152934.GL16471-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
0 siblings, 1 reply; 48+ messages in thread
From: Michal Hocko @ 2013-04-03 15:29 UTC (permalink / raw)
To: Glauber Costa
Cc: Li Zefan, linux-mm, LKML, Cgroups, Tejun Heo, KAMEZAWA Hiroyuki,
Johannes Weiner
On Wed 03-04-13 16:58:48, Glauber Costa wrote:
> On 04/03/2013 01:11 PM, Li Zefan wrote:
> > Use css_get/css_put instead of mem_cgroup_get/put.
> >
> > Note, if at the same time someone is moving @current to a different
> > cgroup and removing the old cgroup, css_tryget() may return false,
> > and sock->sk_cgrp won't be initialized.
> >
> > Signed-off-by: Li Zefan <lizefan@huawei.com>
> > ---
> > mm/memcontrol.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 23d0f6e..43ca91d 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -536,15 +536,15 @@ void sock_update_memcg(struct sock *sk)
> > */
> > if (sk->sk_cgrp) {
> > BUG_ON(mem_cgroup_is_root(sk->sk_cgrp->memcg));
> > - mem_cgroup_get(sk->sk_cgrp->memcg);
> > + css_get(&sk->sk_cgrp->memcg->css);
I am not sure I understand this one. So we have a goup here (which means
that somebody already took a reference on it, right?) and we are taking
another reference. If this is released by sock_release_memcg then who
releases the previous one? It is not directly related to the patch
because this has been done previously already. Could you clarify
Glauber, please?
> > return;
> > }
> >
> > rcu_read_lock();
> > memcg = mem_cgroup_from_task(current);
> > cg_proto = sk->sk_prot->proto_cgroup(memcg);
> > - if (!mem_cgroup_is_root(memcg) && memcg_proto_active(cg_proto)) {
> > - mem_cgroup_get(memcg);
> > + if (!mem_cgroup_is_root(memcg) &&
> > + memcg_proto_active(cg_proto) && css_tryget(&memcg->css)) {
> > sk->sk_cgrp = cg_proto;
> > }
>
> What happens if this tryget fails ? Won't we leak a reference here? We
> will put regardless when the socket is released, and this may go
> negative. No?
AFAICS sock_release_memcg releases the reference only if sk->sk_cgrp and
that one wouldn't be set if css_tryget fails.
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread
[parent not found: <515BF249.50607-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg()
[not found] ` <515BF249.50607-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2013-04-05 5:01 ` Kamezawa Hiroyuki
2013-04-05 13:39 ` Michal Hocko
1 sibling, 0 replies; 48+ messages in thread
From: Kamezawa Hiroyuki @ 2013-04-05 5:01 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups, Tejun Heo,
Glauber Costa, Michal Hocko, Johannes Weiner
(2013/04/03 18:11), Li Zefan wrote:
> Use css_get/css_put instead of mem_cgroup_get/put.
>
> Note, if at the same time someone is moving @current to a different
> cgroup and removing the old cgroup, css_tryget() may return false,
> and sock->sk_cgrp won't be initialized.
>
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Thank you.
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg()
[not found] ` <515BF249.50607-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-05 5:01 ` Kamezawa Hiroyuki
@ 2013-04-05 13:39 ` Michal Hocko
1 sibling, 0 replies; 48+ messages in thread
From: Michal Hocko @ 2013-04-05 13:39 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups, Tejun Heo,
Glauber Costa, KAMEZAWA Hiroyuki, Johannes Weiner
On Wed 03-04-13 17:11:37, Li Zefan wrote:
> Use css_get/css_put instead of mem_cgroup_get/put.
>
> Note, if at the same time someone is moving @current to a different
> cgroup and removing the old cgroup, css_tryget() may return false,
> and sock->sk_cgrp won't be initialized.
>
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Acked-by: Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>
> ---
> mm/memcontrol.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 23d0f6e..43ca91d 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -536,15 +536,15 @@ void sock_update_memcg(struct sock *sk)
> */
> if (sk->sk_cgrp) {
> BUG_ON(mem_cgroup_is_root(sk->sk_cgrp->memcg));
> - mem_cgroup_get(sk->sk_cgrp->memcg);
> + css_get(&sk->sk_cgrp->memcg->css);
> return;
> }
>
> rcu_read_lock();
> memcg = mem_cgroup_from_task(current);
> cg_proto = sk->sk_prot->proto_cgroup(memcg);
> - if (!mem_cgroup_is_root(memcg) && memcg_proto_active(cg_proto)) {
> - mem_cgroup_get(memcg);
> + if (!mem_cgroup_is_root(memcg) &&
> + memcg_proto_active(cg_proto) && css_tryget(&memcg->css)) {
> sk->sk_cgrp = cg_proto;
> }
> rcu_read_unlock();
> @@ -558,7 +558,7 @@ void sock_release_memcg(struct sock *sk)
> struct mem_cgroup *memcg;
> WARN_ON(!sk->sk_cgrp->memcg);
> memcg = sk->sk_cgrp->memcg;
> - mem_cgroup_put(memcg);
> + css_put(&sk->sk_cgrp->memcg->css);
> }
> }
>
> --
> 1.8.0.2
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 48+ messages in thread
* [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
2013-04-03 9:11 ` [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg() Li Zefan
@ 2013-04-03 9:12 ` Li Zefan
2013-04-03 13:05 ` Glauber Costa
` (2 more replies)
2013-04-03 9:12 ` [RFC][PATCH 3/7] memcg: use css_get/put when charging/uncharging kmem Li Zefan
` (6 subsequent siblings)
8 siblings, 3 replies; 48+ messages in thread
From: Li Zefan @ 2013-04-03 9:12 UTC (permalink / raw)
To: linux-mm
Cc: LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
Use css_get()/css_put() instead of mem_cgroup_get()/mem_cgroup_put().
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
mm/memcontrol.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 43ca91d..dafacb8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3191,7 +3191,7 @@ void memcg_release_cache(struct kmem_cache *s)
list_del(&s->memcg_params->list);
mutex_unlock(&memcg->slab_caches_mutex);
- mem_cgroup_put(memcg);
+ css_put(&memcg->css);
out:
kfree(s->memcg_params);
}
@@ -3350,16 +3350,18 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
mutex_lock(&memcg_cache_mutex);
new_cachep = cachep->memcg_params->memcg_caches[idx];
- if (new_cachep)
+ if (new_cachep) {
+ css_put(&memcg->css);
goto out;
+ }
new_cachep = kmem_cache_dup(memcg, cachep);
if (new_cachep == NULL) {
new_cachep = cachep;
+ css_put(&memcg->css);
goto out;
}
- mem_cgroup_get(memcg);
atomic_set(&new_cachep->memcg_params->nr_pages , 0);
cachep->memcg_params->memcg_caches[idx] = new_cachep;
@@ -3449,8 +3451,6 @@ static void memcg_create_cache_work_func(struct work_struct *w)
cw = container_of(w, struct create_work, work);
memcg_create_kmem_cache(cw->memcg, cw->cachep);
- /* Drop the reference gotten when we enqueued. */
- css_put(&cw->memcg->css);
kfree(cw);
}
--
1.8.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache
2013-04-03 9:12 ` [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache Li Zefan
@ 2013-04-03 13:05 ` Glauber Costa
2013-04-03 15:31 ` Michal Hocko
[not found] ` <515BF275.5080408-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2 siblings, 0 replies; 48+ messages in thread
From: Glauber Costa @ 2013-04-03 13:05 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
On 04/03/2013 01:12 PM, Li Zefan wrote:
> Use css_get()/css_put() instead of mem_cgroup_get()/mem_cgroup_put().
>
> Signed-off-by: Li Zefan <lizefan@huawei.com>
> ---
> mm/memcontrol.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 43ca91d..dafacb8 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3191,7 +3191,7 @@ void memcg_release_cache(struct kmem_cache *s)
> list_del(&s->memcg_params->list);
> mutex_unlock(&memcg->slab_caches_mutex);
>
> - mem_cgroup_put(memcg);
> + css_put(&memcg->css);
> out:
> kfree(s->memcg_params);
> }
> @@ -3350,16 +3350,18 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
>
> mutex_lock(&memcg_cache_mutex);
> new_cachep = cachep->memcg_params->memcg_caches[idx];
> - if (new_cachep)
> + if (new_cachep) {
> + css_put(&memcg->css);
> goto out;
> + }
>
> new_cachep = kmem_cache_dup(memcg, cachep);
> if (new_cachep == NULL) {
> new_cachep = cachep;
> + css_put(&memcg->css);
> goto out;
> }
>
> - mem_cgroup_get(memcg);
> atomic_set(&new_cachep->memcg_params->nr_pages , 0);
>
> cachep->memcg_params->memcg_caches[idx] = new_cachep;
> @@ -3449,8 +3451,6 @@ static void memcg_create_cache_work_func(struct work_struct *w)
>
> cw = container_of(w, struct create_work, work);
> memcg_create_kmem_cache(cw->memcg, cw->cachep);
> - /* Drop the reference gotten when we enqueued. */
> - css_put(&cw->memcg->css);
> kfree(cw);
> }
>
>
At first look, this one seems all right.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache
2013-04-03 9:12 ` [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache Li Zefan
2013-04-03 13:05 ` Glauber Costa
@ 2013-04-03 15:31 ` Michal Hocko
[not found] ` <20130403153133.GM16471-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
[not found] ` <515BF275.5080408-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2 siblings, 1 reply; 48+ messages in thread
From: Michal Hocko @ 2013-04-03 15:31 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Glauber Costa,
KAMEZAWA Hiroyuki, Johannes Weiner
On Wed 03-04-13 17:12:21, Li Zefan wrote:
> Use css_get()/css_put() instead of mem_cgroup_get()/mem_cgroup_put().
>
> Signed-off-by: Li Zefan <lizefan@huawei.com>
> ---
> mm/memcontrol.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 43ca91d..dafacb8 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3191,7 +3191,7 @@ void memcg_release_cache(struct kmem_cache *s)
> list_del(&s->memcg_params->list);
> mutex_unlock(&memcg->slab_caches_mutex);
>
> - mem_cgroup_put(memcg);
> + css_put(&memcg->css);
> out:
> kfree(s->memcg_params);
> }
> @@ -3350,16 +3350,18 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
>
> mutex_lock(&memcg_cache_mutex);
> new_cachep = cachep->memcg_params->memcg_caches[idx];
> - if (new_cachep)
> + if (new_cachep) {
> + css_put(&memcg->css);
> goto out;
> + }
>
> new_cachep = kmem_cache_dup(memcg, cachep);
> if (new_cachep == NULL) {
> new_cachep = cachep;
> + css_put(&memcg->css);
> goto out;
> }
>
> - mem_cgroup_get(memcg);
> atomic_set(&new_cachep->memcg_params->nr_pages , 0);
>
> cachep->memcg_params->memcg_caches[idx] = new_cachep;
> @@ -3449,8 +3451,6 @@ static void memcg_create_cache_work_func(struct work_struct *w)
>
> cw = container_of(w, struct create_work, work);
> memcg_create_kmem_cache(cw->memcg, cw->cachep);
> - /* Drop the reference gotten when we enqueued. */
> - css_put(&cw->memcg->css);
> kfree(cw);
> }
You are putting references but I do not see any single css_{try}get
here. /me puzzled.
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread[parent not found: <515BF275.5080408-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache
[not found] ` <515BF275.5080408-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2013-04-05 5:51 ` Kamezawa Hiroyuki
2013-04-05 13:46 ` Michal Hocko
0 siblings, 1 reply; 48+ messages in thread
From: Kamezawa Hiroyuki @ 2013-04-05 5:51 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups, Tejun Heo,
Glauber Costa, Michal Hocko, Johannes Weiner
(2013/04/03 18:12), Li Zefan wrote:
> Use css_get()/css_put() instead of mem_cgroup_get()/mem_cgroup_put().
>
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> ---
> mm/memcontrol.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 43ca91d..dafacb8 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3191,7 +3191,7 @@ void memcg_release_cache(struct kmem_cache *s)
> list_del(&s->memcg_params->list);
> mutex_unlock(&memcg->slab_caches_mutex);
>
> - mem_cgroup_put(memcg);
> + css_put(&memcg->css);
> out:
> kfree(s->memcg_params);
> }
> @@ -3350,16 +3350,18 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
>
> mutex_lock(&memcg_cache_mutex);
> new_cachep = cachep->memcg_params->memcg_caches[idx];
> - if (new_cachep)
> + if (new_cachep) {
> + css_put(&memcg->css);
> goto out;
> + }
Where css_get() against this is done ?
Thanks,
-Kame
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache
2013-04-05 5:51 ` Kamezawa Hiroyuki
@ 2013-04-05 13:46 ` Michal Hocko
0 siblings, 0 replies; 48+ messages in thread
From: Michal Hocko @ 2013-04-05 13:46 UTC (permalink / raw)
To: Kamezawa Hiroyuki
Cc: Li Zefan, linux-mm, LKML, Cgroups, Tejun Heo, Glauber Costa,
Johannes Weiner
On Fri 05-04-13 14:51:10, KAMEZAWA Hiroyuki wrote:
> (2013/04/03 18:12), Li Zefan wrote:
> > Use css_get()/css_put() instead of mem_cgroup_get()/mem_cgroup_put().
> >
> > Signed-off-by: Li Zefan <lizefan@huawei.com>
> > ---
> > mm/memcontrol.c | 10 +++++-----
> > 1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 43ca91d..dafacb8 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -3191,7 +3191,7 @@ void memcg_release_cache(struct kmem_cache *s)
> > list_del(&s->memcg_params->list);
> > mutex_unlock(&memcg->slab_caches_mutex);
> >
> > - mem_cgroup_put(memcg);
> > + css_put(&memcg->css);
> > out:
> > kfree(s->memcg_params);
> > }
> > @@ -3350,16 +3350,18 @@ static struct kmem_cache *memcg_create_kmem_cache(struct mem_cgroup *memcg,
> >
> > mutex_lock(&memcg_cache_mutex);
> > new_cachep = cachep->memcg_params->memcg_caches[idx];
> > - if (new_cachep)
> > + if (new_cachep) {
> > + css_put(&memcg->css);
> > goto out;
> > + }
>
> Where css_get() against this is done ?
As glauber explained in another email in this thread. It was
__memcg_create_cache_enqueue which took the reference.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 48+ messages in thread
* [RFC][PATCH 3/7] memcg: use css_get/put when charging/uncharging kmem
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
2013-04-03 9:11 ` [RFC][PATCH 1/7] memcg: use css_get in sock_update_memcg() Li Zefan
2013-04-03 9:12 ` [RFC][PATCH 2/7] memcg: don't use mem_cgroup_get() when creating a kmemcg cache Li Zefan
@ 2013-04-03 9:12 ` Li Zefan
[not found] ` <515BF284.7060401-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-03 9:12 ` [RFC][PATCH 4/7] memcg: use css_get/put for swap memcg Li Zefan
` (5 subsequent siblings)
8 siblings, 1 reply; 48+ messages in thread
From: Li Zefan @ 2013-04-03 9:12 UTC (permalink / raw)
To: linux-mm
Cc: LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
Use css_get/put instead of mem_cgroup_get/put.
We can't do a simple replacement, because here mem_cgroup_put()
is called during mem_cgroup_css_free(), while mem_cgroup_css_free()
won't be called until css refcnt goes down to 0.
Instead we increment css refcnt in mem_cgroup_css_offline(), and
then check if there's still kmem charges. If not, css refcnt will
be decremented, otherwise the refcnt will be decremented when
kmem charges goes down to 0.
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
mm/memcontrol.c | 49 ++++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 23 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index dafacb8..877551d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3004,7 +3004,7 @@ static void memcg_uncharge_kmem(struct mem_cgroup *memcg, u64 size)
return;
if (memcg_kmem_test_and_clear_dead(memcg))
- mem_cgroup_put(memcg);
+ css_put(&memcg->css);
}
void memcg_cache_list_add(struct mem_cgroup *memcg, struct kmem_cache *cachep)
@@ -5089,14 +5089,6 @@ static int memcg_update_kmem_limit(struct cgroup *cont, u64 val)
* starts accounting before all call sites are patched
*/
memcg_kmem_set_active(memcg);
-
- /*
- * kmem charges can outlive the cgroup. In the case of slab
- * pages, for instance, a page contain objects from various
- * processes, so it is unfeasible to migrate them away. We
- * need to reference count the memcg because of that.
- */
- mem_cgroup_get(memcg);
} else
ret = res_counter_set_limit(&memcg->kmem, val);
out:
@@ -5129,12 +5121,11 @@ static int memcg_propagate_kmem(struct mem_cgroup *memcg)
goto out;
/*
- * destroy(), called if we fail, will issue static_key_slow_inc() and
- * mem_cgroup_put() if kmem is enabled. We have to either call them
- * unconditionally, or clear the KMEM_ACTIVE flag. I personally find
- * this more consistent, since it always leads to the same destroy path
+ * destroy(), called if we fail, will issue static_key_slow_dec() if
+ * kmem is enabled. We have to either call them unconditionally, or
+ * clear the KMEM_ACTIVE flag. I personally find this more consistent,
+ * since it always leads to the same destroy path
*/
- mem_cgroup_get(memcg);
static_key_slow_inc(&memcg_kmem_enabled_key);
mutex_lock(&set_limit_mutex);
@@ -5823,23 +5814,33 @@ static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
return mem_cgroup_sockets_init(memcg, ss);
};
-static void kmem_cgroup_destroy(struct mem_cgroup *memcg)
+static void kmem_cgroup_css_offline(struct mem_cgroup *memcg)
{
- mem_cgroup_sockets_destroy(memcg);
+ /*
+ * kmem charges can outlive the cgroup. In the case of slab
+ * pages, for instance, a page contain objects from various
+ * processes, so it is unfeasible to migrate them away. We
+ * need to reference count the memcg because of that.
+ */
+ css_get(&memcg->css);
+ /*
+ * We need to call css_get() first, because memcg_uncharge_kmem()
+ * will call css_put() if it sees the memcg is dead.
+ */
memcg_kmem_mark_dead(memcg);
if (res_counter_read_u64(&memcg->kmem, RES_USAGE) != 0)
return;
/*
- * Charges already down to 0, undo mem_cgroup_get() done in the charge
- * path here, being careful not to race with memcg_uncharge_kmem: it is
- * possible that the charges went down to 0 between mark_dead and the
- * res_counter read, so in that case, we don't need the put
+ * Charges already down to 0, undo css_get() done previosly,, being
+ * careful not to race with memcg_uncharge_kmem: it is possible that
+ * the charges went down to 0 between mark_dead and the res_counter
+ * read, so in that case, we don't need the put
*/
if (memcg_kmem_test_and_clear_dead(memcg))
- mem_cgroup_put(memcg);
+ css_put(&memcg->css);
}
#else
static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
@@ -5847,7 +5848,7 @@ static int memcg_init_kmem(struct mem_cgroup *memcg, struct cgroup_subsys *ss)
return 0;
}
-static void kmem_cgroup_destroy(struct mem_cgroup *memcg)
+static void kmem_cgroup_css_offline(struct mem_cgroup *memcg)
{
}
#endif
@@ -6274,6 +6275,8 @@ static void mem_cgroup_css_offline(struct cgroup *cont)
{
struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
+ kmem_cgroup_css_offline(memcg);
+
mem_cgroup_invalidate_reclaim_iterators(memcg);
mem_cgroup_reparent_charges(memcg);
mem_cgroup_destroy_all_caches(memcg);
@@ -6283,7 +6286,7 @@ static void mem_cgroup_css_free(struct cgroup *cont)
{
struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
- kmem_cgroup_destroy(memcg);
+ mem_cgroup_sockets_destroy(memcg);
mem_cgroup_put(memcg);
}
--
1.8.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 48+ messages in thread* [RFC][PATCH 4/7] memcg: use css_get/put for swap memcg
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
` (2 preceding siblings ...)
2013-04-03 9:12 ` [RFC][PATCH 3/7] memcg: use css_get/put when charging/uncharging kmem Li Zefan
@ 2013-04-03 9:12 ` Li Zefan
2013-04-04 11:25 ` Michal Hocko
2013-04-05 5:56 ` Kamezawa Hiroyuki
2013-04-03 9:13 ` [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children Li Zefan
` (4 subsequent siblings)
8 siblings, 2 replies; 48+ messages in thread
From: Li Zefan @ 2013-04-03 9:12 UTC (permalink / raw)
To: linux-mm
Cc: LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
Use css_get/put instead of mem_cgroup_get/put.
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
mm/memcontrol.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 877551d..ad576e8 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4137,12 +4137,12 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype,
unlock_page_cgroup(pc);
/*
* even after unlock, we have memcg->res.usage here and this memcg
- * will never be freed.
+ * will never be freed, so it's safe to call css_get().
*/
memcg_check_events(memcg, page);
if (do_swap_account && ctype == MEM_CGROUP_CHARGE_TYPE_SWAPOUT) {
mem_cgroup_swap_statistics(memcg, true);
- mem_cgroup_get(memcg);
+ css_get(&memcg->css);
}
/*
* Migration does not charge the res_counter for the
@@ -4242,7 +4242,7 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
/*
* record memcg information, if swapout && memcg != NULL,
- * mem_cgroup_get() was called in uncharge().
+ * css_get() was called in uncharge().
*/
if (do_swap_account && swapout && memcg)
swap_cgroup_record(ent, css_id(&memcg->css));
@@ -4273,7 +4273,7 @@ void mem_cgroup_uncharge_swap(swp_entry_t ent)
if (!mem_cgroup_is_root(memcg))
res_counter_uncharge(&memcg->memsw, PAGE_SIZE);
mem_cgroup_swap_statistics(memcg, false);
- mem_cgroup_put(memcg);
+ css_put(&memcg->css);
}
rcu_read_unlock();
}
@@ -4307,11 +4307,14 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
* This function is only called from task migration context now.
* It postpones res_counter and refcount handling till the end
* of task migration(mem_cgroup_clear_mc()) for performance
- * improvement. But we cannot postpone mem_cgroup_get(to)
- * because if the process that has been moved to @to does
- * swap-in, the refcount of @to might be decreased to 0.
+ * improvement. But we cannot postpone css_get(to) because if
+ * the process that has been moved to @to does swap-in, the
+ * refcount of @to might be decreased to 0.
+ *
+ * We are in attach() phase, so the cgroup is guaranteed to be
+ * alive, so we can just call css_get().
*/
- mem_cgroup_get(to);
+ css_get(&to->css);
return 0;
}
return -EINVAL;
@@ -6597,6 +6600,7 @@ static void __mem_cgroup_clear_mc(void)
{
struct mem_cgroup *from = mc.from;
struct mem_cgroup *to = mc.to;
+ int i;
/* we must uncharge all the leftover precharges from mc.to */
if (mc.precharge) {
@@ -6617,7 +6621,9 @@ static void __mem_cgroup_clear_mc(void)
if (!mem_cgroup_is_root(mc.from))
res_counter_uncharge(&mc.from->memsw,
PAGE_SIZE * mc.moved_swap);
- __mem_cgroup_put(mc.from, mc.moved_swap);
+
+ for (i = 0; i < mc.moved_swap; i++)
+ css_put(&mc.from->css);
if (!mem_cgroup_is_root(mc.to)) {
/*
@@ -6627,7 +6633,7 @@ static void __mem_cgroup_clear_mc(void)
res_counter_uncharge(&mc.to->res,
PAGE_SIZE * mc.moved_swap);
}
- /* we've already done mem_cgroup_get(mc.to) */
+ /* we've already done css_get(mc.to) */
mc.moved_swap = 0;
}
memcg_oom_recover(from);
--
1.8.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 4/7] memcg: use css_get/put for swap memcg
2013-04-03 9:12 ` [RFC][PATCH 4/7] memcg: use css_get/put for swap memcg Li Zefan
@ 2013-04-04 11:25 ` Michal Hocko
2013-04-05 5:56 ` Kamezawa Hiroyuki
1 sibling, 0 replies; 48+ messages in thread
From: Michal Hocko @ 2013-04-04 11:25 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Glauber Costa,
KAMEZAWA Hiroyuki, Johannes Weiner
On Wed 03-04-13 17:12:54, Li Zefan wrote:
> Use css_get/put instead of mem_cgroup_get/put.
>
> Signed-off-by: Li Zefan <lizefan@huawei.com>
Looks good to me. Swapped in pages still use css_tryget so they would
fallback to recharge in __mem_cgroup_try_charge_swapin if the group was
removed.
Acked-by: Michal Hocko <mhocko@suse.cz>
Thanks!
> ---
> mm/memcontrol.c | 26 ++++++++++++++++----------
> 1 file changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 877551d..ad576e8 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4137,12 +4137,12 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype,
> unlock_page_cgroup(pc);
> /*
> * even after unlock, we have memcg->res.usage here and this memcg
> - * will never be freed.
> + * will never be freed, so it's safe to call css_get().
> */
> memcg_check_events(memcg, page);
> if (do_swap_account && ctype == MEM_CGROUP_CHARGE_TYPE_SWAPOUT) {
> mem_cgroup_swap_statistics(memcg, true);
> - mem_cgroup_get(memcg);
> + css_get(&memcg->css);
> }
> /*
> * Migration does not charge the res_counter for the
> @@ -4242,7 +4242,7 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
>
> /*
> * record memcg information, if swapout && memcg != NULL,
> - * mem_cgroup_get() was called in uncharge().
> + * css_get() was called in uncharge().
> */
> if (do_swap_account && swapout && memcg)
> swap_cgroup_record(ent, css_id(&memcg->css));
> @@ -4273,7 +4273,7 @@ void mem_cgroup_uncharge_swap(swp_entry_t ent)
> if (!mem_cgroup_is_root(memcg))
> res_counter_uncharge(&memcg->memsw, PAGE_SIZE);
> mem_cgroup_swap_statistics(memcg, false);
> - mem_cgroup_put(memcg);
> + css_put(&memcg->css);
> }
> rcu_read_unlock();
> }
> @@ -4307,11 +4307,14 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
> * This function is only called from task migration context now.
> * It postpones res_counter and refcount handling till the end
> * of task migration(mem_cgroup_clear_mc()) for performance
> - * improvement. But we cannot postpone mem_cgroup_get(to)
> - * because if the process that has been moved to @to does
> - * swap-in, the refcount of @to might be decreased to 0.
> + * improvement. But we cannot postpone css_get(to) because if
> + * the process that has been moved to @to does swap-in, the
> + * refcount of @to might be decreased to 0.
> + *
> + * We are in attach() phase, so the cgroup is guaranteed to be
> + * alive, so we can just call css_get().
> */
> - mem_cgroup_get(to);
> + css_get(&to->css);
> return 0;
> }
> return -EINVAL;
> @@ -6597,6 +6600,7 @@ static void __mem_cgroup_clear_mc(void)
> {
> struct mem_cgroup *from = mc.from;
> struct mem_cgroup *to = mc.to;
> + int i;
>
> /* we must uncharge all the leftover precharges from mc.to */
> if (mc.precharge) {
> @@ -6617,7 +6621,9 @@ static void __mem_cgroup_clear_mc(void)
> if (!mem_cgroup_is_root(mc.from))
> res_counter_uncharge(&mc.from->memsw,
> PAGE_SIZE * mc.moved_swap);
> - __mem_cgroup_put(mc.from, mc.moved_swap);
> +
> + for (i = 0; i < mc.moved_swap; i++)
> + css_put(&mc.from->css);
>
> if (!mem_cgroup_is_root(mc.to)) {
> /*
> @@ -6627,7 +6633,7 @@ static void __mem_cgroup_clear_mc(void)
> res_counter_uncharge(&mc.to->res,
> PAGE_SIZE * mc.moved_swap);
> }
> - /* we've already done mem_cgroup_get(mc.to) */
> + /* we've already done css_get(mc.to) */
> mc.moved_swap = 0;
> }
> memcg_oom_recover(from);
> --
> 1.8.0.2
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 4/7] memcg: use css_get/put for swap memcg
2013-04-03 9:12 ` [RFC][PATCH 4/7] memcg: use css_get/put for swap memcg Li Zefan
2013-04-04 11:25 ` Michal Hocko
@ 2013-04-05 5:56 ` Kamezawa Hiroyuki
1 sibling, 0 replies; 48+ messages in thread
From: Kamezawa Hiroyuki @ 2013-04-05 5:56 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
Johannes Weiner
(2013/04/03 18:12), Li Zefan wrote:
> Use css_get/put instead of mem_cgroup_get/put.
>
> Signed-off-by: Li Zefan <lizefan@huawei.com>
> ---
> mm/memcontrol.c | 26 ++++++++++++++++----------
> 1 file changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 877551d..ad576e8 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4137,12 +4137,12 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype,
> unlock_page_cgroup(pc);
> /*
> * even after unlock, we have memcg->res.usage here and this memcg
> - * will never be freed.
> + * will never be freed, so it's safe to call css_get().
> */
> memcg_check_events(memcg, page);
> if (do_swap_account && ctype == MEM_CGROUP_CHARGE_TYPE_SWAPOUT) {
> mem_cgroup_swap_statistics(memcg, true);
> - mem_cgroup_get(memcg);
> + css_get(&memcg->css);
> }
> /*
> * Migration does not charge the res_counter for the
> @@ -4242,7 +4242,7 @@ mem_cgroup_uncharge_swapcache(struct page *page, swp_entry_t ent, bool swapout)
>
> /*
> * record memcg information, if swapout && memcg != NULL,
> - * mem_cgroup_get() was called in uncharge().
> + * css_get() was called in uncharge().
> */
> if (do_swap_account && swapout && memcg)
> swap_cgroup_record(ent, css_id(&memcg->css));
> @@ -4273,7 +4273,7 @@ void mem_cgroup_uncharge_swap(swp_entry_t ent)
> if (!mem_cgroup_is_root(memcg))
> res_counter_uncharge(&memcg->memsw, PAGE_SIZE);
> mem_cgroup_swap_statistics(memcg, false);
> - mem_cgroup_put(memcg);
> + css_put(&memcg->css);
> }
> rcu_read_unlock();
> }
> @@ -4307,11 +4307,14 @@ static int mem_cgroup_move_swap_account(swp_entry_t entry,
> * This function is only called from task migration context now.
> * It postpones res_counter and refcount handling till the end
> * of task migration(mem_cgroup_clear_mc()) for performance
> - * improvement. But we cannot postpone mem_cgroup_get(to)
> - * because if the process that has been moved to @to does
> - * swap-in, the refcount of @to might be decreased to 0.
> + * improvement. But we cannot postpone css_get(to) because if
> + * the process that has been moved to @to does swap-in, the
> + * refcount of @to might be decreased to 0.
> + *
> + * We are in attach() phase, so the cgroup is guaranteed to be
> + * alive, so we can just call css_get().
> */
> - mem_cgroup_get(to);
> + css_get(&to->css);
> return 0;
> }
> return -EINVAL;
> @@ -6597,6 +6600,7 @@ static void __mem_cgroup_clear_mc(void)
> {
> struct mem_cgroup *from = mc.from;
> struct mem_cgroup *to = mc.to;
> + int i;
>
> /* we must uncharge all the leftover precharges from mc.to */
> if (mc.precharge) {
> @@ -6617,7 +6621,9 @@ static void __mem_cgroup_clear_mc(void)
> if (!mem_cgroup_is_root(mc.from))
> res_counter_uncharge(&mc.from->memsw,
> PAGE_SIZE * mc.moved_swap);
> - __mem_cgroup_put(mc.from, mc.moved_swap);
> +
> + for (i = 0; i < mc.moved_swap; i++)
> + css_put(&mc.from->css);
>
> if (!mem_cgroup_is_root(mc.to)) {
> /*
> @@ -6627,7 +6633,7 @@ static void __mem_cgroup_clear_mc(void)
> res_counter_uncharge(&mc.to->res,
> PAGE_SIZE * mc.moved_swap);
> }
> - /* we've already done mem_cgroup_get(mc.to) */
> + /* we've already done css_get(mc.to) */
> mc.moved_swap = 0;
> }
> memcg_oom_recover(from);
>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread
* [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
` (3 preceding siblings ...)
2013-04-03 9:12 ` [RFC][PATCH 4/7] memcg: use css_get/put for swap memcg Li Zefan
@ 2013-04-03 9:13 ` Li Zefan
[not found] ` <515BF2A4.1070703-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
` (2 more replies)
2013-04-03 9:13 ` [RFC][PATCH 6/7] memcg: don't need to get a reference to the parent Li Zefan
` (3 subsequent siblings)
8 siblings, 3 replies; 48+ messages in thread
From: Li Zefan @ 2013-04-03 9:13 UTC (permalink / raw)
To: linux-mm
Cc: LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
Suppose we rmdir a cgroup and there're still css refs, this cgroup won't
be freed. Then we rmdir the parent cgroup, and the parent is freed due
to css ref draining to 0. Now it would be a disaster if the child cgroup
tries to access its parent.
Make sure this won't happen.
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
kernel/cgroup.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index fa54b92..78204bc 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -888,6 +888,13 @@ static void cgroup_free_fn(struct work_struct *work)
mutex_unlock(&cgroup_mutex);
/*
+ * We get a ref to the parent's dentry, and put the ref when
+ * this cgroup is being freed, so it's guaranteed that the
+ * parent won't be destroyed before its children.
+ */
+ dput(cgrp->parent->dentry);
+
+ /*
* Drop the active superblock reference that we took when we
* created the cgroup
*/
@@ -4171,6 +4178,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
for_each_subsys(root, ss)
dget(dentry);
+ /* hold a ref to the parent's dentry */
+ dget(parent->dentry);
+
/* creation succeeded, notify subsystems */
for_each_subsys(root, ss) {
err = online_css(ss, cgrp);
--
1.8.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 48+ messages in thread[parent not found: <515BF2A4.1070703-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children
[not found] ` <515BF2A4.1070703-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2013-04-04 11:37 ` Michal Hocko
[not found] ` <20130404113750.GH29911-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
0 siblings, 1 reply; 48+ messages in thread
From: Michal Hocko @ 2013-04-04 11:37 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups, Tejun Heo,
Glauber Costa, KAMEZAWA Hiroyuki, Johannes Weiner
On Wed 03-04-13 17:13:08, Li Zefan wrote:
> Suppose we rmdir a cgroup and there're still css refs, this cgroup won't
> be freed. Then we rmdir the parent cgroup, and the parent is freed due
> to css ref draining to 0. Now it would be a disaster if the child cgroup
> tries to access its parent.
Hmm, I am not sure what is the correct layer for this to handle - cgroup
core or memcg. But we have enforced that in mem_cgroup_css_online where
we take an additional reference to the memcg.
Handling it in the memcg code would have an advantage of limiting an
additional reference only to use_hierarchy cases which is sufficient
as we never touch the parent otherwise (parent_mem_cgroup).
So I think this patch should just take css reference to parent during
online and drop it from mem_cgroup_css_free.
If there are more contollers that need this then it should be handled by
the cgroup core of course.
> Make sure this won't happen.
>
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
> ---
> kernel/cgroup.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index fa54b92..78204bc 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -888,6 +888,13 @@ static void cgroup_free_fn(struct work_struct *work)
> mutex_unlock(&cgroup_mutex);
>
> /*
> + * We get a ref to the parent's dentry, and put the ref when
> + * this cgroup is being freed, so it's guaranteed that the
> + * parent won't be destroyed before its children.
> + */
> + dput(cgrp->parent->dentry);
> +
> + /*
> * Drop the active superblock reference that we took when we
> * created the cgroup
> */
> @@ -4171,6 +4178,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
> for_each_subsys(root, ss)
> dget(dentry);
>
> + /* hold a ref to the parent's dentry */
> + dget(parent->dentry);
> +
> /* creation succeeded, notify subsystems */
> for_each_subsys(root, ss) {
> err = online_css(ss, cgrp);
> --
> 1.8.0.2
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 48+ messages in thread
* Re: [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children
2013-04-03 9:13 ` [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children Li Zefan
[not found] ` <515BF2A4.1070703-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2013-04-04 15:31 ` Michal Hocko
2013-04-05 5:58 ` Kamezawa Hiroyuki
2 siblings, 0 replies; 48+ messages in thread
From: Michal Hocko @ 2013-04-04 15:31 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Glauber Costa,
KAMEZAWA Hiroyuki, Johannes Weiner
On Wed 03-04-13 17:13:08, Li Zefan wrote:
> Suppose we rmdir a cgroup and there're still css refs, this cgroup won't
> be freed. Then we rmdir the parent cgroup, and the parent is freed due
> to css ref draining to 0. Now it would be a disaster if the child cgroup
> tries to access its parent.
>
> Make sure this won't happen.
>
> Signed-off-by: Li Zefan <lizefan@huawei.com>
OK, after clarification from Tejun, that this is helpful for other
controllers as well I think it is better than a memcg specific handling.
Reviewed-by: Michal Hocko <mhocko@suse.cz>
> ---
> kernel/cgroup.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index fa54b92..78204bc 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -888,6 +888,13 @@ static void cgroup_free_fn(struct work_struct *work)
> mutex_unlock(&cgroup_mutex);
>
> /*
> + * We get a ref to the parent's dentry, and put the ref when
> + * this cgroup is being freed, so it's guaranteed that the
> + * parent won't be destroyed before its children.
> + */
> + dput(cgrp->parent->dentry);
> +
> + /*
> * Drop the active superblock reference that we took when we
> * created the cgroup
> */
> @@ -4171,6 +4178,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
> for_each_subsys(root, ss)
> dget(dentry);
>
> + /* hold a ref to the parent's dentry */
> + dget(parent->dentry);
> +
> /* creation succeeded, notify subsystems */
> for_each_subsys(root, ss) {
> err = online_css(ss, cgrp);
> --
> 1.8.0.2
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children
2013-04-03 9:13 ` [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children Li Zefan
[not found] ` <515BF2A4.1070703-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-04 15:31 ` Michal Hocko
@ 2013-04-05 5:58 ` Kamezawa Hiroyuki
2 siblings, 0 replies; 48+ messages in thread
From: Kamezawa Hiroyuki @ 2013-04-05 5:58 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
Johannes Weiner
(2013/04/03 18:13), Li Zefan wrote:
> Suppose we rmdir a cgroup and there're still css refs, this cgroup won't
> be freed. Then we rmdir the parent cgroup, and the parent is freed due
> to css ref draining to 0. Now it would be a disaster if the child cgroup
> tries to access its parent.
>
> Make sure this won't happen.
>
> Signed-off-by: Li Zefan <lizefan@huawei.com>
> ---
> kernel/cgroup.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index fa54b92..78204bc 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -888,6 +888,13 @@ static void cgroup_free_fn(struct work_struct *work)
> mutex_unlock(&cgroup_mutex);
>
> /*
> + * We get a ref to the parent's dentry, and put the ref when
> + * this cgroup is being freed, so it's guaranteed that the
> + * parent won't be destroyed before its children.
> + */
> + dput(cgrp->parent->dentry);
> +
> + /*
> * Drop the active superblock reference that we took when we
> * created the cgroup
> */
> @@ -4171,6 +4178,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
> for_each_subsys(root, ss)
> dget(dentry);
>
> + /* hold a ref to the parent's dentry */
> + dget(parent->dentry);
> +
> /* creation succeeded, notify subsystems */
> for_each_subsys(root, ss) {
> err = online_css(ss, cgrp);
>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread
* [RFC][PATCH 6/7] memcg: don't need to get a reference to the parent
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
` (4 preceding siblings ...)
2013-04-03 9:13 ` [RFC][PATCH 5/7] cgroup: make sure parent won't be destroyed before its children Li Zefan
@ 2013-04-03 9:13 ` Li Zefan
[not found] ` <515BF2B1.9060909-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-03 9:14 ` [RFC][PATCH 7/7] memcg: kill memcg refcnt Li Zefan
` (2 subsequent siblings)
8 siblings, 1 reply; 48+ messages in thread
From: Li Zefan @ 2013-04-03 9:13 UTC (permalink / raw)
To: linux-mm
Cc: LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
The cgroup core guarantees it's always safe to access the parent.
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
mm/memcontrol.c | 14 +-------------
1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ad576e8..45129cd 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6124,12 +6124,8 @@ static void mem_cgroup_get(struct mem_cgroup *memcg)
static void __mem_cgroup_put(struct mem_cgroup *memcg, int count)
{
- if (atomic_sub_and_test(count, &memcg->refcnt)) {
- struct mem_cgroup *parent = parent_mem_cgroup(memcg);
+ if (atomic_sub_and_test(count, &memcg->refcnt))
call_rcu(&memcg->rcu_freeing, free_rcu);
- if (parent)
- mem_cgroup_put(parent);
- }
}
static void mem_cgroup_put(struct mem_cgroup *memcg)
@@ -6229,14 +6225,6 @@ mem_cgroup_css_online(struct cgroup *cont)
res_counter_init(&memcg->res, &parent->res);
res_counter_init(&memcg->memsw, &parent->memsw);
res_counter_init(&memcg->kmem, &parent->kmem);
-
- /*
- * We increment refcnt of the parent to ensure that we can
- * safely access it on res_counter_charge/uncharge.
- * This refcnt will be decremented when freeing this
- * mem_cgroup(see mem_cgroup_put).
- */
- mem_cgroup_get(parent);
} else {
res_counter_init(&memcg->res, NULL);
res_counter_init(&memcg->memsw, NULL);
--
1.8.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 48+ messages in thread* [RFC][PATCH 7/7] memcg: kill memcg refcnt
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
` (5 preceding siblings ...)
2013-04-03 9:13 ` [RFC][PATCH 6/7] memcg: don't need to get a reference to the parent Li Zefan
@ 2013-04-03 9:14 ` Li Zefan
[not found] ` <515BF2E3.4000605-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-03 9:19 ` [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Glauber Costa
[not found] ` <515BF233.6070308-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
8 siblings, 1 reply; 48+ messages in thread
From: Li Zefan @ 2013-04-03 9:14 UTC (permalink / raw)
To: linux-mm
Cc: LKML, Cgroups, Tejun Heo, Glauber Costa, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
Now memcg has the same life cycle as the corresponding cgroup.
Kill the useless refcnt.
Signed-off-by: Li Zefan <lizefan@huawei.com>
---
mm/memcontrol.c | 24 +-----------------------
1 file changed, 1 insertion(+), 23 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 45129cd..9714a16 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -297,8 +297,6 @@ struct mem_cgroup {
bool oom_lock;
atomic_t under_oom;
- atomic_t refcnt;
-
int swappiness;
/* OOM-Killer disable */
int oom_kill_disable;
@@ -501,9 +499,6 @@ enum res_type {
*/
static DEFINE_MUTEX(memcg_create_mutex);
-static void mem_cgroup_get(struct mem_cgroup *memcg);
-static void mem_cgroup_put(struct mem_cgroup *memcg);
-
static inline
struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *s)
{
@@ -6117,22 +6112,6 @@ static void free_rcu(struct rcu_head *rcu_head)
schedule_work(&memcg->work_freeing);
}
-static void mem_cgroup_get(struct mem_cgroup *memcg)
-{
- atomic_inc(&memcg->refcnt);
-}
-
-static void __mem_cgroup_put(struct mem_cgroup *memcg, int count)
-{
- if (atomic_sub_and_test(count, &memcg->refcnt))
- call_rcu(&memcg->rcu_freeing, free_rcu);
-}
-
-static void mem_cgroup_put(struct mem_cgroup *memcg)
-{
- __mem_cgroup_put(memcg, 1);
-}
-
/*
* Returns the parent mem_cgroup in memcgroup hierarchy with hierarchy enabled.
*/
@@ -6192,7 +6171,6 @@ mem_cgroup_css_alloc(struct cgroup *cont)
memcg->last_scanned_node = MAX_NUMNODES;
INIT_LIST_HEAD(&memcg->oom_notify);
- atomic_set(&memcg->refcnt, 1);
memcg->move_charge_at_immigrate = 0;
mutex_init(&memcg->thresholds_lock);
spin_lock_init(&memcg->move_lock);
@@ -6279,7 +6257,7 @@ static void mem_cgroup_css_free(struct cgroup *cont)
mem_cgroup_sockets_destroy(memcg);
- mem_cgroup_put(memcg);
+ call_rcu(&memcg->rcu_freeing, free_rcu);
}
#ifdef CONFIG_MMU
--
1.8.0.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup
2013-04-03 9:11 [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup Li Zefan
` (6 preceding siblings ...)
2013-04-03 9:14 ` [RFC][PATCH 7/7] memcg: kill memcg refcnt Li Zefan
@ 2013-04-03 9:19 ` Glauber Costa
[not found] ` <515BF233.6070308-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
8 siblings, 0 replies; 48+ messages in thread
From: Glauber Costa @ 2013-04-03 9:19 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Michal Hocko,
KAMEZAWA Hiroyuki, Johannes Weiner
On 04/03/2013 01:11 PM, Li Zefan wrote:
> The historical reason that memcg didn't use css_get in some cases, is that
> cgroup couldn't be removed if there're still css refs. The situation has
> changed so that rmdir a cgroup will succeed regardless css refs, but won't
> be freed until css refs goes down to 0.
>
> This is an early post, and it's NOT TESTED. I just want to see if the changes
> are fine in general.
Well, from my PoV, this will in general greatly simplify memcg lifecycle
management.
Indeed, I can remember no other reason for those complications other
than the problem with removing directories. If cgroup no longer have
this limitation, I would much rather see your approach in.
I will look into the patches individually soon
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread[parent not found: <515BF233.6070308-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup
[not found] ` <515BF233.6070308-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2013-04-03 21:43 ` Tejun Heo
2013-04-04 12:00 ` Michal Hocko
2013-04-07 8:44 ` Li Zefan
2 siblings, 0 replies; 48+ messages in thread
From: Tejun Heo @ 2013-04-03 21:43 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups, Glauber Costa,
Michal Hocko, KAMEZAWA Hiroyuki, Johannes Weiner
On Wed, Apr 03, 2013 at 05:11:15PM +0800, Li Zefan wrote:
> (I'll be off from my office soon, and I won't be responsive in the following
> 3 days.)
>
> I'm working on converting memcg to use cgroup->id, and then we can kill css_id.
>
> Now memcg has its own refcnt, so when a cgroup is destroyed, the memcg can
> still be alive. This patchset converts memcg to always use css_get/put, so
> memcg will have the same life cycle as its corresponding cgroup, and then
> it's always safe for memcg to use cgroup->id.
>
> The historical reason that memcg didn't use css_get in some cases, is that
> cgroup couldn't be removed if there're still css refs. The situation has
> changed so that rmdir a cgroup will succeed regardless css refs, but won't
> be freed until css refs goes down to 0.
Hallelujah. This one is egregious if you take a step back and what
happened as a whole. cgroup core had this weird object life-time
management rule where it forces draining of all css refs on cgroup
destruction, which is very unusual and puts unnecessary restrictions
on css object usages in controllers.
As the restriction wasn't too nice, memcg goes ahead and creates its
own object which basically is the same as css but has a different
life-time rule and does refcnting for both objects. Bah....
So, yeah, let's please get rid of this abomination. It shouldn't have
existed from the beginning.
Thanks a lot for doing this!
--
tejun
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup
[not found] ` <515BF233.6070308-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-03 21:43 ` Tejun Heo
@ 2013-04-04 12:00 ` Michal Hocko
2013-04-07 6:00 ` Li Zefan
2013-04-07 8:44 ` Li Zefan
2 siblings, 1 reply; 48+ messages in thread
From: Michal Hocko @ 2013-04-04 12:00 UTC (permalink / raw)
To: Li Zefan
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups, Tejun Heo,
Glauber Costa, KAMEZAWA Hiroyuki, Johannes Weiner
On Wed 03-04-13 17:11:15, Li Zefan wrote:
> (I'll be off from my office soon, and I won't be responsive in the following
> 3 days.)
>
> I'm working on converting memcg to use cgroup->id, and then we can kill css_id.
>
> Now memcg has its own refcnt, so when a cgroup is destroyed, the memcg can
> still be alive. This patchset converts memcg to always use css_get/put, so
> memcg will have the same life cycle as its corresponding cgroup, and then
> it's always safe for memcg to use cgroup->id.
>
> The historical reason that memcg didn't use css_get in some cases, is that
> cgroup couldn't be removed if there're still css refs. The situation has
> changed so that rmdir a cgroup will succeed regardless css refs, but won't
> be freed until css refs goes down to 0.
>
> This is an early post, and it's NOT TESTED. I just want to see if the changes
> are fine in general.
yes, I like the approach and it looks correct as well (some minor things
mentioned in the patches). Thanks a lot Li! This will make our lifes much
easier. The separate ref counting was PITA especially after
introduction of kmem accounting which made its usage even more trickier.
> btw, after this patchset I think we don't need to free memcg via RCU, because
> cgroup is already freed in RCU callback.
But this depends on changes waiting in for-3.10 branch, right?
Anyway, I think we should be safe with the workqueue based releasing as
well once mem_cgroup_{get,put} are gone, right?
> Note this patchset is based on a few memcg fixes I sent (but hasn't been
> accepted)
>
> --
> kernel/cgroup.c | 10 ++++++++
> mm/memcontrol.c | 129 ++++++++++++++++++++++++++++++++++++++-------------------------------------------------------
> 2 files changed, 62 insertions(+), 77 deletions(-)
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup
2013-04-04 12:00 ` Michal Hocko
@ 2013-04-07 6:00 ` Li Zefan
[not found] ` <51610B78.7080001-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 48+ messages in thread
From: Li Zefan @ 2013-04-07 6:00 UTC (permalink / raw)
To: Michal Hocko
Cc: linux-mm, LKML, Cgroups, Tejun Heo, Glauber Costa,
KAMEZAWA Hiroyuki, Johannes Weiner
On 2013/4/4 20:00, Michal Hocko wrote:
> On Wed 03-04-13 17:11:15, Li Zefan wrote:
>> (I'll be off from my office soon, and I won't be responsive in the following
>> 3 days.)
>>
>> I'm working on converting memcg to use cgroup->id, and then we can kill css_id.
>>
>> Now memcg has its own refcnt, so when a cgroup is destroyed, the memcg can
>> still be alive. This patchset converts memcg to always use css_get/put, so
>> memcg will have the same life cycle as its corresponding cgroup, and then
>> it's always safe for memcg to use cgroup->id.
>>
>> The historical reason that memcg didn't use css_get in some cases, is that
>> cgroup couldn't be removed if there're still css refs. The situation has
>> changed so that rmdir a cgroup will succeed regardless css refs, but won't
>> be freed until css refs goes down to 0.
>>
>> This is an early post, and it's NOT TESTED. I just want to see if the changes
>> are fine in general.
>
> yes, I like the approach and it looks correct as well (some minor things
> mentioned in the patches). Thanks a lot Li! This will make our lifes much
> easier. The separate ref counting was PITA especially after
> introduction of kmem accounting which made its usage even more trickier.
>
>> btw, after this patchset I think we don't need to free memcg via RCU, because
>> cgroup is already freed in RCU callback.
>
> But this depends on changes waiting in for-3.10 branch, right?
What changes? memcg changes or cgroup core changes? I don't think this depends
on anything in cgroup 3.10 branch.
> Anyway, I think we should be safe with the workqueue based releasing as
> well once mem_cgroup_{get,put} are gone, right?
>
cgroup calls mem_cgroup_css_free() in a work function, so seems memcg doesn't
need to use RCU or workqueue in mem_cgroup_css_free().
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 48+ messages in thread
* Re: [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup
[not found] ` <515BF233.6070308-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2013-04-03 21:43 ` Tejun Heo
2013-04-04 12:00 ` Michal Hocko
@ 2013-04-07 8:44 ` Li Zefan
2013-04-07 19:51 ` Michal Hocko
[not found] ` <516131D7.8030004-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2 siblings, 2 replies; 48+ messages in thread
From: Li Zefan @ 2013-04-07 8:44 UTC (permalink / raw)
To: Glauber Costa, Michal Hocko
Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups, Tejun Heo,
KAMEZAWA Hiroyuki, Johannes Weiner
Hi,
I'm rebasing this patchset against latest linux-next, and it conflicts with
"[PATCH v2] memcg: debugging facility to access dangling memcgs." slightly.
That is a debugging patch and will never be pushed into mainline, so should I
still base this patchset on that debugging patch?
Also that patch needs update (and can be simplified) after this patchset:
- move memcg_dangling_add() to mem_cgroup_css_offline()
- remove memcg->memcg_name, and use cgroup_path() in mem_cgroup_dangling_read()?
On 2013/4/3 17:11, Li Zefan wrote:
> (I'll be off from my office soon, and I won't be responsive in the following
> 3 days.)
>
> I'm working on converting memcg to use cgroup->id, and then we can kill css_id.
>
> Now memcg has its own refcnt, so when a cgroup is destroyed, the memcg can
> still be alive. This patchset converts memcg to always use css_get/put, so
> memcg will have the same life cycle as its corresponding cgroup, and then
> it's always safe for memcg to use cgroup->id.
>
> The historical reason that memcg didn't use css_get in some cases, is that
> cgroup couldn't be removed if there're still css refs. The situation has
> changed so that rmdir a cgroup will succeed regardless css refs, but won't
> be freed until css refs goes down to 0.
>
> This is an early post, and it's NOT TESTED. I just want to see if the changes
> are fine in general.
>
> btw, after this patchset I think we don't need to free memcg via RCU, because
> cgroup is already freed in RCU callback.
>
> Note this patchset is based on a few memcg fixes I sent (but hasn't been
> accepted)
>
> --
> kernel/cgroup.c | 10 ++++++++
> mm/memcontrol.c | 129 ++++++++++++++++++++++++++++++++++++++-------------------------------------------------------
> 2 files changed, 62 insertions(+), 77 deletions(-)
>
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup
2013-04-07 8:44 ` Li Zefan
@ 2013-04-07 19:51 ` Michal Hocko
[not found] ` <516131D7.8030004-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
1 sibling, 0 replies; 48+ messages in thread
From: Michal Hocko @ 2013-04-07 19:51 UTC (permalink / raw)
To: Li Zefan
Cc: Glauber Costa, linux-mm, LKML, Cgroups, Tejun Heo,
KAMEZAWA Hiroyuki, Johannes Weiner
On Sun 07-04-13 16:44:07, Li Zefan wrote:
> Hi,
>
> I'm rebasing this patchset against latest linux-next, and it conflicts with
> "[PATCH v2] memcg: debugging facility to access dangling memcgs." slightly.
>
> That is a debugging patch and will never be pushed into mainline, so should I
> still base this patchset on that debugging patch?
Could you split CONFIG_MEMCG_DEBUG_ASYNC_DESTROY changes into a separate
patch so that Andrew could put it on top of the mentioned patch?
> Also that patch needs update (and can be simplified) after this patchset:
> - move memcg_dangling_add() to mem_cgroup_css_offline()
> - remove memcg->memcg_name, and use cgroup_path() in mem_cgroup_dangling_read()?
Every improvement is welcome.
Thanks
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 48+ messages in thread[parent not found: <516131D7.8030004-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>]
* Re: [RFC][PATCH 0/7] memcg: make memcg's life cycle the same as cgroup
[not found] ` <516131D7.8030004-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2013-04-08 7:18 ` Glauber Costa
0 siblings, 0 replies; 48+ messages in thread
From: Glauber Costa @ 2013-04-08 7:18 UTC (permalink / raw)
To: Li Zefan
Cc: Michal Hocko, linux-mm-Bw31MaZKKs3YtjvyW6yDsg, LKML, Cgroups,
Tejun Heo, KAMEZAWA Hiroyuki, Johannes Weiner
On 04/07/2013 12:44 PM, Li Zefan wrote:
> Hi,
>
> I'm rebasing this patchset against latest linux-next, and it conflicts with
> "[PATCH v2] memcg: debugging facility to access dangling memcgs." slightly.
>
> That is a debugging patch and will never be pushed into mainline, so should I
> still base this patchset on that debugging patch?
>
It will conflict as well with my shrinking patches: I will still keep
the memcgs in the dangling list, but that will have nothing to do with
debugging. So I will split that patch in a list management part, which
will be used, and a debugging part (with the file + the debugging
information).
I will be happy to rebase it ontop of your series.
> Also that patch needs update (and can be simplified) after this patchset:
> - move memcg_dangling_add() to mem_cgroup_css_offline()
> - remove memcg->memcg_name, and use cgroup_path() in mem_cgroup_dangling_read()?
>
Don't worry about it. If this is just this one patch conflicting, I
would avise Andrew to remove it, and I will provide another (maybe two,
already splitted up) version.
^ permalink raw reply [flat|nested] 48+ messages in thread