OpenVZ Forum - RDF feed
type: channel
items: [PATCH v4 00/14] kmem controller for memcg.
items: [PATCH v4 01/14] memcg: Make it possible to use the stock for more than one page.
items: [PATCH v4 02/14] memcg: Reclaim when more than one page needed.
items: [PATCH v4 03/14] memcg: change defines to an enum
items: [PATCH v4 04/14] kmem accounting basic infrastructure
items: [PATCH v4 05/14] Add a __GFP_KMEMCG flag
items: [PATCH v4 06/14] memcg: kmem controller infrastructure
items: [PATCH v4 07/14] mm: Allocate kernel pages to the right memcg
items: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
items: [PATCH v4 09/14] memcg: kmem accounting lifecycle management
items: [PATCH v4 10/14] memcg: use static branches when code not in use
items: [PATCH v4 11/14] memcg: allow a memcg with kmem charges to be destructed.
items: [PATCH v4 12/14] execute the whole memcg freeing in free_worker
items: [PATCH v4 13/14] protect architectures where THREAD_SIZE &gt;= PAGE_SIZE against fork bombs
items: [PATCH v4 14/14] Add documentation about the kmem controller
items: Re: [PATCH v4 05/14] Add a __GFP_KMEMCG flag
items: Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
items: Re: [PATCH v4 04/14] kmem accounting basic infrastructure
items: Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
items: Re: [PATCH v4 09/14] memcg: kmem accounting lifecycle management
items: Re: [PATCH v4 10/14] memcg: use static branches when code not in use
items: Re: [PATCH v4 12/14] execute the whole memcg freeing in free_worker
items: Re: [PATCH v4 14/14] Add documentation about the kmem controller
items: Re: [PATCH v4 02/14] memcg: Reclaim when more than one page needed.

[PATCH v4 00/14] kmem controller for memcg.
type: item
description: Hi, This is the first part of the kernel memory controller for memcg. It has been discussed many times, and I consider this stable enough to be on tree. A follow up to this series are the patches to also track slab memory. They are not included here because I believe we could benefit from merging them separately for better testing coverage. If there are any issues preventing this to be merged, let me know. I'll be happy to address them. *v4: - kmem_accounted can no longer become unlimited - kmem_accounted can no longer become limited, if group has children. - documentation moved to this patchset - more style changes - css_get in charge path to ensure task won't move during charge *v3: - Changed function names to match memcg's - avoid doing get/put in charge/uncharge path - revert back to keeping the account enabled after it is first activated The slab patches are going through a rework of the cache selection mechanism. But after some rounds of discussion, the bulk of it is still stable in my self evaluation and could be merged not too long after this. For the reference, the last discussion about them happened at http://lwn.net/Articles/516705/. I expect to send patches for that within the week. Numbers can be found at https://lkml.org/lkml/2012/9/13/239 A (throwaway) git tree with them is placed at: git://git.kernel.org/pub/scm/linux/kernel/git/glommer/memcg. git kmemcg-stack A general explanation of what this is all about follows: The kernel memory limitation mechanism for memcg concerns itself with disallowing potentially non-reclaimable allocations to happen in exaggerate quantities by a particular set of processes (cgroup). Those allocations could create pressure that affects the behavior of a different and unrelated set of processes. Its basic working mechanism is to annotate some allocations with the _GFP_KMEMCG flag. When this flag is set, the current process allocating will have its memcg identified and charged against. When reaching a specific limit, furthe…
creator: Glauber Costa
date: 2012-10-08T10:06:06-00:00

