OpenVZ Forum - RDF feed
type: channel
items: [PATCH v5 0/2] fix static_key disabling problem in memcg
items: [PATCH v5 1/2] Always free struct memcg through schedule_work()
items: [PATCH v5 2/2] decrement static keys on real destroy time
items: Re: [PATCH v5 1/2] Always free struct memcg through schedule_work()
items: Re: [PATCH v5 2/2] decrement static keys on real destroy time

[PATCH v5 0/2] fix static_key disabling problem in memcg
type: item
description: Hi, Tejun, Kame, This series is composed of the two patches of the last fix, with no changes (only exception is the removal of x = false assignments that Tejun requested, that is done now). Note also that patch 1 of this series was reused by me in the slab accounting patches for memcg. The first patch, that adds a mutex to memcg is dropped. I didn't posted it before so I could wait for Kame to get back from his vacations and properly review it. Kame: Steven Rostedt pointed out that our analysis of the static branch updates were wrong, so the mutex is really not needed. The key to understand that, is that atomic_inc_not_zero will only return right away if the value is not yet zero - as the name implies - but the update in the atomic variable only happens after the code is patched. Therefore, if two callers enters with a key value of zero, both will be held at the jump_label_lock() call, effectively guaranteeing the behavior we need. Glauber Costa (2): Always free struct memcg through schedule_work() decrement static keys on real destroy time include/net/sock.h | 9 ++++++++ mm/memcontrol.c | 50 +++++++++++++++++++++++++++++++++----------- net/ipv4/tcp_memcontrol.c | 32 ++++++++++++++++++++++------ 3 files changed, 71 insertions(+), 20 deletions(-) -- 1.7.7.6
creator: Glauber Costa
date: 2012-05-11T20:11:15-00:00

