Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758683Ab2JKNke (ORCPT ); Thu, 11 Oct 2012 09:40:34 -0400 Received: from cantor2.suse.de ([195.135.220.15]:57647 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753986Ab2JKNka (ORCPT ); Thu, 11 Oct 2012 09:40:30 -0400 Date: Thu, 11 Oct 2012 15:40:28 +0200 From: Michal Hocko To: Glauber Costa Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Mel Gorman , Suleiman Souhlal , Tejun Heo , cgroups@vger.kernel.org, kamezawa.hiroyu@jp.fujitsu.com, Johannes Weiner , Greg Thelen , devel@openvz.org, Frederic Weisbecker , Christoph Lameter , Pekka Enberg Subject: Re: [PATCH v4 10/14] memcg: use static branches when code not in use Message-ID: <20121011134028.GH29295@dhcp22.suse.cz> References: <1349690780-15988-1-git-send-email-glommer@parallels.com> <1349690780-15988-11-git-send-email-glommer@parallels.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1349690780-15988-11-git-send-email-glommer@parallels.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2489 Lines: 69 On Mon 08-10-12 14:06:16, Glauber Costa wrote: > We can use static branches to patch the code in or out when not used. > > Because the _ACTIVE bit on kmem_accounted is only set after the > increment is done, we guarantee that the root memcg will always be > selected for kmem charges until all call sites are patched (see > memcg_kmem_enabled). This guarantees that no mischarges are applied. > > static branch decrement happens when the last reference count from the > kmem accounting in memcg dies. This will only happen when the charges > drop down to 0. > > When that happen, we need to disable the static branch only on those > memcgs that enabled it. To achieve this, we would be forced to > complicate the code by keeping track of which memcgs were the ones > that actually enabled limits, and which ones got it from its parents. > > It is a lot simpler just to do static_key_slow_inc() on every child > that is accounted. > > [ v4: adapted this patch to the changes in kmem_accounted ] > > Signed-off-by: Glauber Costa > CC: Kamezawa Hiroyuki > CC: Christoph Lameter > CC: Pekka Enberg > CC: Michal Hocko > CC: Johannes Weiner > CC: Suleiman Souhlal Looks reasonable to me Acked-by: Michal Hocko Just a little nit. [...] > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 634c7b5..724a08b 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -344,11 +344,15 @@ struct mem_cgroup { > /* internal only representation about the status of kmem accounting. */ > enum { > KMEM_ACCOUNTED_ACTIVE = 0, /* accounted by this cgroup itself */ > + KMEM_ACCOUNTED_ACTIVATED, /* static key enabled. */ > KMEM_ACCOUNTED_DEAD, /* dead memcg, pending kmem charges */ > }; > > -/* first bit */ > -#define KMEM_ACCOUNTED_MASK 0x1 > +/* > + * first two bits. We account when limit is on, but only after > + * call sites are patched > + */ > +#define KMEM_ACCOUNTED_MASK 0x3 The names are long but why not use KMEM_ACCOUNTED_ACTIVE* #define KMEM_ACCOUNTED_MASK 1<