[PATCH v4 01/14] memcg: Make it possible to use the stock for more than one page.
type: item
description: From: Suleiman Souhlal <ssouhlal@FreeBSD.org> We currently have a percpu stock cache scheme that charges one page at a time from memcg->res, the user counter. When the kernel memory controller comes into play, we'll need to charge more than that. This is because kernel memory allocations will also draw from the user counter, and can be bigger than a single page, as it is the case with the stack (usually 2 pages) or some higher order slabs. [ glommer@parallels.com: added a changelog ] Signed-off-by: Suleiman Souhlal <suleiman@google.com> Signed-off-by: Glauber Costa <glommer@parallels.com> Acked-by: David Rientjes <rientjes@google.com> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/memcontrol.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7acf43b..47cb019 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2028,20 +2028,28 @@ struct memcg_stock_pcp { static DEFINE_PER_CPU(struct memcg_stock_pcp, memcg_stock); static DEFINE_MUTEX(percpu_charge_mutex); -/* - * Try to consume stocked charge on this cpu. If success, one page is consumed - * from local stock and true is returned. If the stock is 0 or charges from a - * cgroup which is not current target, returns false. This stock will be - * refilled. +/** + * consume_stock: Try to consume stocked charge on this cpu. + * @memcg: memcg to consume from. + * @nr_pages: how many pages to charge. + * + * The charges will only happen if @memcg matches the current cpu's memcg + * stock, and at least @nr_pages are available in that stock. Failure to + * service an allocation will refill the stock. + * + * returns true if succesfull, false otherwise. */ -static bool consume_stock(struct mem_cgroup *memcg) +static bool consume_stock(struct mem_cgroup *memcg, int nr_pages) { struct memcg_stock_pcp *stock; bool ret = true; + if (nr_pa…
creator: Glauber Costa
date: 2012-10-08T10:06:07-00:00

[PATCH v4 02/14] memcg: Reclaim when more than one page needed.
type: item
description: From: Suleiman Souhlal <ssouhlal@FreeBSD.org> mem_cgroup_do_charge() was written before kmem accounting, and expects three cases: being called for 1 page, being called for a stock of 32 pages, or being called for a hugepage. If we call for 2 or 3 pages (and both the stack and several slabs used in process creation are such, at least with the debug options I had), it assumed it's being called for stock and just retried without reclaiming. Fix that by passing down a minsize argument in addition to the csize. And what to do about that (csize == PAGE_SIZE && ret) retry? If it's needed at all (and presumably is since it's there, perhaps to handle races), then it should be extended to more than PAGE_SIZE, yet how far? And should there be a retry count limit, of what? For now retry up to COSTLY_ORDER (as page_alloc.c does) and make sure not to do it if __GFP_NORETRY. [v4: fixed nr pages calculation pointed out by Christoph Lameter ] Signed-off-by: Suleiman Souhlal <suleiman@google.com> Signed-off-by: Glauber Costa <glommer@parallels.com> Reviewed-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/memcontrol.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 47cb019..7a9652a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2226,7 +2226,8 @@ enum { }; static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, - unsigned int nr_pages, bool oom_check) + unsigned int nr_pages, unsigned int min_pages, + bool oom_check) { unsigned long csize = nr_pages * PAGE_SIZE; struct mem_cgroup *mem_over_limit; @@ -2249,18 +2250,18 @@ static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, } else mem_over_limit = mem_cgroup_from_res_counter(fail_res, res); /* - * nr_pages can be either a huge page (HPAGE_PMD_NR), a batch - * of regular pages (CHARGE_BATCH), or a single regular page (1…
creator: Glauber Costa
date: 2012-10-08T10:06:08-00:00

[PATCH v4 03/14] memcg: change defines to an enum
type: item
description: This is just a cleanup patch for clarity of expression. In earlier submissions, people asked it to be in a separate patch, so here it is. [ v2: use named enum as type throughout the file as well ] Signed-off-by: Glauber Costa <glommer@parallels.com> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Johannes Weiner <hannes@cmpxchg.org> --- mm/memcontrol.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7a9652a..71d259e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -386,9 +386,12 @@ enum charge_type { }; /* for encoding cft->private value on file */ -#define _MEM (0) -#define _MEMSWAP (1) -#define _OOM_TYPE (2) +enum res_type { + _MEM, + _MEMSWAP, + _OOM_TYPE, +}; + #define MEMFILE_PRIVATE(x, val) ((x) << 16 | (val)) #define MEMFILE_TYPE(val) ((val) >> 16 & 0xffff) #define MEMFILE_ATTR(val) ((val) & 0xffff) @@ -3915,7 +3918,8 @@ static ssize_t mem_cgroup_read(struct cgroup *cont, struct cftype *cft, struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); char str[64]; u64 val; - int type, name, len; + int name, len; + enum res_type type; type = MEMFILE_TYPE(cft->private); name = MEMFILE_ATTR(cft->private); @@ -3951,7 +3955,8 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, const char *buffer) { struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); - int type, name; + enum res_type type; + int name; unsigned long long val; int ret; @@ -4027,7 +4032,8 @@ out: static int mem_cgroup_reset(struct cgroup *cont, unsigned int event) { struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); - int type, name; + int name; + enum res_type type; type = MEMFILE_TYPE(event); name = MEMFILE_ATTR(event); @@ -4363,7 +4369,7 @@ static int mem_cgroup_usage_register_event(struct cgroup *cgrp, struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); struct mem_cgroup_thresholds *thresholds; struct mem_cgroup_threshol…
creator: Glauber Costa
date: 2012-10-08T10:06:09-00:00

[PATCH v4 04/14] kmem accounting basic infrastructure
type: item
description: This patch adds the basic infrastructure for the accounting of the slab caches. To control that, the following files are created: * memory.kmem.usage_in_bytes * memory.kmem.limit_in_bytes * memory.kmem.failcnt * memory.kmem.max_usage_in_bytes They have the same meaning of their user memory counterparts. They reflect the state of the "kmem" res_counter. Per cgroup slab memory accounting is not enabled until a limit is set for the group. Once the limit is set the accounting cannot be disabled for that group. This means that after the patch is applied, no behavioral changes exists for whoever is still using memcg to control their memory usage, until memory.kmem.limit_in_bytes is set for the first time. We always account to both user and kernel resource_counters. This effectively means that an independent kernel limit is in place when the limit is set to a lower value than the user memory. A equal or higher value means that the user limit will always hit first, meaning that kmem is effectively unlimited. People who want to track kernel memory but not limit it, can set this limit to a very high number (like RESOURCE_MAX - 1page - that no one will ever hit, or equal to the user memory) [ v4: make kmem files part of the main array; do not allow limit to be set for non-empty cgroups ] Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Michal Hocko <mhocko@suse.cz> CC: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> --- mm/memcontrol.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 71d259e..ba855cc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -266,6 +266,10 @@ struct mem_cgroup { }; /* + * the counter to account for kernel memory usage. + */ + struct res_counter kmem; + /* * Per cgroup active and inactive list, similar to the * per zone LRU lists. */ @@ -280,6 +284,7 @@ struct mem_cgroup { * Sho…
creator: Glauber Costa
date: 2012-10-08T10:06:10-00:00

[PATCH v4 05/14] Add a __GFP_KMEMCG flag
type: item
description: This flag is used to indicate to the callees that this allocation is a kernel allocation in process context, and should be accounted to current's memcg. It takes numerical place of the of the recently removed __GFP_NO_KSWAPD. [ v4: make flag unconditional, also declare it in trace code ] Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Christoph Lameter <cl@linux.com> CC: Pekka Enberg <penberg@cs.helsinki.fi> CC: Michal Hocko <mhocko@suse.cz> CC: Suleiman Souhlal <suleiman@google.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Rik van Riel <riel@redhat.com> Acked-by: Mel Gorman <mel@csn.ul.ie> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> --- include/linux/gfp.h | 3 ++- include/trace/events/gfpflags.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 02c1c97..9289d46 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -31,6 +31,7 @@ struct vm_area_struct; #define ___GFP_THISNODE 0x40000u #define ___GFP_RECLAIMABLE 0x80000u #define ___GFP_NOTRACK 0x200000u +#define ___GFP_KMEMCG 0x400000u #define ___GFP_OTHER_NODE 0x800000u #define ___GFP_WRITE 0x1000000u @@ -87,7 +88,7 @@ struct vm_area_struct; #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */ #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */ - +#define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */ /* * This may seem redundant, but it's a way of annotating false positives vs. * allocations that simply cannot be supported (e.g. page tables). diff --git a/include/trace/events/gfpflags.h b/include/trace/events/gfpflags.h index 9391706..730df12 100644 --- a/include/trace/events/gfpflags.h +++ b/include/trace/events/gfpflags.h @@ -36,6 +36,7 @@ {(unsigned long)__GFP_RECLAIMABLE, "GFP_RECLAIMABLE"}, \ {(unsigned long)__GFP_MOVABLE, "GFP_MOVABLE"}, \ {(unsigned long)__GFP_NOTRACK, "GF…
creator: Glauber Costa
date: 2012-10-08T10:06:11-00:00

[PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: This patch introduces infrastructure for tracking kernel memory pages to a given memcg. This will happen whenever the caller includes the flag __GFP_KMEMCG flag, and the task belong to a memcg other than the root. In memcontrol.h those functions are wrapped in inline acessors. The idea is to later on, patch those with static branches, so we don't incur any overhead when no mem cgroups with limited kmem are being used. Users of this functionality shall interact with the memcg core code through the following functions: memcg_kmem_newpage_charge: will return true if the group can handle the allocation. At this point, struct page is not yet allocated. memcg_kmem_commit_charge: will either revert the charge, if struct page allocation failed, or embed memcg information into page_cgroup. memcg_kmem_uncharge_page: called at free time, will revert the charge. [ v2: improved comments and standardized function names ] [ v3: handle no longer opaque, functions not exported, even more comments ] [ v4: reworked Used bit handling and surroundings for more clarity ] [ v5: simplified code for kmemcg compiled out and core functions in memcontrol.c, moved kmem code to the middle to avoid forward decls ] Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Christoph Lameter <cl@linux.com> CC: Pekka Enberg <penberg@cs.helsinki.fi> CC: Michal Hocko <mhocko@suse.cz> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> CC: Johannes Weiner <hannes@cmpxchg.org> --- include/linux/memcontrol.h | 95 +++++++++++++++++++++++++ mm/memcontrol.c | 173 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 263 insertions(+), 5 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 8d9489f..783cd78 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -21,6 +21,7 @@ #define _LINUX_MEMCONTROL_H #include <linux/cgroup.h> #include <linux/vm_event_item.h> +#include <linux/hardirq.h> struct mem_cgroup; struct page_cgroup; @@ -399,6 +400,85…
creator: Glauber Costa
date: 2012-10-08T10:06:12-00:00

[PATCH v4 07/14] mm: Allocate kernel pages to the right memcg
type: item
description: When a process tries to allocate a page with the __GFP_KMEMCG flag, the page allocator will call the corresponding memcg functions to validate the allocation. Tasks in the root memcg can always proceed. To avoid adding markers to the page - and a kmem flag that would necessarily follow, as much as doing page_cgroup lookups for no reason, whoever is marking its allocations with __GFP_KMEMCG flag is responsible for telling the page allocator that this is such an allocation at free_pages() time. This is done by the invocation of __free_accounted_pages() and free_accounted_pages(). [ v2: inverted test order to avoid a memcg_get leak, free_accounted_pages simplification ] [ v4: test for TIF_MEMDIE at newpage_charge ] Signed-off-by: Glauber Costa <glommer@parallels.com> Acked-by: Michal Hocko <mhocko@suse.cz> Acked-by: Mel Gorman <mgorman@suse.de> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> CC: Christoph Lameter <cl@linux.com> CC: Pekka Enberg <penberg@cs.helsinki.fi> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Suleiman Souhlal <suleiman@google.com> --- include/linux/gfp.h | 3 +++ mm/page_alloc.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 9289d46..8f6fe34 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -362,6 +362,9 @@ extern void free_pages(unsigned long addr, unsigned int order); extern void free_hot_cold_page(struct page *page, int cold); extern void free_hot_cold_page_list(struct list_head *list, int cold); +extern void __free_accounted_pages(struct page *page, unsigned int order); +extern void free_accounted_pages(unsigned long addr, unsigned int order); + #define __free_page(page) __free_pages((page), 0) #define free_page(addr) free_pages((addr), 0) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index feddc7f..dcf33ad 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2595,6 +2595,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int or…
creator: Glauber Costa
date: 2012-10-08T10:06:13-00:00

[PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: It is useful to know how many charges are still left after a call to res_counter_uncharge. While it is possible to issue a res_counter_read after uncharge, this can be racy. If we need, for instance, to take some action when the counters drop down to 0, only one of the callers should see it. This is the same semantics as the atomic variables in the kernel. Since the current return value is void, we don't need to worry about anything breaking due to this change: nobody relied on that, and only users appearing from now on will be checking this value. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Michal Hocko <mhocko@suse.cz> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Suleiman Souhlal <suleiman@google.com> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> --- Documentation/cgroups/resource_counter.txt | 7 ++++--- include/linux/res_counter.h | 12 +++++++----- kernel/res_counter.c | 20 +++++++++++++------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Documentation/cgroups/resource_counter.txt b/Documentation/cgroups/resource_counter.txt index 0c4a344..c4d99ed 100644 --- a/Documentation/cgroups/resource_counter.txt +++ b/Documentation/cgroups/resource_counter.txt @@ -83,16 +83,17 @@ to work with it. res_counter->lock internally (it must be called with res_counter->lock held). The force parameter indicates whether we can bypass the limit. - e. void res_counter_uncharge[_locked] + e. u64 res_counter_uncharge[_locked] (struct res_counter *rc, unsigned long val) When a resource is released (freed) it should be de-accounted from the resource counter it was accounted to. This is called - "uncharging". + "uncharging". The return value of this function indicate the amount + of charges still present in the counter. The _locked routines imply that the res_counter->lock is taken. - f. void res_counter_uncharge_until + f. u64 res_counter_uncharge_until (struct res_counter *rc, struct res_counter *top, unsinged long val) diff --git a/include/linux/…
creator: Glauber Costa
date: 2012-10-08T10:06:14-00:00

[PATCH v4 09/14] memcg: kmem accounting lifecycle management
type: item
description: Because kmem charges can outlive the cgroup, we need to make sure that we won't free the memcg structure while charges are still in flight. For reviewing simplicity, the charge functions will issue mem_cgroup_get() at every charge, and mem_cgroup_put() at every uncharge. This can get expensive, however, and we can do better. mem_cgroup_get() only really needs to be issued once: when the first limit is set. In the same spirit, we only need to issue mem_cgroup_put() when the last charge is gone. We'll need an extra bit in kmem_accounted for that: KMEM_ACCOUNTED_DEAD. it will be set when the cgroup dies, if there are charges in the group. If there aren't, we can proceed right away. Our uncharge function will have to test that bit every time the charges drop to 0. Because that is not the likely output of res_counter_uncharge, this should not impose a big hit on us: it is certainly much better than a reference count decrease at every operation. [ v3: merged all lifecycle related patches in one ] Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> CC: Christoph Lameter <cl@linux.com> CC: Pekka Enberg <penberg@cs.helsinki.fi> CC: Michal Hocko <mhocko@suse.cz> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Suleiman Souhlal <suleiman@google.com> --- mm/memcontrol.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index dda54f0..634c7b5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -344,6 +344,7 @@ struct mem_cgroup { /* internal only representation about the status of kmem accounting. */ enum { KMEM_ACCOUNTED_ACTIVE = 0, /* accounted by this cgroup itself */ + KMEM_ACCOUNTED_DEAD, /* dead memcg, pending kmem charges */ }; /* first bit */ @@ -354,6 +355,22 @@ static void memcg_kmem_set_active(struct mem_cgroup *memcg) { set_bit(KMEM_ACCOUNTED_ACTIVE, &memcg->kmem_accounted); } + +static bool memcg_kmem_is_ac…
creator: Glauber Costa
date: 2012-10-08T10:06:15-00:00

[PATCH v4 10/14] memcg: use static branches when code not in use
type: item
description: 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 <glommer@parallels.com> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> CC: Christoph Lameter <cl@linux.com> CC: Pekka Enberg <penberg@cs.helsinki.fi> CC: Michal Hocko <mhocko@suse.cz> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Suleiman Souhlal <suleiman@google.com> --- include/linux/memcontrol.h | 4 ++- mm/memcontrol.c | 82 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 783cd78..40d658d 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -22,6 +22,7 @@ #include <linux/cgroup.h> #include <linux/vm_event_item.h> #include <linux/hardirq.h> +#include <linux/jump_label.h> struct mem_cgroup; struct page_cgroup; @@ -401,9 +402,10 @@ struct sock; void sock_update_memcg(struct sock *sk); void sock_release_memcg(struct sock *sk); +extern struct static_key memcg_kmem_enabled_key; static inline bool memcg_kmem_enabled(void) { - return true; + return static_key_false(&memcg_kmem_enabled_key); } extern boo…
creator: Glauber Costa
date: 2012-10-08T10:06:16-00:00

[PATCH v4 11/14] memcg: allow a memcg with kmem charges to be destructed.
type: item
description: Because the ultimate goal of the kmem tracking in memcg is to track slab pages as well, we can't guarantee that we'll always be able to point a page to a particular process, and migrate the charges along with it - since in the common case, a page will contain data belonging to multiple processes. Because of that, when we destroy a memcg, we only make sure the destruction will succeed by discounting the kmem charges from the user charges when we try to empty the cgroup. Signed-off-by: Glauber Costa <glommer@parallels.com> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Michal Hocko <mhocko@suse.cz> CC: Christoph Lameter <cl@linux.com> CC: Pekka Enberg <penberg@cs.helsinki.fi> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Suleiman Souhlal <suleiman@google.com> --- mm/memcontrol.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 724a08b..2f92f89 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -546,6 +546,11 @@ static void disarm_kmem_keys(struct mem_cgroup *memcg) { if (memcg_kmem_is_active(memcg)) static_key_slow_dec(&memcg_kmem_enabled_key); + /* + * This check can't live in kmem destruction function, + * since the charges will outlive the cgroup + */ + WARN_ON(res_counter_read_u64(&memcg->kmem, RES_USAGE) != 0); } #else static void disarm_kmem_keys(struct mem_cgroup *memcg) @@ -3994,6 +3999,7 @@ static int mem_cgroup_force_empty(struct mem_cgroup *memcg, bool free_all) int node, zid, shrink; int nr_retries = MEM_CGROUP_RECLAIM_RETRIES; struct cgroup *cgrp = memcg->css.cgroup; + u64 usage; css_get(&memcg->css); @@ -4027,8 +4033,17 @@ move_account: mem_cgroup_end_move(memcg); memcg_oom_recover(memcg); cond_resched(); + /* + * Kernel memory may not necessarily be trackable to a specific + * process. So they are not migrated, and therefore we can't + * expect their value to drop to 0 here. + * + * having res filled up with kmem only is enough + */ + usage = res_coun…
creator: Glauber Costa
date: 2012-10-08T10:06:17-00:00

[PATCH v4 12/14] execute the whole memcg freeing in free_worker
type: item
description: A lot of the initialization we do in mem_cgroup_create() is done with softirqs enabled. This include grabbing a css id, which holds &ss->id_lock->rlock, and the per-zone trees, which holds rtpz->lock->rlock. All of those signal to the lockdep mechanism that those locks can be used in SOFTIRQ-ON-W context. This means that the freeing of memcg structure must happen in a compatible context, otherwise we'll get a deadlock, like the one bellow, caught by lockdep: [<ffffffff81103095>] free_accounted_pages+0x47/0x4c [<ffffffff81047f90>] free_task+0x31/0x5c [<ffffffff8104807d>] __put_task_struct+0xc2/0xdb [<ffffffff8104dfc7>] put_task_struct+0x1e/0x22 [<ffffffff8104e144>] delayed_put_task_struct+0x7a/0x98 [<ffffffff810cf0e5>] __rcu_process_callbacks+0x269/0x3df [<ffffffff810cf28c>] rcu_process_callbacks+0x31/0x5b [<ffffffff8105266d>] __do_softirq+0x122/0x277 This usage pattern could not be triggered before kmem came into play. With the introduction of kmem stack handling, it is possible that we call the last mem_cgroup_put() from the task destructor, which is run in an rcu callback. Such callbacks are run with softirqs disabled, leading to the offensive usage pattern. In general, we have little, if any, means to guarantee in which context the last memcg_put will happen. The best we can do is test it and try to make sure no invalid context releases are happening. But as we add more code to memcg, the possible interactions grow in number and expose more ways to get context conflicts. One thing to keep in mind, is that part of the freeing process is already deferred to a worker, such as vfree(), that can only be called from process context. For the moment, the only two functions we really need moved away are: * free_css_id(), and * mem_cgroup_remove_from_trees(). But because the later accesses per-zone info, free_mem_cgroup_per_zone_info() needs to be moved as well. With that, we are left with the per_cpu stats only. Better move it all. Signed-off-by: Glauber Costa <glommer@pa…
creator: Glauber Costa
date: 2012-10-08T10:06:18-00:00

[PATCH v4 13/14] protect architectures where THREAD_SIZE &gt;= PAGE_SIZE against fork bombs
type: item
description: Because those architectures will draw their stacks directly from the page allocator, rather than the slab cache, we can directly pass __GFP_KMEMCG flag, and issue the corresponding free_pages. This code path is taken when the architecture doesn't define CONFIG_ARCH_THREAD_INFO_ALLOCATOR (only ia64 seems to), and has THREAD_SIZE >= PAGE_SIZE. Luckily, most - if not all - of the remaining architectures fall in this category. This will guarantee that every stack page is accounted to the memcg the process currently lives on, and will have the allocations to fail if they go over limit. For the time being, I am defining a new variant of THREADINFO_GFP, not to mess with the other path. Once the slab is also tracked by memcg, we can get rid of that flag. Tested to successfully protect against :(){ :|:& };: Signed-off-by: Glauber Costa <glommer@parallels.com> Acked-by: Frederic Weisbecker <fweisbec@redhat.com> Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Michal Hocko <mhocko@suse.cz> CC: Christoph Lameter <cl@linux.com> CC: Pekka Enberg <penberg@cs.helsinki.fi> CC: Johannes Weiner <hannes@cmpxchg.org> CC: Suleiman Souhlal <suleiman@google.com> --- include/linux/thread_info.h | 2 ++ kernel/fork.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index ccc1899..e7e0473 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -61,6 +61,8 @@ extern long do_no_restart_syscall(struct restart_block *parm); # define THREADINFO_GFP (GFP_KERNEL | __GFP_NOTRACK) #endif +#define THREADINFO_GFP_ACCOUNTED (THREADINFO_GFP | __GFP_KMEMCG) + /* * flag set/clear/test wrappers * - pass TIF_xxxx constants to these functions diff --git a/kernel/fork.c b/kernel/fork.c index 03b86f1..b3f6298 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -146,7 +146,7 @@ void __weak arch_release_thread_info(struct thread_info *ti) static struct thread_info *alloc_thread_info_node(stru…
creator: Glauber Costa
date: 2012-10-08T10:06:19-00:00

[PATCH v4 14/14] Add documentation about the kmem controller
type: item
description: Signed-off-by: Glauber Costa <glommer@parallels.com> --- Documentation/cgroups/memory.txt | 55 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt index c07f7b4..9b08548 100644 --- a/Documentation/cgroups/memory.txt +++ b/Documentation/cgroups/memory.txt @@ -71,6 +71,11 @@ Brief summary of control files. memory.oom_control # set/show oom controls. memory.numa_stat # show the number of memory usage per numa node + memory.kmem.limit_in_bytes # set/show hard limit for kernel memory + memory.kmem.usage_in_bytes # show current kernel memory allocation + memory.kmem.failcnt # show the number of kernel memory usage hits limits + memory.kmem.max_usage_in_bytes # show max kernel memory usage recorded + memory.kmem.tcp.limit_in_bytes # set/show hard limit for tcp buf memory memory.kmem.tcp.usage_in_bytes # show current tcp buf memory allocation memory.kmem.tcp.failcnt # show the number of tcp buf memory usage hits limits @@ -268,20 +273,62 @@ the amount of kernel memory used by the system. Kernel memory is fundamentally different than user memory, since it can't be swapped out, which makes it possible to DoS the system by consuming too much of this precious resource. +Kernel memory won't be accounted at all until it is limited. This allows for +existing setups to continue working without disruption. Note that it is +possible to account it without an effective limit by setting the limits +to a very high number (like RESOURCE_MAX -1page). The limit cannot be set +if the cgroup have children, or if there are already tasks in the cgroup. + +After a controller is first limited, it will be kept being accounted until it +is removed. The memory limitation itself, can of course be removed by writing +-1 to memory.kmem.limit_in_bytes + Kernel memory limits are not imposed for the root cgroup. Usage for the root -cgroup may or may not be accounted. +cgroup may or may not…
creator: Glauber Costa
date: 2012-10-08T10:06:20-00:00

Re: [PATCH v4 05/14] Add a __GFP_KMEMCG flag
type: item
description: On Mon 08-10-12 14:06:11, Glauber Costa wrote: > This flag is used to indicate to the callees that this allocation is a > kernel allocation in process context, and should be accounted to > current's memcg. It takes numerical place of the of the recently removed > __GFP_NO_KSWAPD. > > [ v4: make flag unconditional, also declare it in trace code ] > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Christoph Lameter <cl@linux.com> > CC: Pekka Enberg <penberg@cs.helsinki.fi> > CC: Michal Hocko <mhocko@suse.cz> > CC: Suleiman Souhlal <suleiman@google.com> > Acked-by: Johannes Weiner <hannes@cmpxchg.org> > Acked-by: Rik van Riel <riel@redhat.com> > Acked-by: Mel Gorman <mel@csn.ul.ie> > Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Michal Hocko <mhocko@suse.cz> > --- > include/linux/gfp.h | 3 ++- > include/trace/events/gfpflags.h | 1 + > 2 files changed, 3 insertions(+), 1 deletion(-) > > diff --git a/include/linux/gfp.h b/include/linux/gfp.h > index 02c1c97..9289d46 100644 > --- a/include/linux/gfp.h > +++ b/include/linux/gfp.h > @@ -31,6 +31,7 @@ struct vm_area_struct; > #define ___GFP_THISNODE 0x40000u > #define ___GFP_RECLAIMABLE 0x80000u > #define ___GFP_NOTRACK 0x200000u > +#define ___GFP_KMEMCG 0x400000u > #define ___GFP_OTHER_NODE 0x800000u > #define ___GFP_WRITE 0x1000000u > > @@ -87,7 +88,7 @@ struct vm_area_struct; > > #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */ > #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */ > - > +#define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */ > /* > * This may seem redundant, but it's a way of annotating false positives vs. > * allocations that simply cannot be supported (e.g. page tables). > diff --git a/include/trace/events/gfpflags.h b/include/trace/events/gfpflags.h > index 9391706..730df12 100644 > --- a/include/trace/events/gfpflags.h > +++ b/include/tra…
creator: Michal Hocko
date: 2012-10-09T15:04:03-00:00

Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: On Mon 08-10-12 14:06:14, Glauber Costa wrote: [...] > diff --git a/kernel/res_counter.c b/kernel/res_counter.c > index ad581aa..7b3d6dc 100644 > --- a/kernel/res_counter.c > +++ b/kernel/res_counter.c > @@ -86,33 +86,39 @@ int res_counter_charge_nofail(struct res_counter *counter, unsigned long val, > return __res_counter_charge(counter, val, limit_fail_at, true); > } > > -void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val) > +u64 res_counter_uncharge_locked(struct res_counter *counter, unsigned long val) > { > if (WARN_ON(counter->usage < val)) > val = counter->usage; > > counter->usage -= val; > + return counter->usage; > } > > -void res_counter_uncharge_until(struct res_counter *counter, > - struct res_counter *top, > - unsigned long val) > +u64 res_counter_uncharge_until(struct res_counter *counter, > + struct res_counter *top, > + unsigned long val) > { > unsigned long flags; > struct res_counter *c; > + u64 ret = 0; > > local_irq_save(flags); > for (c = counter; c != top; c = c->parent) { > + u64 r; > spin_lock(&c->lock); > - res_counter_uncharge_locked(c, val); > + r = res_counter_uncharge_locked(c, val); > + if (c == counter) > + ret = r; > spin_unlock(&c->lock); > } > local_irq_restore(flags); > + return ret; As I have already mentioned in my previous feedback this is cetainly not atomic as you the lock protects only one group in the hierarchy. How is the return value from this function supposed to be used? -- Michal Hocko SUSE Labs
creator: Michal Hocko
date: 2012-10-09T15:08:45-00:00

Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: On 10/09/2012 07:08 PM, Michal Hocko wrote: > As I have already mentioned in my previous feedback this is cetainly not > atomic as you the lock protects only one group in the hierarchy. How is > the return value from this function supposed to be used? So, I tried to make that clearer in the updated changelog. Only the value of the base memcg (the one passed to the function) is returned, and it is atomic, in the sense that it has the same semantics as the atomic variables: If 2 threads uncharge 4k each from a 8 k counter, a subsequent read can return 0 for both. The return value here will guarantee that only one sees the drop to 0. This is used in the patch "kmem_accounting lifecycle management" to be sure that only one process will call mem_cgroup_put() in the memcg structure.
creator: Glauber Costa
date: 2012-10-09T15:14:57-00:00

Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: On Tue 09-10-12 19:14:57, Glauber Costa wrote: > On 10/09/2012 07:08 PM, Michal Hocko wrote: > > As I have already mentioned in my previous feedback this is cetainly not > > atomic as you the lock protects only one group in the hierarchy. How is > > the return value from this function supposed to be used? > > So, I tried to make that clearer in the updated changelog. > > Only the value of the base memcg (the one passed to the function) is > returned, and it is atomic, in the sense that it has the same semantics > as the atomic variables: If 2 threads uncharge 4k each from a 8 k > counter, a subsequent read can return 0 for both. The return value here > will guarantee that only one sees the drop to 0. > > This is used in the patch "kmem_accounting lifecycle management" to be > sure that only one process will call mem_cgroup_put() in the memcg > structure. Yes, you are using res_counter_uncharge and its semantic makes sense. I was refering to res_counter_uncharge_until (you removed that context from my reply) because that one can race resulting that nobody sees 0 even though that parents get down to 0 as a result: A | B / \ C(x) D(y) D and C uncharge everything. CPU0 CPU1 ret += uncharge(D) [0] ret += uncharge(C) [0] ret += uncharge(B) [x-from C] ret += uncharge(B) [0] ret += uncharge(A) [y-from D] ret += uncharge(A) [0] ret == x ret == y -- Michal Hocko SUSE Labs
creator: Michal Hocko
date: 2012-10-09T15:35:06-00:00

Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: On 10/09/2012 07:35 PM, Michal Hocko wrote: > On Tue 09-10-12 19:14:57, Glauber Costa wrote: >> On 10/09/2012 07:08 PM, Michal Hocko wrote: >>> As I have already mentioned in my previous feedback this is cetainly not >>> atomic as you the lock protects only one group in the hierarchy. How is >>> the return value from this function supposed to be used? >> >> So, I tried to make that clearer in the updated changelog. >> >> Only the value of the base memcg (the one passed to the function) is >> returned, and it is atomic, in the sense that it has the same semantics >> as the atomic variables: If 2 threads uncharge 4k each from a 8 k >> counter, a subsequent read can return 0 for both. The return value here >> will guarantee that only one sees the drop to 0. >> >> This is used in the patch "kmem_accounting lifecycle management" to be >> sure that only one process will call mem_cgroup_put() in the memcg >> structure. > > Yes, you are using res_counter_uncharge and its semantic makes sense. > I was refering to res_counter_uncharge_until (you removed that context > from my reply) because that one can race resulting that nobody sees 0 > even though that parents get down to 0 as a result: > A > | > B > / \ > C(x) D(y) > > D and C uncharge everything. > > CPU0 CPU1 > ret += uncharge(D) [0] ret += uncharge(C) [0] > ret += uncharge(B) [x-from C] > ret += uncharge(B) [0] > ret += uncharge(A) [y-from D] > ret += uncharge(A) [0] > > ret == x ret == y > Sorry Michal, I didn't realize you were talking about res_counter_uncharge_until. I don't really need res_counter_uncharge_until to return anything, so I can just remove that if you prefer, keeping just the main res_counter_uncharge. However, I still can't make sense of your concern. The return value will return the value of the counter passed as a parameter to the function: r = res_counter_uncharge_locked(c, val); if (c == counter) ret = r; So when you call res_counter_uncharge_until(D, whatever, x), you will see zero here as a res…
creator: Glauber Costa
date: 2012-10-10T09:03:39-00:00

Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: On Wed 10-10-12 13:03:39, Glauber Costa wrote: > On 10/09/2012 07:35 PM, Michal Hocko wrote: > > On Tue 09-10-12 19:14:57, Glauber Costa wrote: > >> On 10/09/2012 07:08 PM, Michal Hocko wrote: > >>> As I have already mentioned in my previous feedback this is cetainly not > >>> atomic as you the lock protects only one group in the hierarchy. How is > >>> the return value from this function supposed to be used? > >> > >> So, I tried to make that clearer in the updated changelog. > >> > >> Only the value of the base memcg (the one passed to the function) is > >> returned, and it is atomic, in the sense that it has the same semantics > >> as the atomic variables: If 2 threads uncharge 4k each from a 8 k > >> counter, a subsequent read can return 0 for both. The return value here > >> will guarantee that only one sees the drop to 0. > >> > >> This is used in the patch "kmem_accounting lifecycle management" to be > >> sure that only one process will call mem_cgroup_put() in the memcg > >> structure. > > > > Yes, you are using res_counter_uncharge and its semantic makes sense. > > I was refering to res_counter_uncharge_until (you removed that context > > from my reply) because that one can race resulting that nobody sees 0 > > even though that parents get down to 0 as a result: > > A > > | > > B > > / \ > > C(x) D(y) > > > > D and C uncharge everything. > > > > CPU0 CPU1 > > ret += uncharge(D) [0] ret += uncharge(C) [0] > > ret += uncharge(B) [x-from C] > > ret += uncharge(B) [0] > > ret += uncharge(A) [y-from D] > > ret += uncharge(A) [0] > > > > ret == x ret == y > > > > Sorry Michal, I didn't realize you were talking about > res_counter_uncharge_until. I could have been more specific. > I don't really need res_counter_uncharge_until to return anything, so I > can just remove that if you prefer, keeping just the main > res_counter_uncharge. > > However, I still can't make sense of your concern. > > The return value will return the value of the counter passed as a > param…
creator: Michal Hocko
date: 2012-10-10T11:24:47-00:00

Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: On Mon 08-10-12 14:06:14, Glauber Costa wrote: > It is useful to know how many charges are still left after a call to > res_counter_uncharge. While it is possible to issue a res_counter_read > after uncharge, this can be racy. > > If we need, for instance, to take some action when the counters drop > down to 0, only one of the callers should see it. This is the same > semantics as the atomic variables in the kernel. > > Since the current return value is void, we don't need to worry about > anything breaking due to this change: nobody relied on that, and only > users appearing from now on will be checking this value. > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Michal Hocko <mhocko@suse.cz> > CC: Johannes Weiner <hannes@cmpxchg.org> > CC: Suleiman Souhlal <suleiman@google.com> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Reviewed-by: Michal Hocko <mhocko@suse.cz> > --- > Documentation/cgroups/resource_counter.txt | 7 ++++--- > include/linux/res_counter.h | 12 +++++++----- > kernel/res_counter.c | 20 +++++++++++++------- > 3 files changed, 24 insertions(+), 15 deletions(-) > > diff --git a/Documentation/cgroups/resource_counter.txt b/Documentation/cgroups/resource_counter.txt > index 0c4a344..c4d99ed 100644 > --- a/Documentation/cgroups/resource_counter.txt > +++ b/Documentation/cgroups/resource_counter.txt > @@ -83,16 +83,17 @@ to work with it. > res_counter->lock internally (it must be called with res_counter->lock > held). The force parameter indicates whether we can bypass the limit. > > - e. void res_counter_uncharge[_locked] > + e. u64 res_counter_uncharge[_locked] > (struct res_counter *rc, unsigned long val) > > When a resource is released (freed) it should be de-accounted > from the resource counter it was accounted to. This is called > - "uncharging". > + "uncharging". The return value of this function indicate the amount > + of charges still present in the counter. > > The _locked routines imply that the res_counter->lock is ta…
creator: Michal Hocko
date: 2012-10-10T11:25:49-00:00

Re: [PATCH v4 04/14] kmem accounting basic infrastructure
type: item
description: On Mon 08-10-12 14:06:10, Glauber Costa wrote: > This patch adds the basic infrastructure for the accounting of the slab > caches. To control that, the following files are created: > > * memory.kmem.usage_in_bytes > * memory.kmem.limit_in_bytes > * memory.kmem.failcnt > * memory.kmem.max_usage_in_bytes > > They have the same meaning of their user memory counterparts. They > reflect the state of the "kmem" res_counter. > > Per cgroup slab memory accounting is not enabled until a limit is set s/slab/kmem/ right? > for the group. Once the limit is set the accounting cannot be disabled > for that group. This means that after the patch is applied, no > behavioral changes exists for whoever is still using memcg to control > their memory usage, until memory.kmem.limit_in_bytes is set for the > first time. > > We always account to both user and kernel resource_counters. This > effectively means that an independent kernel limit is in place when the > limit is set to a lower value than the user memory. A equal or higher > value means that the user limit will always hit first, meaning that kmem > is effectively unlimited. > > People who want to track kernel memory but not limit it, can set this > limit to a very high number (like RESOURCE_MAX - 1page - that no one > will ever hit, or equal to the user memory) > > [ v4: make kmem files part of the main array; > do not allow limit to be set for non-empty cgroups ] > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Michal Hocko <mhocko@suse.cz> > CC: Johannes Weiner <hannes@cmpxchg.org> > Acked-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > --- > mm/memcontrol.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 122 insertions(+), 1 deletion(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 71d259e..ba855cc 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c [...] > @@ -332,6 +337,26 @@ struct mem_cgroup { > #endif > }; > > +/* internal only representation about t…
creator: Michal Hocko
date: 2012-10-11T10:11:19-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On Mon 08-10-12 14:06:12, Glauber Costa wrote: > This patch introduces infrastructure for tracking kernel memory pages to > a given memcg. This will happen whenever the caller includes the flag > __GFP_KMEMCG flag, and the task belong to a memcg other than the root. > > In memcontrol.h those functions are wrapped in inline acessors. The > idea is to later on, patch those with static branches, so we don't incur > any overhead when no mem cgroups with limited kmem are being used. > > Users of this functionality shall interact with the memcg core code > through the following functions: > > memcg_kmem_newpage_charge: will return true if the group can handle the > allocation. At this point, struct page is not > yet allocated. > > memcg_kmem_commit_charge: will either revert the charge, if struct page > allocation failed, or embed memcg information > into page_cgroup. > > memcg_kmem_uncharge_page: called at free time, will revert the charge. > > [ v2: improved comments and standardized function names ] > [ v3: handle no longer opaque, functions not exported, > even more comments ] > [ v4: reworked Used bit handling and surroundings for more clarity ] > [ v5: simplified code for kmemcg compiled out and core functions in > memcontrol.c, moved kmem code to the middle to avoid forward decls ] > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Christoph Lameter <cl@linux.com> > CC: Pekka Enberg <penberg@cs.helsinki.fi> > CC: Michal Hocko <mhocko@suse.cz> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > CC: Johannes Weiner <hannes@cmpxchg.org> > --- > include/linux/memcontrol.h | 95 +++++++++++++++++++++++++ > mm/memcontrol.c | 173 +++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 263 insertions(+), 5 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 8d9489f..783cd78 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -21,6 +21,7 @@ > #define _LINUX_MEMCONTROL_H > #inc…
creator: Michal Hocko
date: 2012-10-11T12:42:12-00:00

Re: [PATCH v4 04/14] kmem accounting basic infrastructure
type: item
description: On Thu 11-10-12 12:11:19, Michal Hocko wrote: > On Mon 08-10-12 14:06:10, Glauber Costa wrote: [...] > > +static void memcg_kmem_set_active(struct mem_cgroup *memcg) > > +{ > > + set_bit(KMEM_ACCOUNTED_ACTIVE, &memcg->kmem_accounted); > > +} > > + > > +static bool memcg_kmem_is_accounted(struct mem_cgroup *memcg) > > +{ > > + return test_bit(KMEM_ACCOUNTED_ACTIVE, &memcg->kmem_accounted); > > +} > > +#endif > > set_active vs. is_accounted. Is there any reason for inconsistency here? Ahh, fixed later and 09/14 makes it memcg_kmem_is_active so this is just a code churn. I think making it memcg_kmem_is_active here would be better. -- Michal Hocko SUSE Labs
creator: Michal Hocko
date: 2012-10-11T12:53:10-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On Thu 11-10-12 14:42:12, Michal Hocko wrote: [...] > /* > * Keep reference on memcg while the page is charged to prevent > * group from vanishing because allocation can outlive their > * tasks. The reference is dropped in __memcg_kmem_uncharge_page > */ > > please > > + mem_cgroup_get(memcg); Ahh, this will go away. The it doesn't make much sense to add the comment here. -- Michal Hocko SUSE Labs
creator: Michal Hocko
date: 2012-10-11T12:56:03-00:00

Re: [PATCH v4 09/14] memcg: kmem accounting lifecycle management
type: item
description: On Mon 08-10-12 14:06:15, Glauber Costa wrote: > Because kmem charges can outlive the cgroup, we need to make sure that > we won't free the memcg structure while charges are still in flight. > For reviewing simplicity, the charge functions will issue > mem_cgroup_get() at every charge, and mem_cgroup_put() at every > uncharge. > > This can get expensive, however, and we can do better. mem_cgroup_get() > only really needs to be issued once: when the first limit is set. In the > same spirit, we only need to issue mem_cgroup_put() when the last charge > is gone. > > We'll need an extra bit in kmem_accounted for that: KMEM_ACCOUNTED_DEAD. > it will be set when the cgroup dies, if there are charges in the group. > If there aren't, we can proceed right away. > > Our uncharge function will have to test that bit every time the charges > drop to 0. Because that is not the likely output of > res_counter_uncharge, this should not impose a big hit on us: it is > certainly much better than a reference count decrease at every > operation. > > [ v3: merged all lifecycle related patches in one ] > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > CC: Christoph Lameter <cl@linux.com> > CC: Pekka Enberg <penberg@cs.helsinki.fi> > CC: Michal Hocko <mhocko@suse.cz> > CC: Johannes Weiner <hannes@cmpxchg.org> > CC: Suleiman Souhlal <suleiman@google.com> OK, I like the optimization. I have just one comment to the memcg_kmem_dead naming but other than that Acked-by: Michal Hocko <mhocko@suse.cz> [...] > +static bool memcg_kmem_dead(struct mem_cgroup *memcg) The name is tricky because it doesn't tell you that it clears the flag which made me scratch my head when reading comment in kmem_cgroup_destroy > +{ > + return test_and_clear_bit(KMEM_ACCOUNTED_DEAD, &memcg->kmem_accounted); > +} > #endif > > /* Stuffs for move charges at task migration. */ [...] > @@ -4876,6 +4904,20 @@ static int memcg_init_kmem(struct mem_cgroup *memcg,…
creator: Michal Hocko
date: 2012-10-11T13:11:43-00:00

Re: [PATCH v4 04/14] kmem accounting basic infrastructure
type: item
description: On Thu 11-10-12 12:11:19, Michal Hocko wrote: > On Mon 08-10-12 14:06:10, Glauber Costa wrote: > > + cgroup_lock(); > > + mutex_lock(&set_limit_mutex); > > + if (!memcg->kmem_accounted && val != RESOURCE_MAX) { > > Just a nit but wouldn't memcg_kmem_is_accounted(memcg) be better than > directly checking kmem_accounted? OK, I see that jump lable patch changes this and we set activated inside the conditional so kmem_accounted check catches both flags. That could be changed to memcg_kmem_is_activated in that patch but what ever. -- Michal Hocko SUSE Labs
creator: Michal Hocko
date: 2012-10-11T13:38:56-00:00

Re: [PATCH v4 10/14] memcg: use static branches when code not in use
type: item
description: 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 <glommer@parallels.com> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > CC: Christoph Lameter <cl@linux.com> > CC: Pekka Enberg <penberg@cs.helsinki.fi> > CC: Michal Hocko <mhocko@suse.cz> > CC: Johannes Weiner <hannes@cmpxchg.org> > CC: Suleiman Souhlal <suleiman@google.com> Looks reasonable to me Acked-by: Michal Hocko <mhocko@suse.cz> 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 pa…
creator: Michal Hocko
date: 2012-10-11T13:40:28-00:00

Re: [PATCH v4 12/14] execute the whole memcg freeing in free_worker
type: item
description: On Mon 08-10-12 14:06:18, Glauber Costa wrote: > A lot of the initialization we do in mem_cgroup_create() is done with > softirqs enabled. This include grabbing a css id, which holds > &ss->id_lock->rlock, and the per-zone trees, which holds > rtpz->lock->rlock. All of those signal to the lockdep mechanism that > those locks can be used in SOFTIRQ-ON-W context. This means that the > freeing of memcg structure must happen in a compatible context, > otherwise we'll get a deadlock, like the one bellow, caught by lockdep: > > [<ffffffff81103095>] free_accounted_pages+0x47/0x4c > [<ffffffff81047f90>] free_task+0x31/0x5c > [<ffffffff8104807d>] __put_task_struct+0xc2/0xdb > [<ffffffff8104dfc7>] put_task_struct+0x1e/0x22 > [<ffffffff8104e144>] delayed_put_task_struct+0x7a/0x98 > [<ffffffff810cf0e5>] __rcu_process_callbacks+0x269/0x3df > [<ffffffff810cf28c>] rcu_process_callbacks+0x31/0x5b > [<ffffffff8105266d>] __do_softirq+0x122/0x277 > > This usage pattern could not be triggered before kmem came into play. > With the introduction of kmem stack handling, it is possible that we > call the last mem_cgroup_put() from the task destructor, which is run in > an rcu callback. Such callbacks are run with softirqs disabled, leading > to the offensive usage pattern. > > In general, we have little, if any, means to guarantee in which context > the last memcg_put will happen. The best we can do is test it and try to > make sure no invalid context releases are happening. But as we add more > code to memcg, the possible interactions grow in number and expose more > ways to get context conflicts. One thing to keep in mind, is that part > of the freeing process is already deferred to a worker, such as vfree(), > that can only be called from process context. > > For the moment, the only two functions we really need moved away are: > > * free_css_id(), and > * mem_cgroup_remove_from_trees(). > > But because the later accesses per-zone info, > free_mem_cgroup_per_zone_info() needs to be move…
creator: Michal Hocko
date: 2012-10-11T14:21:27-00:00

Re: [PATCH v4 14/14] Add documentation about the kmem controller
type: item
description: On Mon 08-10-12 14:06:20, Glauber Costa wrote: > Signed-off-by: Glauber Costa <glommer@parallels.com> > --- > Documentation/cgroups/memory.txt | 55 +++++++++++++++++++++++++++++++++++++++- > 1 file changed, 54 insertions(+), 1 deletion(-) > > diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt > index c07f7b4..9b08548 100644 > --- a/Documentation/cgroups/memory.txt > +++ b/Documentation/cgroups/memory.txt > @@ -71,6 +71,11 @@ Brief summary of control files. > memory.oom_control # set/show oom controls. > memory.numa_stat # show the number of memory usage per numa node > > + memory.kmem.limit_in_bytes # set/show hard limit for kernel memory > + memory.kmem.usage_in_bytes # show current kernel memory allocation > + memory.kmem.failcnt # show the number of kernel memory usage hits limits > + memory.kmem.max_usage_in_bytes # show max kernel memory usage recorded > + > memory.kmem.tcp.limit_in_bytes # set/show hard limit for tcp buf memory > memory.kmem.tcp.usage_in_bytes # show current tcp buf memory allocation > memory.kmem.tcp.failcnt # show the number of tcp buf memory usage hits limits > @@ -268,20 +273,62 @@ the amount of kernel memory used by the system. Kernel memory is fundamentally > different than user memory, since it can't be swapped out, which makes it > possible to DoS the system by consuming too much of this precious resource. > > +Kernel memory won't be accounted at all until it is limited. This allows for until limit on a group is set. > +existing setups to continue working without disruption. Note that it is > +possible to account it without an effective limit by setting the limits > +to a very high number (like RESOURCE_MAX -1page). I have brought that up in an earlier patch already. Why not just do echo -1 (which translates to RESOURCE_MAX internally) and be done with that. RESOURCE_MAX-1 sounds quite inconvenient. > The limit cannot be set > +if the cgroup have children, or if there are already tasks in the cgroup. I wou…
creator: Michal Hocko
date: 2012-10-11T14:35:59-00:00

Re: [PATCH v4 04/14] kmem accounting basic infrastructure
type: item
description: On 10/11/2012 02:11 PM, Michal Hocko wrote: > On Mon 08-10-12 14:06:10, Glauber Costa wrote: >> This patch adds the basic infrastructure for the accounting of the slab >> caches. To control that, the following files are created: >> >> * memory.kmem.usage_in_bytes >> * memory.kmem.limit_in_bytes >> * memory.kmem.failcnt >> * memory.kmem.max_usage_in_bytes >> >> They have the same meaning of their user memory counterparts. They >> reflect the state of the "kmem" res_counter. >> >> Per cgroup slab memory accounting is not enabled until a limit is set > > s/slab/kmem/ right? > right. >> +static int memcg_update_kmem_limit(struct cgroup *cont, u64 val) >> +{ >> + int ret = -EINVAL; >> +#ifdef CONFIG_MEMCG_KMEM >> + struct mem_cgroup *memcg = mem_cgroup_from_cont(cont); >> + /* >> + * For simplicity, we won't allow this to be disabled. It also can't >> + * be changed if the cgroup has children already, or if tasks had >> + * already joined. >> + * >> + * If tasks join before we set the limit, a person looking at >> + * kmem.usage_in_bytes will have no way to determine when it took >> + * place, which makes the value quite meaningless. >> + * >> + * After it first became limited, changes in the value of the limit are >> + * of course permitted. >> + * >> + * Taking the cgroup_lock is really offensive, but it is so far the only >> + * way to guarantee that no children will appear. There are plenty of >> + * other offenders, and they should all go away. Fine grained locking >> + * is probably the way to go here. When we are fully hierarchical, we >> + * can also get rid of the use_hierarchy check. >> + */ >> + cgroup_lock(); >> + mutex_lock(&set_limit_mutex); >> + if (!memcg->kmem_accounted && val != RESOURCE_MAX) { > > Just a nit but wouldn't memcg_kmem_is_accounted(memcg) be better than > directly checking kmem_accounted? > Besides that I am not sure I fully understand RESOURCE_MAX test. Say I > want to have kmem accounting for monitoring so I do > echo -1 > memory.kmem.li…
creator: Glauber Costa
date: 2012-10-12T07:36:38-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On 10/11/2012 04:42 PM, Michal Hocko wrote: > On Mon 08-10-12 14:06:12, Glauber Costa wrote: >> This patch introduces infrastructure for tracking kernel memory pages to >> a given memcg. This will happen whenever the caller includes the flag >> __GFP_KMEMCG flag, and the task belong to a memcg other than the root. >> >> In memcontrol.h those functions are wrapped in inline acessors. The >> idea is to later on, patch those with static branches, so we don't incur >> any overhead when no mem cgroups with limited kmem are being used. >> >> Users of this functionality shall interact with the memcg core code >> through the following functions: >> >> memcg_kmem_newpage_charge: will return true if the group can handle the >> allocation. At this point, struct page is not >> yet allocated. >> >> memcg_kmem_commit_charge: will either revert the charge, if struct page >> allocation failed, or embed memcg information >> into page_cgroup. >> >> memcg_kmem_uncharge_page: called at free time, will revert the charge. >> >> [ v2: improved comments and standardized function names ] >> [ v3: handle no longer opaque, functions not exported, >> even more comments ] >> [ v4: reworked Used bit handling and surroundings for more clarity ] >> [ v5: simplified code for kmemcg compiled out and core functions in >> memcontrol.c, moved kmem code to the middle to avoid forward decls ] >> >> Signed-off-by: Glauber Costa <glommer@parallels.com> >> CC: Christoph Lameter <cl@linux.com> >> CC: Pekka Enberg <penberg@cs.helsinki.fi> >> CC: Michal Hocko <mhocko@suse.cz> >> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> >> CC: Johannes Weiner <hannes@cmpxchg.org> >> --- >> include/linux/memcontrol.h | 95 +++++++++++++++++++++++++ >> mm/memcontrol.c | 173 +++++++++++++++++++++++++++++++++++++++++++-- >> 2 files changed, 263 insertions(+), 5 deletions(-) >> > > Just a nit. Hmm we are far from being consisten in using vs. not using > externs in header files for function declarations but I do not see …
creator: Glauber Costa
date: 2012-10-12T07:45:46-00:00

Re: [PATCH v4 09/14] memcg: kmem accounting lifecycle management
type: item
description: On 10/11/2012 05:11 PM, Michal Hocko wrote: > On Mon 08-10-12 14:06:15, Glauber Costa wrote: >> Because kmem charges can outlive the cgroup, we need to make sure that >> we won't free the memcg structure while charges are still in flight. >> For reviewing simplicity, the charge functions will issue >> mem_cgroup_get() at every charge, and mem_cgroup_put() at every >> uncharge. >> >> This can get expensive, however, and we can do better. mem_cgroup_get() >> only really needs to be issued once: when the first limit is set. In the >> same spirit, we only need to issue mem_cgroup_put() when the last charge >> is gone. >> >> We'll need an extra bit in kmem_accounted for that: KMEM_ACCOUNTED_DEAD. >> it will be set when the cgroup dies, if there are charges in the group. >> If there aren't, we can proceed right away. >> >> Our uncharge function will have to test that bit every time the charges >> drop to 0. Because that is not the likely output of >> res_counter_uncharge, this should not impose a big hit on us: it is >> certainly much better than a reference count decrease at every >> operation. >> >> [ v3: merged all lifecycle related patches in one ] >> >> Signed-off-by: Glauber Costa <glommer@parallels.com> >> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> >> CC: Christoph Lameter <cl@linux.com> >> CC: Pekka Enberg <penberg@cs.helsinki.fi> >> CC: Michal Hocko <mhocko@suse.cz> >> CC: Johannes Weiner <hannes@cmpxchg.org> >> CC: Suleiman Souhlal <suleiman@google.com> > > OK, I like the optimization. I have just one comment to the > memcg_kmem_dead naming but other than that > > Acked-by: Michal Hocko <mhocko@suse.cz> > > [...] >> +static bool memcg_kmem_dead(struct mem_cgroup *memcg) > > The name is tricky because it doesn't tell you that it clears the flag > which made me scratch my head when reading comment in kmem_cgroup_destroy > memcg_kmem_finally_kill_that_bastard() ?
creator: Glauber Costa
date: 2012-10-12T07:47:17-00:00

Re: [PATCH v4 10/14] memcg: use static branches when code not in use
type: item
description: On 10/11/2012 05:40 PM, Michal Hocko wrote: > 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 <glommer@parallels.com> >> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> >> CC: Christoph Lameter <cl@linux.com> >> CC: Pekka Enberg <penberg@cs.helsinki.fi> >> CC: Michal Hocko <mhocko@suse.cz> >> CC: Johannes Weiner <hannes@cmpxchg.org> >> CC: Suleiman Souhlal <suleiman@google.com> > > Looks reasonable to me > Acked-by: Michal Hocko <mhocko@suse.cz> > > 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_…
creator: Glauber Costa
date: 2012-10-12T07:47:53-00:00

Re: [PATCH v4 14/14] Add documentation about the kmem controller
type: item
description: On 10/11/2012 06:35 PM, Michal Hocko wrote: > On Mon 08-10-12 14:06:20, Glauber Costa wrote: >> Signed-off-by: Glauber Costa <glommer@parallels.com> >> --- >> Documentation/cgroups/memory.txt | 55 +++++++++++++++++++++++++++++++++++++++- >> 1 file changed, 54 insertions(+), 1 deletion(-) >> >> diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt >> index c07f7b4..9b08548 100644 >> --- a/Documentation/cgroups/memory.txt >> +++ b/Documentation/cgroups/memory.txt >> @@ -71,6 +71,11 @@ Brief summary of control files. >> memory.oom_control # set/show oom controls. >> memory.numa_stat # show the number of memory usage per numa node >> >> + memory.kmem.limit_in_bytes # set/show hard limit for kernel memory >> + memory.kmem.usage_in_bytes # show current kernel memory allocation >> + memory.kmem.failcnt # show the number of kernel memory usage hits limits >> + memory.kmem.max_usage_in_bytes # show max kernel memory usage recorded >> + >> memory.kmem.tcp.limit_in_bytes # set/show hard limit for tcp buf memory >> memory.kmem.tcp.usage_in_bytes # show current tcp buf memory allocation >> memory.kmem.tcp.failcnt # show the number of tcp buf memory usage hits limits >> @@ -268,20 +273,62 @@ the amount of kernel memory used by the system. Kernel memory is fundamentally >> different than user memory, since it can't be swapped out, which makes it >> possible to DoS the system by consuming too much of this precious resource. >> >> +Kernel memory won't be accounted at all until it is limited. This allows for > > until limit on a group is set. > ok. >> +existing setups to continue working without disruption. Note that it is >> +possible to account it without an effective limit by setting the limits >> +to a very high number (like RESOURCE_MAX -1page). > > I have brought that up in an earlier patch already. Why not just do echo > -1 (which translates to RESOURCE_MAX internally) and be done with that. > RESOURCE_MAX-1 sounds quite inconvenient. > For the case …
creator: Glauber Costa
date: 2012-10-12T07:53:23-00:00

Re: [PATCH v4 04/14] kmem accounting basic infrastructure
type: item
description: On Fri 12-10-12 11:36:38, Glauber Costa wrote: > On 10/11/2012 02:11 PM, Michal Hocko wrote: > > On Mon 08-10-12 14:06:10, Glauber Costa wrote: [...] > >> + if (!memcg->kmem_accounted && val != RESOURCE_MAX) { > > > > Just a nit but wouldn't memcg_kmem_is_accounted(memcg) be better than > > directly checking kmem_accounted? > > Besides that I am not sure I fully understand RESOURCE_MAX test. Say I > > want to have kmem accounting for monitoring so I do > > echo -1 > memory.kmem.limit_in_bytes > > > > so you set the value but do not activate it. Isn't this just a reminder > > from the time when the accounting could be deactivated? > > > > No, not at all. > > I see you have talked about that in other e-mails, (I was on sick leave > yesterday), so let me consolidate it all here: > > What we discussed before, regarding to echo -1 > ... was around the > disable code, something that we no longer allow. So now, if you will > echo -1 to that file *after* it is limited, you get in track only mode. > > But for you to start that, you absolutely have to write something > different than -1. > > Just one example: libcgroup, regardless of how lame we think it is in > this regard, will write to all cgroup files by default when a file is > updated. If you haven't written anything, it will still write the same > value that the file had before. Ohh, I wasn't aware of that and it sounds pretty lame. > This means that an already deployed libcg-managed installation will > suddenly enable kmem for every cgroup. Sure this can be fixed in > userspace, but: > > 1) There is no reason to break it, if we can You are right > 2) It is perfectly reasonable to expect that if you write to a file the > same value that was already there, nothing happens. Fair enough -- Michal Hocko SUSE Labs
creator: Michal Hocko
date: 2012-10-12T08:27:28-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On Fri 12-10-12 11:45:46, Glauber Costa wrote: > On 10/11/2012 04:42 PM, Michal Hocko wrote: > > On Mon 08-10-12 14:06:12, Glauber Costa wrote: [...] > >> + /* > >> + * Conditions under which we can wait for the oom_killer. > >> + * __GFP_NORETRY should be masked by __mem_cgroup_try_charge, > >> + * but there is no harm in being explicit here > >> + */ > >> + may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); > > > > Well we _have to_ check __GFP_NORETRY here because if we don't then we > > can end up in OOM. mem_cgroup_do_charge returns CHARGE_NOMEM for > > __GFP_NORETRY (without doing any reclaim) and of oom==true we decrement > > oom retries counter and eventually hit OOM killer. So the comment is > > misleading. > > I will update. What i understood from your last message is that we don't > really need to, because try_charge will do it. IIRC I just said it couldn't happen before because migration doesn't go through charge and thp disable oom by default. > >> + > >> + _memcg = memcg; > >> + ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, > >> + &_memcg, may_oom); > >> + > >> + if (!ret) { > >> + ret = res_counter_charge(&memcg->kmem, size, &fail_res); > > > > Now that I'm thinking about the charging ordering we should charge the > > kmem first because we would like to hit kmem limit before we hit u+k > > limit, don't we. > > Say that you have kmem limit 10M and the total limit 50M. Current `u' > > would be 40M and this charge would cause kmem to hit the `k' limit. I > > think we should fail to charge kmem before we go to u+k and potentially > > reclaim/oom. > > Or has this been alredy discussed and I just do not remember? > > > This has never been discussed as far as I remember. We charged u first > since day0, and you are so far the first one to raise it... > > One of the things in favor of charging 'u' first is that > mem_cgroup_try_charge is already equipped to make a lot of decisions, > like when to allow reclaim, when to bypass charges, and …
creator: Michal Hocko
date: 2012-10-12T08:39:45-00:00

Re: [PATCH v4 09/14] memcg: kmem accounting lifecycle management
type: item
description: On Fri 12-10-12 11:47:17, Glauber Costa wrote: > On 10/11/2012 05:11 PM, Michal Hocko wrote: > > On Mon 08-10-12 14:06:15, Glauber Costa wrote: > >> Because kmem charges can outlive the cgroup, we need to make sure that > >> we won't free the memcg structure while charges are still in flight. > >> For reviewing simplicity, the charge functions will issue > >> mem_cgroup_get() at every charge, and mem_cgroup_put() at every > >> uncharge. > >> > >> This can get expensive, however, and we can do better. mem_cgroup_get() > >> only really needs to be issued once: when the first limit is set. In the > >> same spirit, we only need to issue mem_cgroup_put() when the last charge > >> is gone. > >> > >> We'll need an extra bit in kmem_accounted for that: KMEM_ACCOUNTED_DEAD. > >> it will be set when the cgroup dies, if there are charges in the group. > >> If there aren't, we can proceed right away. > >> > >> Our uncharge function will have to test that bit every time the charges > >> drop to 0. Because that is not the likely output of > >> res_counter_uncharge, this should not impose a big hit on us: it is > >> certainly much better than a reference count decrease at every > >> operation. > >> > >> [ v3: merged all lifecycle related patches in one ] > >> > >> Signed-off-by: Glauber Costa <glommer@parallels.com> > >> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > >> CC: Christoph Lameter <cl@linux.com> > >> CC: Pekka Enberg <penberg@cs.helsinki.fi> > >> CC: Michal Hocko <mhocko@suse.cz> > >> CC: Johannes Weiner <hannes@cmpxchg.org> > >> CC: Suleiman Souhlal <suleiman@google.com> > > > > OK, I like the optimization. I have just one comment to the > > memcg_kmem_dead naming but other than that > > > > Acked-by: Michal Hocko <mhocko@suse.cz> > > > > [...] > >> +static bool memcg_kmem_dead(struct mem_cgroup *memcg) > > > > The name is tricky because it doesn't tell you that it clears the flag > > which made me scratch my head when reading comment in kmem_cgroup_destroy >…
creator: Michal Hocko
date: 2012-10-12T08:41:01-00:00

Re: [PATCH v4 14/14] Add documentation about the kmem controller
type: item
description: On Fri 12-10-12 11:53:23, Glauber Costa wrote: > On 10/11/2012 06:35 PM, Michal Hocko wrote: > > On Mon 08-10-12 14:06:20, Glauber Costa wrote: [...] > >> Kernel memory limits are not imposed for the root cgroup. Usage for the root > >> -cgroup may or may not be accounted. > >> +cgroup may or may not be accounted. The memory used is accumulated into > >> +memory.kmem.usage_in_bytes, or in a separate counter when it makes sense. > > > > Which separate counter? Is this about tcp kmem? > > > > So far, yes, this is the only case that makes sense, and the fewer the > better. In any case it exists, and I wanted to be generic. Add (currently tcp) or something similar [...] > >> + Kernel memory is effectively set as a percentage of the user memory. This > > > > not a percentage it is subset of the user memory > > > Well, this is semantics. I can change, but for me it makes a lot of > sense to think of it in terms of a percentage, because it is easy to > administer. You don't actually write a percentage, which I tried to > clarify by using the term "effective set as a percentage". I can still see somebody reading this and wondering why echo 50 > ...limit didn't set a percentage... -- Michal Hocko SUSE Labs
creator: Michal Hocko
date: 2012-10-12T08:44:32-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On 10/12/2012 12:39 PM, Michal Hocko wrote: > On Fri 12-10-12 11:45:46, Glauber Costa wrote: >> On 10/11/2012 04:42 PM, Michal Hocko wrote: >>> On Mon 08-10-12 14:06:12, Glauber Costa wrote: > [...] >>>> + /* >>>> + * Conditions under which we can wait for the oom_killer. >>>> + * __GFP_NORETRY should be masked by __mem_cgroup_try_charge, >>>> + * but there is no harm in being explicit here >>>> + */ >>>> + may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); >>> >>> Well we _have to_ check __GFP_NORETRY here because if we don't then we >>> can end up in OOM. mem_cgroup_do_charge returns CHARGE_NOMEM for >>> __GFP_NORETRY (without doing any reclaim) and of oom==true we decrement >>> oom retries counter and eventually hit OOM killer. So the comment is >>> misleading. >> >> I will update. What i understood from your last message is that we don't >> really need to, because try_charge will do it. > > IIRC I just said it couldn't happen before because migration doesn't go > through charge and thp disable oom by default. > I had it changed to: /* * Conditions under which we can wait for the oom_killer. * We have to be able to wait, but also, if we can't retry, * we obviously shouldn't go mess with oom. */ may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); >>>> + >>>> + _memcg = memcg; >>>> + ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, >>>> + &_memcg, may_oom); >>>> + >>>> + if (!ret) { >>>> + ret = res_counter_charge(&memcg->kmem, size, &fail_res); >>> >>> Now that I'm thinking about the charging ordering we should charge the >>> kmem first because we would like to hit kmem limit before we hit u+k >>> limit, don't we. >>> Say that you have kmem limit 10M and the total limit 50M. Current `u' >>> would be 40M and this charge would cause kmem to hit the `k' limit. I >>> think we should fail to charge kmem before we go to u+k and potentially >>> reclaim/oom. >>> Or has this been alredy discussed and I just do not remember? >>> >> This has never been d…
creator: Glauber Costa
date: 2012-10-12T08:44:57-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On Fri 12-10-12 12:44:57, Glauber Costa wrote: > On 10/12/2012 12:39 PM, Michal Hocko wrote: > > On Fri 12-10-12 11:45:46, Glauber Costa wrote: > >> On 10/11/2012 04:42 PM, Michal Hocko wrote: > >>> On Mon 08-10-12 14:06:12, Glauber Costa wrote: > > [...] > >>>> + /* > >>>> + * Conditions under which we can wait for the oom_killer. > >>>> + * __GFP_NORETRY should be masked by __mem_cgroup_try_charge, > >>>> + * but there is no harm in being explicit here > >>>> + */ > >>>> + may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); > >>> > >>> Well we _have to_ check __GFP_NORETRY here because if we don't then we > >>> can end up in OOM. mem_cgroup_do_charge returns CHARGE_NOMEM for > >>> __GFP_NORETRY (without doing any reclaim) and of oom==true we decrement > >>> oom retries counter and eventually hit OOM killer. So the comment is > >>> misleading. > >> > >> I will update. What i understood from your last message is that we don't > >> really need to, because try_charge will do it. > > > > IIRC I just said it couldn't happen before because migration doesn't go > > through charge and thp disable oom by default. > > > > I had it changed to: > > /* > * Conditions under which we can wait for the oom_killer. > * We have to be able to wait, but also, if we can't retry, > * we obviously shouldn't go mess with oom. > */ > may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); OK > > >>>> + > >>>> + _memcg = memcg; > >>>> + ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, > >>>> + &_memcg, may_oom); > >>>> + > >>>> + if (!ret) { > >>>> + ret = res_counter_charge(&memcg->kmem, size, &fail_res); > >>> > >>> Now that I'm thinking about the charging ordering we should charge the > >>> kmem first because we would like to hit kmem limit before we hit u+k > >>> limit, don't we. > >>> Say that you have kmem limit 10M and the total limit 50M. Current `u' > >>> would be 40M and this charge would cause kmem to hit the `k' limit. I > >>> think we should fail to charge kmem b…
creator: Michal Hocko
date: 2012-10-12T08:57:40-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On 10/12/2012 12:57 PM, Michal Hocko wrote: > On Fri 12-10-12 12:44:57, Glauber Costa wrote: >> On 10/12/2012 12:39 PM, Michal Hocko wrote: >>> On Fri 12-10-12 11:45:46, Glauber Costa wrote: >>>> On 10/11/2012 04:42 PM, Michal Hocko wrote: >>>>> On Mon 08-10-12 14:06:12, Glauber Costa wrote: >>> [...] >>>>>> + /* >>>>>> + * Conditions under which we can wait for the oom_killer. >>>>>> + * __GFP_NORETRY should be masked by __mem_cgroup_try_charge, >>>>>> + * but there is no harm in being explicit here >>>>>> + */ >>>>>> + may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); >>>>> >>>>> Well we _have to_ check __GFP_NORETRY here because if we don't then we >>>>> can end up in OOM. mem_cgroup_do_charge returns CHARGE_NOMEM for >>>>> __GFP_NORETRY (without doing any reclaim) and of oom==true we decrement >>>>> oom retries counter and eventually hit OOM killer. So the comment is >>>>> misleading. >>>> >>>> I will update. What i understood from your last message is that we don't >>>> really need to, because try_charge will do it. >>> >>> IIRC I just said it couldn't happen before because migration doesn't go >>> through charge and thp disable oom by default. >>> >> >> I had it changed to: >> >> /* >> * Conditions under which we can wait for the oom_killer. >> * We have to be able to wait, but also, if we can't retry, >> * we obviously shouldn't go mess with oom. >> */ >> may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); > > OK > >> >>>>>> + >>>>>> + _memcg = memcg; >>>>>> + ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, >>>>>> + &_memcg, may_oom); >>>>>> + >>>>>> + if (!ret) { >>>>>> + ret = res_counter_charge(&memcg->kmem, size, &fail_res); >>>>> >>>>> Now that I'm thinking about the charging ordering we should charge the >>>>> kmem first because we would like to hit kmem limit before we hit u+k >>>>> limit, don't we. >>>>> Say that you have kmem limit 10M and the total limit 50M. Current `u' >>>>> would be 40M and this charge would cause kmem to h…
creator: Glauber Costa
date: 2012-10-12T09:13:04-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: On Fri 12-10-12 13:13:04, Glauber Costa wrote: [...] > Just so we don't ping-pong in another submission: > > I changed memcontrol.h's memcg_kmem_newpage_charge to include: > > /* If the test is dying, just let it go. */ > if (unlikely(test_thread_flag(TIF_MEMDIE) > || fatal_signal_pending(current))) > return true; OK > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c32aaaf..72cf189 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > +static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size) > +{ > + struct res_counter *fail_res; > + struct mem_cgroup *_memcg; > + int ret = 0; > + bool may_oom; > + > + ret = res_counter_charge(&memcg->kmem, size, &fail_res); > + if (ret) > + return ret; > + > + /* > + * Conditions under which we can wait for the oom_killer. > + * We have to be able to wait, but also, if we can't retry, > + * we obviously shouldn't go mess with oom. > + */ > + may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); > + > + _memcg = memcg; > + ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, > + &_memcg, may_oom); > + > + if (ret == -EINTR) { > + /* > + * __mem_cgroup_try_charge() chosed to bypass to root due to > + * OOM kill or fatal signal. Since our only options are to > + * either fail the allocation or charge it to this cgroup, do > + * it as a temporary condition. But we can't fail. From a > + * kmem/slab perspective, the cache has already been selected, > + * by mem_cgroup_get_kmem_cache(), so it is too late to change > + * our minds. This condition will only trigger if the task > + * entered memcg_charge_kmem in a sane state, but was > + * OOM-killed. during __mem_cgroup_try_charge. Tasks that are > + * already dying when the allocation triggers should have been > + * already directed to the root cgroup. > + */ > + res_counter_charge_nofail(&memcg->res, size, &fail_res); > + if (do_swap_account) > + res_counter_charge_nofail(&memcg->memsw, size, > + &fail_res); > + ret = 0; > + } else if (ret) > + res…
creator: Michal Hocko
date: 2012-10-12T09:47:26-00:00

Re: [PATCH v4 02/14] memcg: Reclaim when more than one page needed.
type: item
description: (2012/10/08 19:06), Glauber Costa wrote: > From: Suleiman Souhlal <ssouhlal@FreeBSD.org> > > mem_cgroup_do_charge() was written before kmem accounting, and expects > three cases: being called for 1 page, being called for a stock of 32 > pages, or being called for a hugepage. If we call for 2 or 3 pages (and > both the stack and several slabs used in process creation are such, at > least with the debug options I had), it assumed it's being called for > stock and just retried without reclaiming. > > Fix that by passing down a minsize argument in addition to the csize. > > And what to do about that (csize == PAGE_SIZE && ret) retry? If it's > needed at all (and presumably is since it's there, perhaps to handle > races), then it should be extended to more than PAGE_SIZE, yet how far? > And should there be a retry count limit, of what? For now retry up to > COSTLY_ORDER (as page_alloc.c does) and make sure not to do it if > __GFP_NORETRY. > > [v4: fixed nr pages calculation pointed out by Christoph Lameter ] > > Signed-off-by: Suleiman Souhlal <suleiman@google.com> > Signed-off-by: Glauber Costa <glommer@parallels.com> > Reviewed-by: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > Acked-by: Michal Hocko <mhocko@suse.cz> > Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
creator: KAMEZAWA Hiroyuki
date: 2012-10-16T03:22:34-00:00

Re: [PATCH v4 06/14] memcg: kmem controller infrastructure
type: item
description: (2012/10/12 18:13), Glauber Costa wrote: > On 10/12/2012 12:57 PM, Michal Hocko wrote: >> On Fri 12-10-12 12:44:57, Glauber Costa wrote: >>> On 10/12/2012 12:39 PM, Michal Hocko wrote: >>>> On Fri 12-10-12 11:45:46, Glauber Costa wrote: >>>>> On 10/11/2012 04:42 PM, Michal Hocko wrote: >>>>>> On Mon 08-10-12 14:06:12, Glauber Costa wrote: >>>> [...] >>>>>>> + /* >>>>>>> + * Conditions under which we can wait for the oom_killer. >>>>>>> + * __GFP_NORETRY should be masked by __mem_cgroup_try_charge, >>>>>>> + * but there is no harm in being explicit here >>>>>>> + */ >>>>>>> + may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); >>>>>> >>>>>> Well we _have to_ check __GFP_NORETRY here because if we don't then we >>>>>> can end up in OOM. mem_cgroup_do_charge returns CHARGE_NOMEM for >>>>>> __GFP_NORETRY (without doing any reclaim) and of oom==true we decrement >>>>>> oom retries counter and eventually hit OOM killer. So the comment is >>>>>> misleading. >>>>> >>>>> I will update. What i understood from your last message is that we don't >>>>> really need to, because try_charge will do it. >>>> >>>> IIRC I just said it couldn't happen before because migration doesn't go >>>> through charge and thp disable oom by default. >>>> >>> >>> I had it changed to: >>> >>> /* >>> * Conditions under which we can wait for the oom_killer. >>> * We have to be able to wait, but also, if we can't retry, >>> * we obviously shouldn't go mess with oom. >>> */ >>> may_oom = (gfp & __GFP_WAIT) && !(gfp & __GFP_NORETRY); >> >> OK >> >>> >>>>>>> + >>>>>>> + _memcg = memcg; >>>>>>> + ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, >>>>>>> + &_memcg, may_oom); >>>>>>> + >>>>>>> + if (!ret) { >>>>>>> + ret = res_counter_charge(&memcg->kmem, size, &fail_res); >>>>>> >>>>>> Now that I'm thinking about the charging ordering we should charge the >>>>>> kmem first because we would like to hit kmem limit before we hit u+k >>>>>> limit, don't we. >>>>>> Say that you have kmem limit 10M …
creator: KAMEZAWA Hiroyuki
date: 2012-10-16T08:00:03-00:00

Re: [PATCH v4 08/14] res_counter: return amount of charges after res_counter_uncharge
type: item
description: (2012/10/08 19:06), Glauber Costa wrote: > It is useful to know how many charges are still left after a call to > res_counter_uncharge. While it is possible to issue a res_counter_read > after uncharge, this can be racy. > > If we need, for instance, to take some action when the counters drop > down to 0, only one of the callers should see it. This is the same > semantics as the atomic variables in the kernel. > > Since the current return value is void, we don't need to worry about > anything breaking due to this change: nobody relied on that, and only > users appearing from now on will be checking this value. > > Signed-off-by: Glauber Costa <glommer@parallels.com> > CC: Michal Hocko <mhocko@suse.cz> > CC: Johannes Weiner <hannes@cmpxchg.org> > CC: Suleiman Souhlal <suleiman@google.com> > CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> > --- > Documentation/cgroups/resource_counter.txt | 7 ++++--- > include/linux/res_counter.h | 12 +++++++----- > kernel/res_counter.c | 20 +++++++++++++------- > 3 files changed, 24 insertions(+), 15 deletions(-) Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
creator: KAMEZAWA Hiroyuki
date: 2012-10-16T08:20:34-00:00

Re: [PATCH v4 09/14] memcg: kmem accounting lifecycle management
type: item
description: (2012/10/12 17:41), Michal Hocko wrote: > On Fri 12-10-12 11:47:17, Glauber Costa wrote: >> On 10/11/2012 05:11 PM, Michal Hocko wrote: >>> On Mon 08-10-12 14:06:15, Glauber Costa wrote: >>>> Because kmem charges can outlive the cgroup, we need to make sure that >>>> we won't free the memcg structure while charges are still in flight. >>>> For reviewing simplicity, the charge functions will issue >>>> mem_cgroup_get() at every charge, and mem_cgroup_put() at every >>>> uncharge. >>>> >>>> This can get expensive, however, and we can do better. mem_cgroup_get() >>>> only really needs to be issued once: when the first limit is set. In the >>>> same spirit, we only need to issue mem_cgroup_put() when the last charge >>>> is gone. >>>> >>>> We'll need an extra bit in kmem_accounted for that: KMEM_ACCOUNTED_DEAD. >>>> it will be set when the cgroup dies, if there are charges in the group. >>>> If there aren't, we can proceed right away. >>>> >>>> Our uncharge function will have to test that bit every time the charges >>>> drop to 0. Because that is not the likely output of >>>> res_counter_uncharge, this should not impose a big hit on us: it is >>>> certainly much better than a reference count decrease at every >>>> operation. >>>> >>>> [ v3: merged all lifecycle related patches in one ] >>>> >>>> Signed-off-by: Glauber Costa <glommer@parallels.com> >>>> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> >>>> CC: Christoph Lameter <cl@linux.com> >>>> CC: Pekka Enberg <penberg@cs.helsinki.fi> >>>> CC: Michal Hocko <mhocko@suse.cz> >>>> CC: Johannes Weiner <hannes@cmpxchg.org> >>>> CC: Suleiman Souhlal <suleiman@google.com> >>> >>> OK, I like the optimization. I have just one comment to the >>> memcg_kmem_dead naming but other than that >>> >>> Acked-by: Michal Hocko <mhocko@suse.cz> >>> >>> [...] >>>> +static bool memcg_kmem_dead(struct mem_cgroup *memcg) >>> >>> The name is tricky because it doesn't tell you that it clears the flag >>> which made me scratch my head wh…
creator: KAMEZAWA Hiroyuki
date: 2012-10-16T08:41:32-00:00

Re: [PATCH v4 10/14] memcg: use static branches when code not in use
type: item
description: (2012/10/12 16:47), Glauber Costa wrote: > On 10/11/2012 05:40 PM, Michal Hocko wrote: >> 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 <glommer@parallels.com> >>> CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> >>> CC: Christoph Lameter <cl@linux.com> >>> CC: Pekka Enberg <penberg@cs.helsinki.fi> >>> CC: Michal Hocko <mhocko@suse.cz> >>> CC: Johannes Weiner <hannes@cmpxchg.org> >>> CC: Suleiman Souhlal <suleiman@google.com> >> >> Looks reasonable to me >> Acked-by: Michal Hocko <mhocko@suse.cz> >> >> 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, /* de…
creator: KAMEZAWA Hiroyuki
date: 2012-10-16T08:48:29-00:00

Re: [PATCH v4 14/14] Add documentation about the kmem controller
type: item
description: (2012/10/08 19:06), Glauber Costa wrote: > Signed-off-by: Glauber Costa <glommer@parallels.com> > --- > Documentation/cgroups/memory.txt | 55 +++++++++++++++++++++++++++++++++++++++- > 1 file changed, 54 insertions(+), 1 deletion(-) > Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
creator: KAMEZAWA Hiroyuki
date: 2012-10-17T07:29:50-00:00