[PATCH v5 1/2] Always free struct memcg through schedule_work()
type: item
description: Right now we free struct memcg with kfree right after a rcu grace period, but defer it if we need to use vfree() to get rid of that memory area. We do that by need, because we need vfree to be called in a process context. This patch unifies this behavior, by ensuring that even kfree will happen in a separate thread. The goal is to have a stable place to call the upcoming jump label destruction function outside the realm of the complicated and quite far-reaching cgroup lock (that can't be held when calling neither the cpu_hotplug.lock nor the jump_label_mutex) Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Tejun Heo <tj@kernel.org> CC: Li Zefan <lizefan@huawei.com> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Michal Hocko <mhocko@suse.cz> --- mm/memcontrol.c | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 932a734..0b4b4c8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -245,8 +245,8 @@ struct mem_cgroup { */ struct rcu_head rcu_freeing; /* - * But when using vfree(), that cannot be done at - * interrupt time, so we must then queue the work. + * We also need some space for a worker in deferred freeing. + * By the time we call it, rcu_freeing is not longer in use. */ struct work_struct work_freeing; }; @@ -4826,23 +4826,28 @@ out_free: } /* - * Helpers for freeing a vzalloc()ed mem_cgroup by RCU, + * Helpers for freeing a kmalloc()ed/vzalloc()ed mem_cgroup by RCU, * but in process context. The work_freeing structure is overlaid * on the rcu_freeing structure, which itself is overlaid on memsw. */ -static void vfree_work(struct work_struct *work) +static void free_work(struct work_struct *work) { struct mem_cgroup *memcg; + int size = sizeof(struct mem_cgroup); memcg = container_of(work, struct mem_cgroup, work_freeing); - vfree(memcg); + if (size < PAGE_SIZE) + kfree(memcg); + else + vfree(memcg); } -static void vf…
creator: Glauber Costa
date: 2012-05-11T20:11:16-00:00

[PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: We call the destroy function when a cgroup starts to be removed, such as by a rmdir event. However, because of our reference counters, some objects are still inflight. Right now, we are decrementing the static_keys at destroy() time, meaning that if we get rid of the last static_key reference, some objects will still have charges, but the code to properly uncharge them won't be run. This becomes a problem specially if it is ever enabled again, because now new charges will be added to the staled charges making keeping it pretty much impossible. We just need to be careful with the static branch activation: since there is no particular preferred order of their activation, we need to make sure that we only start using it after all call sites are active. This is achieved by having a per-memcg flag that is only updated after static_key_slow_inc() returns. At this time, we are sure all sites are active. This is made per-memcg, not global, for a reason: it also has the effect of making socket accounting more consistent. The first memcg to be limited will trigger static_key() activation, therefore, accounting. But all the others will then be accounted no matter what. After this patch, only limited memcgs will have its sockets accounted. [v2: changed a tcp limited flag for a generic proto limited flag ] [v3: update the current active flag only after the static_key update ] [v4: disarm_static_keys() inside free_work ] [v5: got rid of tcp_limit_mutex, now in the static_key interface ] Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Tejun Heo <tj@kernel.org> CC: Li Zefan <lizefan@huawei.com> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Michal Hocko <mhocko@suse.cz> --- include/net/sock.h | 9 +++++++++ mm/memcontrol.c | 26 ++++++++++++++++++++++++-- net/ipv4/tcp_memcontrol.c | 32 +++++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h ind…
creator: Glauber Costa
date: 2012-05-11T20:11:17-00:00

Re: [PATCH v5 1/2] Always free struct memcg through schedule_work()
type: item
description: (2012/05/12 5:11), Glauber Costa wrote: > Right now we free struct memcg with kfree right after a > rcu grace period, but defer it if we need to use vfree() to get > rid of that memory area. We do that by need, because we need vfree > to be called in a process context. > > This patch unifies this behavior, by ensuring that even kfree will > happen in a separate thread. The goal is to have a stable place to > call the upcoming jump label destruction function outside the realm > of the complicated and quite far-reaching cgroup lock (that can't be > held when calling neither the cpu_hotplug.lock nor the jump_label_mutex) > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Tejun Heo <tj@kernel.org> > CC: Li Zefan <lizefan@huawei.com> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > CC: Johannes Weiner <hannes@cmpxchg.org> > CC: Michal Hocko <mhocko@suse.cz> I think we'll need to revisit this, again. for now, Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
creator: KAMEZAWA Hiroyuki
date: 2012-05-14T00:56:20-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: (2012/05/12 5:11), Glauber Costa wrote: > We call the destroy function when a cgroup starts to be removed, > such as by a rmdir event. > > However, because of our reference counters, some objects are still > inflight. Right now, we are decrementing the static_keys at destroy() > time, meaning that if we get rid of the last static_key reference, > some objects will still have charges, but the code to properly > uncharge them won't be run. > > This becomes a problem specially if it is ever enabled again, because > now new charges will be added to the staled charges making keeping > it pretty much impossible. > > We just need to be careful with the static branch activation: > since there is no particular preferred order of their activation, > we need to make sure that we only start using it after all > call sites are active. This is achieved by having a per-memcg > flag that is only updated after static_key_slow_inc() returns. > At this time, we are sure all sites are active. > > This is made per-memcg, not global, for a reason: > it also has the effect of making socket accounting more > consistent. The first memcg to be limited will trigger static_key() > activation, therefore, accounting. But all the others will then be > accounted no matter what. After this patch, only limited memcgs > will have its sockets accounted. > > [v2: changed a tcp limited flag for a generic proto limited flag ] > [v3: update the current active flag only after the static_key update ] > [v4: disarm_static_keys() inside free_work ] > [v5: got rid of tcp_limit_mutex, now in the static_key interface ] > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Tejun Heo <tj@kernel.org> > CC: Li Zefan <lizefan@huawei.com> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > CC: Johannes Weiner <hannes@cmpxchg.org> > CC: Michal Hocko <mhocko@suse.cz> Thank you for your patient works. Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> BTW, what is the relationship between 1/2 an…
creator: KAMEZAWA Hiroyuki
date: 2012-05-14T00:59:04-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: > +static void disarm_static_keys(struct mem_cgroup *memcg) > +{ > +#ifdef CONFIG_INET > + if (memcg->tcp_mem.cg_proto.activated) > + static_key_slow_dec(&memcg_socket_limit_enabled); > +#endif > +} Move this inside the ifdef/endif below ? Otherwise I think you'll get compile error if !CONFIG_INET... > + > #ifdef CONFIG_INET > struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) > { > @@ -452,6 +462,11 @@ struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) > } > EXPORT_SYMBOL(tcp_proto_cgroup); > #endif /* CONFIG_INET */ > +#else > +static inline void disarm_static_keys(struct mem_cgroup *memcg) > +{ > +} > + > #endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */
creator: Li Zefan
date: 2012-05-14T01:38:36-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On Fri, May 11, 2012 at 05:11:17PM -0300, Glauber Costa wrote: > We call the destroy function when a cgroup starts to be removed, > such as by a rmdir event. > > However, because of our reference counters, some objects are still > inflight. Right now, we are decrementing the static_keys at destroy() > time, meaning that if we get rid of the last static_key reference, > some objects will still have charges, but the code to properly > uncharge them won't be run. > > This becomes a problem specially if it is ever enabled again, because > now new charges will be added to the staled charges making keeping > it pretty much impossible. > > We just need to be careful with the static branch activation: > since there is no particular preferred order of their activation, > we need to make sure that we only start using it after all > call sites are active. This is achieved by having a per-memcg > flag that is only updated after static_key_slow_inc() returns. > At this time, we are sure all sites are active. > > This is made per-memcg, not global, for a reason: > it also has the effect of making socket accounting more > consistent. The first memcg to be limited will trigger static_key() > activation, therefore, accounting. But all the others will then be > accounted no matter what. After this patch, only limited memcgs > will have its sockets accounted. > > [v2: changed a tcp limited flag for a generic proto limited flag ] > [v3: update the current active flag only after the static_key update ] > [v4: disarm_static_keys() inside free_work ] > [v5: got rid of tcp_limit_mutex, now in the static_key interface ] > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Tejun Heo <tj@kernel.org> > CC: Li Zefan <lizefan@huawei.com> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > CC: Johannes Weiner <hannes@cmpxchg.org> > CC: Michal Hocko <mhocko@suse.cz> Generally looks sane to me. Please feel free to addmy Reviewed-by. > + if (val == RESOURCE_MAX) > + cg_proto->active…
creator: Tejun Heo
date: 2012-05-14T18:12:50-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/14/2012 04:59 AM, KAMEZAWA Hiroyuki wrote: > (2012/05/12 5:11), Glauber Costa wrote: > >> We call the destroy function when a cgroup starts to be removed, >> such as by a rmdir event. >> >> However, because of our reference counters, some objects are still >> inflight. Right now, we are decrementing the static_keys at destroy() >> time, meaning that if we get rid of the last static_key reference, >> some objects will still have charges, but the code to properly >> uncharge them won't be run. >> >> This becomes a problem specially if it is ever enabled again, because >> now new charges will be added to the staled charges making keeping >> it pretty much impossible. >> >> We just need to be careful with the static branch activation: >> since there is no particular preferred order of their activation, >> we need to make sure that we only start using it after all >> call sites are active. This is achieved by having a per-memcg >> flag that is only updated after static_key_slow_inc() returns. >> At this time, we are sure all sites are active. >> >> This is made per-memcg, not global, for a reason: >> it also has the effect of making socket accounting more >> consistent. The first memcg to be limited will trigger static_key() >> activation, therefore, accounting. But all the others will then be >> accounted no matter what. After this patch, only limited memcgs >> will have its sockets accounted. >> >> [v2: changed a tcp limited flag for a generic proto limited flag ] >> [v3: update the current active flag only after the static_key update ] >> [v4: disarm_static_keys() inside free_work ] >> [v5: got rid of tcp_limit_mutex, now in the static_key interface ] >> >> Signed-off-by: Glauber Costa<glommer@parallels.com> >> CC: Tejun Heo<tj@kernel.org> >> CC: Li Zefan<lizefan@huawei.com> >> CC: Kamezawa Hiroyuki<kamezawa.hiroyu@jp.fujitsu.com> >> CC: Johannes Weiner<hannes@cmpxchg.org> >> CC: Michal Hocko<mhocko@suse.cz> > > > Thank you for your patient works. > > Acked-by: …
creator: Glauber Costa
date: 2012-05-16T06:03:08-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/14/2012 05:38 AM, Li Zefan wrote: >> +static void disarm_static_keys(struct mem_cgroup *memcg) > >> +{ >> +#ifdef CONFIG_INET >> + if (memcg->tcp_mem.cg_proto.activated) >> + static_key_slow_dec(&memcg_socket_limit_enabled); >> +#endif >> +} > > > Move this inside the ifdef/endif below ? > > Otherwise I think you'll get compile error if !CONFIG_INET... I don't fully get it. We are supposed to provide a version of it for CONFIG_CGROUP_MEM_RES_CTLR_KMEM and an empty version for !CONFIG_CGROUP_MEM_RES_CTLR_KMEM Inside the first, we take an action for CONFIG_INET, and no action for !CONFIG_INET. Bear in mind that the slab patches will add another test to that place, and that's why I am doing it this way from the beginning. Well, that said, I not only can be wrong, I very frequently am. But I just compiled this one with and without CONFIG_INET, and it seems to be going alright. >> + >> #ifdef CONFIG_INET >> struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) >> { >> @@ -452,6 +462,11 @@ struct cg_proto *tcp_proto_cgroup(struct mem_cgroup *memcg) >> } >> EXPORT_SYMBOL(tcp_proto_cgroup); >> #endif /* CONFIG_INET */ >> +#else >> +static inline void disarm_static_keys(struct mem_cgroup *memcg) >> +{ >> +} >> + >> #endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */ > > -- > To unsubscribe from this list: send the line "unsubscribe cgroups" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html
creator: Glauber Costa
date: 2012-05-16T07:03:47-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/16/2012 10:03 AM, Glauber Costa wrote: >> BTW, what is the relationship between 1/2 and 2/2 ? > Can't do jump label patching inside an interrupt handler. They need to > happen when we free the structure, and I was about to add a worker > myself when I found out we already have one: just we don't always use it. > > Before we merge it, let me just make sure the issue with config Li > pointed out don't exist. I did test it, but since I've reposted this > many times with multiple tiny changes - the type that will usually get > us killed, I'd be more comfortable with an extra round of testing if > someone spotted a possibility. > > Who is merging this fix, btw ? > I find it to be entirely memcg related, even though it touches a file in > net (but a file with only memcg code in it) > For the record, I compiled test it many times, and the problem that Li wondered about seems not to exist.
creator: Glauber Costa
date: 2012-05-16T07:04:43-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: (2012/05/16 16:04), Glauber Costa wrote: > On 05/16/2012 10:03 AM, Glauber Costa wrote: >>> BTW, what is the relationship between 1/2 and 2/2 ? >> Can't do jump label patching inside an interrupt handler. They need to >> happen when we free the structure, and I was about to add a worker >> myself when I found out we already have one: just we don't always use it. >> >> Before we merge it, let me just make sure the issue with config Li >> pointed out don't exist. I did test it, but since I've reposted this >> many times with multiple tiny changes - the type that will usually get >> us killed, I'd be more comfortable with an extra round of testing if >> someone spotted a possibility. >> >> Who is merging this fix, btw ? >> I find it to be entirely memcg related, even though it touches a file in >> net (but a file with only memcg code in it) >> > > For the record, I compiled test it many times, and the problem that Li > wondered about seems not to exist. > Ah...Hmm.....I guess dependency problem will be found in -mm if any rather than netdev... David, can this bug-fix patch goes via -mm tree ? Or will you pick up ? CC'ed David Miller and Andrew Morton. Thanks, -Kame
creator: KAMEZAWA Hiroyuki
date: 2012-05-16T08:28:29-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/16/2012 12:28 PM, KAMEZAWA Hiroyuki wrote: >> For the record, I compiled test it many times, and the problem that Li >> > wondered about seems not to exist. >> > > Ah...Hmm.....I guess dependency problem will be found in -mm if any rather than > netdev... Yes. As I said, this only touches stuff in core memcg and the memcg specific file. Any conflicts should come from other memcg fixes that may have got into the tree... > David, can this bug-fix patch goes via -mm tree ? Or will you pick up ? > > CC'ed David Miller and Andrew Morton. > > Thanks, > -Kame > >
creator: Glauber Costa
date: 2012-05-16T08:30:25-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/16/2012 12:28 PM, KAMEZAWA Hiroyuki wrote: > (2012/05/16 16:04), Glauber Costa wrote: > >> On 05/16/2012 10:03 AM, Glauber Costa wrote: >>>> BTW, what is the relationship between 1/2 and 2/2 ? >>> Can't do jump label patching inside an interrupt handler. They need to >>> happen when we free the structure, and I was about to add a worker >>> myself when I found out we already have one: just we don't always use it. >>> >>> Before we merge it, let me just make sure the issue with config Li >>> pointed out don't exist. I did test it, but since I've reposted this >>> many times with multiple tiny changes - the type that will usually get >>> us killed, I'd be more comfortable with an extra round of testing if >>> someone spotted a possibility. >>> >>> Who is merging this fix, btw ? >>> I find it to be entirely memcg related, even though it touches a file in >>> net (but a file with only memcg code in it) >>> >> >> For the record, I compiled test it many times, and the problem that Li >> wondered about seems not to exist. >> > > Ah...Hmm.....I guess dependency problem will be found in -mm if any rather than > netdev... > > David, can this bug-fix patch goes via -mm tree ? Or will you pick up ? > Another thing: Patch 2 in this series is of course dependent on patch 1 - which lives 100 % in memcg core. Without that, lockdep will scream while disabling the static key.
creator: Glauber Costa
date: 2012-05-16T08:37:32-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On Wed, 16 May 2012 11:03:47 +0400 Glauber Costa <glommer@parallels.com> wrote: > On 05/14/2012 05:38 AM, Li Zefan wrote: > >> +static void disarm_static_keys(struct mem_cgroup *memcg) > > > >> +{ > >> +#ifdef CONFIG_INET > >> + if (memcg->tcp_mem.cg_proto.activated) > >> + static_key_slow_dec(&memcg_socket_limit_enabled); > >> +#endif > >> +} > > > > > > Move this inside the ifdef/endif below ? > > > > Otherwise I think you'll get compile error if !CONFIG_INET... > > I don't fully get it. > > We are supposed to provide a version of it for > CONFIG_CGROUP_MEM_RES_CTLR_KMEM and an empty version for > !CONFIG_CGROUP_MEM_RES_CTLR_KMEM > > Inside the first, we take an action for CONFIG_INET, and no action for > !CONFIG_INET. > > Bear in mind that the slab patches will add another test to that place, > and that's why I am doing it this way from the beginning. > > Well, that said, I not only can be wrong, I very frequently am. > > But I just compiled this one with and without CONFIG_INET, and it seems > to be going alright. > Yes, the ifdeffings in that area are rather nasty. I wonder if it would be simpler to do away with the ifdef nesting. At the top-level, just do #if defined(CONFIG_CGROUP_MEM_RES_CTLR_KMEM) && defined(CONFIG_INET) static void disarm_static_keys(struct mem_cgroup *memcg) { if (memcg->tcp_mem.cg_proto.activated) static_key_slow_dec(&memcg_socket_limit_enabled); } #else static inline void disarm_static_keys(struct mem_cgroup *memcg) { } #endif The tcp_proto_cgroup() definition could go inside that ifdef as well.
creator: akpm
date: 2012-05-16T20:57:55-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On Fri, 11 May 2012 17:11:17 -0300 Glauber Costa <glommer@parallels.com> wrote: > We call the destroy function when a cgroup starts to be removed, > such as by a rmdir event. > > However, because of our reference counters, some objects are still > inflight. Right now, we are decrementing the static_keys at destroy() > time, meaning that if we get rid of the last static_key reference, > some objects will still have charges, but the code to properly > uncharge them won't be run. > > This becomes a problem specially if it is ever enabled again, because > now new charges will be added to the staled charges making keeping > it pretty much impossible. > > We just need to be careful with the static branch activation: > since there is no particular preferred order of their activation, > we need to make sure that we only start using it after all > call sites are active. This is achieved by having a per-memcg > flag that is only updated after static_key_slow_inc() returns. > At this time, we are sure all sites are active. > > This is made per-memcg, not global, for a reason: > it also has the effect of making socket accounting more > consistent. The first memcg to be limited will trigger static_key() > activation, therefore, accounting. But all the others will then be > accounted no matter what. After this patch, only limited memcgs > will have its sockets accounted. > > ... > > @@ -107,10 +104,31 @@ static int tcp_update_limit(struct mem_cgroup *memcg, u64 val) > tcp->tcp_prot_mem[i] = min_t(long, val >> PAGE_SHIFT, > net->ipv4.sysctl_tcp_mem[i]); > > - if (val == RESOURCE_MAX && old_lim != RESOURCE_MAX) > - static_key_slow_dec(&memcg_socket_limit_enabled); > - else if (old_lim == RESOURCE_MAX && val != RESOURCE_MAX) > - static_key_slow_inc(&memcg_socket_limit_enabled); > + if (val == RESOURCE_MAX) > + cg_proto->active = false; > + else if (val != RESOURCE_MAX) { > + /* > + * ->activated needs to be written after the static_key update. > + * This is what guarantees that the …
creator: akpm
date: 2012-05-16T21:06:37-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On Fri, 11 May 2012 17:11:17 -0300 Glauber Costa <glommer@parallels.com> wrote: > We call the destroy function when a cgroup starts to be removed, > such as by a rmdir event. > > However, because of our reference counters, some objects are still > inflight. Right now, we are decrementing the static_keys at destroy() > time, meaning that if we get rid of the last static_key reference, > some objects will still have charges, but the code to properly > uncharge them won't be run. > > This becomes a problem specially if it is ever enabled again, because > now new charges will be added to the staled charges making keeping > it pretty much impossible. > > We just need to be careful with the static branch activation: > since there is no particular preferred order of their activation, > we need to make sure that we only start using it after all > call sites are active. This is achieved by having a per-memcg > flag that is only updated after static_key_slow_inc() returns. > At this time, we are sure all sites are active. > > This is made per-memcg, not global, for a reason: > it also has the effect of making socket accounting more > consistent. The first memcg to be limited will trigger static_key() > activation, therefore, accounting. But all the others will then be > accounted no matter what. After this patch, only limited memcgs > will have its sockets accounted. So I'm scratching my head over what the actual bug is, and how important it is. AFAICT it will cause charging stats to exhibit some inaccuracy when memcg's are being torn down? I don't know how serious this in in the real world and so can't decide which kernel version(s) we should fix. When fixing bugs, please always fully describe the bug's end-user impact, so that I and others can make these sorts of decisions.
creator: akpm
date: 2012-05-16T21:13:42-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: (2012/05/17 6:13), Andrew Morton wrote: > On Fri, 11 May 2012 17:11:17 -0300 > Glauber Costa <glommer@parallels.com> wrote: > >> We call the destroy function when a cgroup starts to be removed, >> such as by a rmdir event. >> >> However, because of our reference counters, some objects are still >> inflight. Right now, we are decrementing the static_keys at destroy() >> time, meaning that if we get rid of the last static_key reference, >> some objects will still have charges, but the code to properly >> uncharge them won't be run. >> >> This becomes a problem specially if it is ever enabled again, because >> now new charges will be added to the staled charges making keeping >> it pretty much impossible. >> >> We just need to be careful with the static branch activation: >> since there is no particular preferred order of their activation, >> we need to make sure that we only start using it after all >> call sites are active. This is achieved by having a per-memcg >> flag that is only updated after static_key_slow_inc() returns. >> At this time, we are sure all sites are active. >> >> This is made per-memcg, not global, for a reason: >> it also has the effect of making socket accounting more >> consistent. The first memcg to be limited will trigger static_key() >> activation, therefore, accounting. But all the others will then be >> accounted no matter what. After this patch, only limited memcgs >> will have its sockets accounted. > > So I'm scratching my head over what the actual bug is, and how > important it is. AFAICT it will cause charging stats to exhibit some > inaccuracy when memcg's are being torn down? > > I don't know how serious this in in the real world and so can't decide > which kernel version(s) we should fix. > > When fixing bugs, please always fully describe the bug's end-user > impact, so that I and others can make these sorts of decisions. > Ah, this was a bug report from me. tcp accounting can be easily broken. Costa, could you include this ? == tc…
creator: KAMEZAWA Hiroyuki
date: 2012-05-17T00:07:11-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/17/2012 01:06 AM, Andrew Morton wrote: > On Fri, 11 May 2012 17:11:17 -0300 > Glauber Costa<glommer@parallels.com> wrote: > >> We call the destroy function when a cgroup starts to be removed, >> such as by a rmdir event. >> >> However, because of our reference counters, some objects are still >> inflight. Right now, we are decrementing the static_keys at destroy() >> time, meaning that if we get rid of the last static_key reference, >> some objects will still have charges, but the code to properly >> uncharge them won't be run. >> >> This becomes a problem specially if it is ever enabled again, because >> now new charges will be added to the staled charges making keeping >> it pretty much impossible. >> >> We just need to be careful with the static branch activation: >> since there is no particular preferred order of their activation, >> we need to make sure that we only start using it after all >> call sites are active. This is achieved by having a per-memcg >> flag that is only updated after static_key_slow_inc() returns. >> At this time, we are sure all sites are active. >> >> This is made per-memcg, not global, for a reason: >> it also has the effect of making socket accounting more >> consistent. The first memcg to be limited will trigger static_key() >> activation, therefore, accounting. But all the others will then be >> accounted no matter what. After this patch, only limited memcgs >> will have its sockets accounted. >> >> ... >> >> @@ -107,10 +104,31 @@ static int tcp_update_limit(struct mem_cgroup *memcg, u64 val) >> tcp->tcp_prot_mem[i] = min_t(long, val>> PAGE_SHIFT, >> net->ipv4.sysctl_tcp_mem[i]); >> >> - if (val == RESOURCE_MAX&& old_lim != RESOURCE_MAX) >> - static_key_slow_dec(&memcg_socket_limit_enabled); >> - else if (old_lim == RESOURCE_MAX&& val != RESOURCE_MAX) >> - static_key_slow_inc(&memcg_socket_limit_enabled); >> + if (val == RESOURCE_MAX) >> + cg_proto->active = false; >> + else if (val != RESOURCE_MAX) { >> + /* >> + * ->activated…
creator: Glauber Costa
date: 2012-05-17T03:06:52-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/17/2012 01:13 AM, Andrew Morton wrote: > On Fri, 11 May 2012 17:11:17 -0300 > Glauber Costa<glommer@parallels.com> wrote: > >> We call the destroy function when a cgroup starts to be removed, >> such as by a rmdir event. >> >> However, because of our reference counters, some objects are still >> inflight. Right now, we are decrementing the static_keys at destroy() >> time, meaning that if we get rid of the last static_key reference, >> some objects will still have charges, but the code to properly >> uncharge them won't be run. >> >> This becomes a problem specially if it is ever enabled again, because >> now new charges will be added to the staled charges making keeping >> it pretty much impossible. >> >> We just need to be careful with the static branch activation: >> since there is no particular preferred order of their activation, >> we need to make sure that we only start using it after all >> call sites are active. This is achieved by having a per-memcg >> flag that is only updated after static_key_slow_inc() returns. >> At this time, we are sure all sites are active. >> >> This is made per-memcg, not global, for a reason: >> it also has the effect of making socket accounting more >> consistent. The first memcg to be limited will trigger static_key() >> activation, therefore, accounting. But all the others will then be >> accounted no matter what. After this patch, only limited memcgs >> will have its sockets accounted. > > So I'm scratching my head over what the actual bug is, and how > important it is. AFAICT it will cause charging stats to exhibit some > inaccuracy when memcg's are being torn down? > > I don't know how serious this in in the real world and so can't decide > which kernel version(s) we should fix. > > When fixing bugs, please always fully describe the bug's end-user > impact, so that I and others can make these sorts of decisions. Hi Andrew. I believe that was described in patch 0/2 ? In any case, this is something we need fixed, but it…
creator: Glauber Costa
date: 2012-05-17T03:09:29-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On Thu, 17 May 2012 07:06:52 +0400 Glauber Costa <glommer@parallels.com> wrote: > ... > >> + else if (val != RESOURCE_MAX) { > >> + /* > >> + * ->activated needs to be written after the static_key update. > >> + * This is what guarantees that the socket activation function > >> + * is the last one to run. See sock_update_memcg() for details, > >> + * and note that we don't mark any socket as belonging to this > >> + * memcg until that flag is up. > >> + * > >> + * We need to do this, because static_keys will span multiple > >> + * sites, but we can't control their order. If we mark a socket > >> + * as accounted, but the accounting functions are not patched in > >> + * yet, we'll lose accounting. > >> + * > >> + * We never race with the readers in sock_update_memcg(), because > >> + * when this value change, the code to process it is not patched in > >> + * yet. > >> + */ > >> + if (!cg_proto->activated) { > >> + static_key_slow_inc(&memcg_socket_limit_enabled); > >> + cg_proto->activated = true; > >> + } > > > > If two threads run this code concurrently, they can both see > > cg_proto->activated==false and they will both run > > static_key_slow_inc(). > > > > Hopefully there's some locking somewhere which prevents this, but it is > > unobvious. We should comment this, probably at the cg_proto.activated > > definition site. Or we should fix the bug ;) > > > If that happens, locking in static_key_slow_inc will prevent any damage. > My previous version had explicit code to prevent that, but we were > pointed out that this is already part of the static_key expectations, so > that was dropped. This makes no sense. If two threads run that code concurrently, key->enabled gets incremented twice. Nobody anywhere has a record that this happened so it cannot be undone. key->enabled is now in an unknown state.
creator: akpm
date: 2012-05-17T05:37:15-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/17/2012 09:37 AM, Andrew Morton wrote: >> > If that happens, locking in static_key_slow_inc will prevent any damage. >> > My previous version had explicit code to prevent that, but we were >> > pointed out that this is already part of the static_key expectations, so >> > that was dropped. > This makes no sense. If two threads run that code concurrently, > key->enabled gets incremented twice. Nobody anywhere has a record that > this happened so it cannot be undone. key->enabled is now in an > unknown state. Kame, Tejun, Andrew is right. It seems we will need that mutex after all. Just this is not a race, and neither something that should belong in the static_branch interface. We want to make sure that enabled is not updated before the jump label update, because we need a specific ordering guarantee at the patched sites. And *that*, the interface guarantees, and we were wrong to believe it did not. That is a correction issue for the accounting, and that part is right. But when we disarm it, we'll need to make sure that happened only once, otherwise we may never unpatch it. That, or we'd need that to be a counter. The jump label interface does not - and should not - keep track of how many updates happened to a key. That's the role of whoever is using it. If you agree with the above, I'll send this patch again with the correction. Andrew, thank you very much. Do you spot anything else here?
creator: Glauber Costa
date: 2012-05-17T09:52:13-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: (2012/05/17 18:52), Glauber Costa wrote: > On 05/17/2012 09:37 AM, Andrew Morton wrote: >>>> If that happens, locking in static_key_slow_inc will prevent any damage. >>>> My previous version had explicit code to prevent that, but we were >>>> pointed out that this is already part of the static_key expectations, so >>>> that was dropped. >> This makes no sense. If two threads run that code concurrently, >> key->enabled gets incremented twice. Nobody anywhere has a record that >> this happened so it cannot be undone. key->enabled is now in an >> unknown state. > > Kame, Tejun, > > Andrew is right. It seems we will need that mutex after all. Just this > is not a race, and neither something that should belong in the > static_branch interface. > Hmm....how about having res_counter_xchg_limit(res, &old_limit, new_limit); if (!cg_proto->updated && old_limit == RESOURCE_MAX) ....update labels... Then, no mutex overhead maybe and activated will be updated only once. Ah, but please fix in a way you like. Above is an example. Thanks, -Kame (*) I'm sorry I won't be able to read e-mails, tomorrow.
creator: KAMEZAWA Hiroyuki
date: 2012-05-17T10:18:09-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On 05/17/2012 02:18 PM, KAMEZAWA Hiroyuki wrote: > (2012/05/17 18:52), Glauber Costa wrote: > >> On 05/17/2012 09:37 AM, Andrew Morton wrote: >>>>> If that happens, locking in static_key_slow_inc will prevent any damage. >>>>> My previous version had explicit code to prevent that, but we were >>>>> pointed out that this is already part of the static_key expectations, so >>>>> that was dropped. >>> This makes no sense. If two threads run that code concurrently, >>> key->enabled gets incremented twice. Nobody anywhere has a record that >>> this happened so it cannot be undone. key->enabled is now in an >>> unknown state. >> >> Kame, Tejun, >> >> Andrew is right. It seems we will need that mutex after all. Just this >> is not a race, and neither something that should belong in the >> static_branch interface. >> > > > Hmm....how about having > > res_counter_xchg_limit(res,&old_limit, new_limit); > > if (!cg_proto->updated&& old_limit == RESOURCE_MAX) > ....update labels... > > Then, no mutex overhead maybe and activated will be updated only once. > Ah, but please fix in a way you like. Above is an example. I think a mutex is a lot cleaner than adding a new function to the res_counter interface. We could do a counter, and then later decrement the key until the counter reaches zero, but between those two, I still think a mutex here is preferable. Only that, instead of coming up with a mutex of ours, we could export and reuse set_limit_mutex from memcontrol.c > Thanks, > -Kame > (*) I'm sorry I won't be able to read e-mails, tomorrow. > Ok Kame. I am not in a terrible hurry to fix this, it doesn't seem to be hurting any real workload.
creator: Glauber Costa
date: 2012-05-17T10:22:05-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: (2012/05/17 19:22), Glauber Costa wrote: > On 05/17/2012 02:18 PM, KAMEZAWA Hiroyuki wrote: >> (2012/05/17 18:52), Glauber Costa wrote: >> >>> On 05/17/2012 09:37 AM, Andrew Morton wrote: >>>>>> If that happens, locking in static_key_slow_inc will prevent any damage. >>>>>> My previous version had explicit code to prevent that, but we were >>>>>> pointed out that this is already part of the static_key expectations, so >>>>>> that was dropped. >>>> This makes no sense. If two threads run that code concurrently, >>>> key->enabled gets incremented twice. Nobody anywhere has a record that >>>> this happened so it cannot be undone. key->enabled is now in an >>>> unknown state. >>> >>> Kame, Tejun, >>> >>> Andrew is right. It seems we will need that mutex after all. Just this >>> is not a race, and neither something that should belong in the >>> static_branch interface. >>> >> >> >> Hmm....how about having >> >> res_counter_xchg_limit(res,&old_limit, new_limit); >> >> if (!cg_proto->updated&& old_limit == RESOURCE_MAX) >> ....update labels... >> >> Then, no mutex overhead maybe and activated will be updated only once. >> Ah, but please fix in a way you like. Above is an example. > > I think a mutex is a lot cleaner than adding a new function to the > res_counter interface. > > We could do a counter, and then later decrement the key until the > counter reaches zero, but between those two, I still think a mutex here > is preferable. > > Only that, instead of coming up with a mutex of ours, we could export > and reuse set_limit_mutex from memcontrol.c > ok, please. thx, -Kame > >> Thanks, >> -Kame >> (*) I'm sorry I won't be able to read e-mails, tomorrow. >> > Ok Kame. I am not in a terrible hurry to fix this, it doesn't seem to be > hurting any real workload. > >
creator: KAMEZAWA Hiroyuki
date: 2012-05-17T10:27:09-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On Thu, May 17, 2012 at 01:52:13PM +0400, Glauber Costa wrote: > Andrew is right. It seems we will need that mutex after all. Just > this is not a race, and neither something that should belong in the > static_branch interface. Yeah, with a completely different comment. It just needs to wrap ->activated alteration and static key inc/dec, right? Thanks. -- tejun
creator: Tejun Heo
date: 2012-05-17T15:19:47-00:00

Re: [PATCH v5 2/2] decrement static keys on real destroy time
type: item
description: On Thu, 17 May 2012 13:52:13 +0400 Glauber Costa <glommer@parallels.com> wrote: > Andrew is right. It seems we will need that mutex after all. Just this > is not a race, and neither something that should belong in the > static_branch interface. Well, a mutex is one way. Or you could do something like if (!test_and_set_bit(CGPROTO_ACTIVATED, &cg_proto->flags)) static_key_slow_inc(&memcg_socket_limit_enabled);
creator: akpm
date: 2012-05-17T17:02:53-00:00