OpenVZ Forum - RDF feed
type: channel
items: [PATCH v5 00/10] per-cgroup tcp memory pressure
items: [PATCH v5 01/10] Basic kernel memory functionality for the Memory Controller
items: [PATCH v5 02/10] foundations of per-cgroup memory pressure controlling.
items: [PATCH v5 03/10] socket: initial cgroup code.
items: [PATCH v5 04/10] per-cgroup tcp buffers control
items: [PATCH v5 05/10] per-netns ipv4 sysctl_tcp_mem
items: [PATCH v5 06/10] tcp buffer limitation: per-cgroup limit
items: [PATCH v5 07/10] Display current tcp memory allocation in kmem cgroup
items: [PATCH v5 08/10] Display current tcp memory allocation in kmem cgroup
items: [PATCH v5 09/10] Display current tcp memory allocation in kmem cgroup
items: [PATCH v5 10/10] Disable task moving when using kernel memory accounting
items: RE: [PATCH v5 04/10] per-cgroup tcp buffers control
items: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
items: Re: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure

[PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: Hi all, This is my new attempt at implementing per-cgroup tcp memory pressure. I am particularly interested in what the network folks have to comment on it: my main goal is to achieve the least impact possible in the network code. Here's a brief description of my approach: When only the root cgroup is present, the code should behave the same way as before - with the exception of the inclusion of an extra field in struct sock, and one in struct proto. All tests are patched out with static branch, and we still access addresses directly - the same as we did before. When a cgroup other than root is created, we patch in the branches, and account resources for that cgroup. The variables in the root cgroup are still updated. If we were to try to be 100 % coherent with the memcg code, that should depend on use_hierarchy. However, I feel that this is a good compromise in terms of leaving the network code untouched, and still having a global vision of its resources. I also do not compute max_usage for the root cgroup, for a similar reason. Please let me know what you think of it. Glauber Costa (10): Basic kernel memory functionality for the Memory Controller foundations of per-cgroup memory pressure controlling. socket: initial cgroup code. per-cgroup tcp buffers control per-netns ipv4 sysctl_tcp_mem tcp buffer limitation: per-cgroup limit Display current tcp memory allocation in kmem cgroup Display current tcp memory allocation in kmem cgroup Display current tcp memory allocation in kmem cgroup Disable task moving when using kernel memory accounting Documentation/cgroups/memory.txt | 38 +++- include/linux/memcontrol.h | 40 ++++ include/net/netns/ipv4.h | 1 + include/net/sock.h | 231 +++++++++++++++++++- include/net/tcp.h | 22 ++- include/net/transp_v6.h | 1 + init/Kconfig | 14 ++ mm/memcontrol.c | 442 ++++++++++++++++++++++++++++++++++++- net/core/sock.c | 121 ++++++++--- net/ipv4/af_inet.c | 5 + net/ipv4/proc.c | 7 +- net/ipv4/sysctl_net_ipv4.c | 65 +++++- net/ipv4/tcp.c | …
creator: Glauber Costa
date: 2011-11-07T15:26:25-00:00

[PATCH v5 01/10] Basic kernel memory functionality for the Memory Controller
type: item
description: This patch lays down the foundation for the kernel memory component of the Memory Controller. As of today, I am only laying down the following files: * memory.independent_kmem_limit * memory.kmem.limit_in_bytes (currently ignored) * memory.kmem.usage_in_bytes (always zero) Signed-off-by: Glauber Costa <glommer@parallels.com> Reviewed-by: Kirill A. Shutemov <kirill@shutemov.name> CC: Paul Menage <paul@paulmenage.org> CC: Greg Thelen <gthelen@google.com> --- Documentation/cgroups/memory.txt | 36 ++++++++++++- init/Kconfig | 14 +++++ mm/memcontrol.c | 104 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 147 insertions(+), 7 deletions(-) diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt index 06eb6d9..bf00cd2 100644 --- a/Documentation/cgroups/memory.txt +++ b/Documentation/cgroups/memory.txt @@ -44,8 +44,9 @@ Features: - oom-killer disable knob and oom-notifier - Root cgroup has no limit controls. - Kernel memory and Hugepages are not under control yet. We just manage - pages on LRU. To add more controls, we have to take care of performance. + Hugepages is not under control yet. We just manage pages on LRU. To add more + controls, we have to take care of performance. Kernel memory support is work + in progress, and the current version provides basically functionality. Brief summary of control files. @@ -56,8 +57,11 @@ Brief summary of control files. (See 5.5 for details) memory.memsw.usage_in_bytes # show current res_counter usage for memory+Swap (See 5.5 for details) + memory.kmem.usage_in_bytes # show current res_counter usage for kmem only. + (See 2.7 for details) memory.limit_in_bytes # set/show limit of memory usage memory.memsw.limit_in_bytes # set/show limit of memory+Swap usage + memory.kmem.limit_in_bytes # if allowed, set/show limit of kernel memory memory.failcnt # show the number of memory usage hits limits memory.memsw.failcnt # show the number of memory+Swap hits limits memory.max_usage_in_bytes # show max memory usag…
creator: Glauber Costa
date: 2011-11-07T15:26:26-00:00

[PATCH v5 02/10] foundations of per-cgroup memory pressure controlling.
type: item
description: This patch replaces all uses of struct sock fields' memory_pressure, memory_allocated, sockets_allocated, and sysctl_mem to acessor macros. Those macros can either receive a socket argument, or a mem_cgroup argument, depending on the context they live in. Since we're only doing a macro wrapping here, no performance impact at all is expected in the case where we don't have cgroups disabled. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: David S. Miller <davem@davemloft.net> CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com> CC: Eric W. Biederman <ebiederm@xmission.com> CC: Eric Dumazet <eric.dumazet@gmail.com> --- include/linux/memcontrol.h | 4 ++ include/net/sock.h | 86 ++++++++++++++++++++++++++++++++++++++----- include/net/tcp.h | 3 +- net/core/sock.c | 55 +++++++++++++++++----------- net/ipv4/proc.c | 7 ++-- net/ipv4/tcp_input.c | 12 +++--- net/ipv4/tcp_ipv4.c | 4 +- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- 10 files changed, 130 insertions(+), 47 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index ac797fa..e9ff93a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -362,6 +362,10 @@ static inline void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx) { } +static inline struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) +{ + return NULL; +} #endif /* CONFIG_CGROUP_MEM_CONT */ #if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM) diff --git a/include/net/sock.h b/include/net/sock.h index c6658be..8959dcc 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -54,6 +54,7 @@ #include <linux/security.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/cgroup.h> #include <linux/filter.h> #include <linux/rculist_nulls.h> @@ -168,6 +169,8 @@ struct sock_common { /* public: */ }; +struct mem_cgroup; + /** * struct sock - network layer representation of sockets * @__sk_common: shared …
creator: Glauber Costa
date: 2011-11-07T15:26:27-00:00

[PATCH v5 03/10] socket: initial cgroup code.
type: item
description: The goal of this work is to move the memory pressure tcp controls to a cgroup, instead of just relying on global conditions. To avoid excessive overhead in the network fast paths, the code that accounts allocated memory to a cgroup is hidden inside a static_branch(). This branch is patched out until the first non-root cgroup is created. So when nobody is using cgroups, even if it is mounted, no significant performance penalty should be seen. This patch handles the generic part of the code, and has nothing tcp-specific. Signed-off-by: Glauber Costa <glommer@parallels.com> Acked-by: Kirill A. Shutemov<kirill@shutemov.name> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujtsu.com> CC: David S. Miller <davem@davemloft.net> CC: Eric W. Biederman <ebiederm@xmission.com> CC: Eric Dumazet <eric.dumazet@gmail.com> --- include/linux/memcontrol.h | 27 ++++++++ include/net/sock.h | 151 +++++++++++++++++++++++++++++++++++++++++++- mm/memcontrol.c | 85 +++++++++++++++++++++++-- net/core/sock.c | 36 ++++++++--- 4 files changed, 281 insertions(+), 18 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e9ff93a..994a06a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -381,5 +381,32 @@ mem_cgroup_print_bad_page(struct page *page) } #endif +#ifdef CONFIG_INET +enum { + UNDER_LIMIT, + SOFT_LIMIT, + OVER_LIMIT, +}; + +struct sock; +struct cg_proto; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +void sock_update_memcg(struct sock *sk); +void memcg_sockets_allocated_dec(struct mem_cgroup *memcg, + struct cg_proto *prot); +void memcg_sockets_allocated_inc(struct mem_cgroup *memcg, + struct cg_proto *prot); +void memcg_memory_allocated_add(struct mem_cgroup *memcg, struct cg_proto *prot, + unsigned long amt, int *parent_status); +void memcg_memory_allocated_sub(struct mem_cgroup *memcg, struct cg_proto *prot, + unsigned long amt); +u64 memcg_memory_allocated_read(struct mem_cgroup *memcg, + struct cg_proto *prot); +#else +static …
creator: Glauber Costa
date: 2011-11-07T15:26:28-00:00

[PATCH v5 04/10] per-cgroup tcp buffers control
type: item
description: With all the infrastructure in place, this patch implements per-cgroup control for tcp memory pressure handling. A resource conter is used to control allocated memory, except for the root cgroup, that will keep using global counters. This patch is the one that actually enables/disables the jump labels controlling cgroup. To this point, they were always disabled. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujtisu.com> CC: David S. Miller <davem@davemloft.net> CC: Eric W. Biederman <ebiederm@xmission.com> CC: Eric Dumazet <eric.dumazet@gmail.com> --- include/net/tcp.h | 18 +++++++ include/net/transp_v6.h | 1 + mm/memcontrol.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++- net/core/sock.c | 46 +++++++++++++++-- net/ipv4/af_inet.c | 3 + net/ipv4/tcp_ipv4.c | 12 +++++ net/ipv6/af_inet6.c | 3 + net/ipv6/tcp_ipv6.c | 10 ++++ 8 files changed, 211 insertions(+), 7 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index ccaa3b6..7301ca8 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -253,6 +253,22 @@ extern int sysctl_tcp_cookie_size; extern int sysctl_tcp_thin_linear_timeouts; extern int sysctl_tcp_thin_dupack; +struct tcp_memcontrol { + /* per-cgroup tcp memory pressure knobs */ + struct res_counter tcp_memory_allocated; + struct percpu_counter tcp_sockets_allocated; + /* those two are read-mostly, leave them at the end */ + long tcp_prot_mem[3]; + int tcp_memory_pressure; +}; + +long *sysctl_mem_tcp(struct mem_cgroup *memcg); +struct percpu_counter *sockets_allocated_tcp(struct mem_cgroup *memcg); +int *memory_pressure_tcp(struct mem_cgroup *memcg); +struct res_counter *memory_allocated_tcp(struct mem_cgroup *memcg); +int tcp_init_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss); +void tcp_destroy_cgroup(struct cgroup *cgrp, struct cgroup_subsys *ss); + extern atomic_long_t tcp_memory_allocated; extern struct percpu_counter tcp_sockets_allocated; extern int tcp_memory_pressure; @@ -305…
creator: Glauber Costa
date: 2011-11-07T15:26:29-00:00

[PATCH v5 05/10] per-netns ipv4 sysctl_tcp_mem
type: item
description: This patch allows each namespace to independently set up its levels for tcp memory pressure thresholds. This patch alone does not buy much: we need to make this values per group of process somehow. This is achieved in the patches that follows in this patchset. Signed-off-by: Glauber Costa <glommer@parallels.com> Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> CC: David S. Miller <davem@davemloft.net> CC: Eric W. Biederman <ebiederm@xmission.com> --- include/net/netns/ipv4.h | 1 + include/net/tcp.h | 1 - mm/memcontrol.c | 8 ++++-- net/ipv4/af_inet.c | 2 + net/ipv4/sysctl_net_ipv4.c | 51 +++++++++++++++++++++++++++++++++++++------ net/ipv4/tcp.c | 11 +------- net/ipv4/tcp_ipv4.c | 1 - net/ipv6/af_inet6.c | 2 + net/ipv6/tcp_ipv6.c | 1 - 9 files changed, 56 insertions(+), 22 deletions(-) diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index d786b4f..bbd023a 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -55,6 +55,7 @@ struct netns_ipv4 { int current_rt_cache_rebuild_count; unsigned int sysctl_ping_group_range[2]; + long sysctl_tcp_mem[3]; atomic_t rt_genid; atomic_t dev_addr_genid; diff --git a/include/net/tcp.h b/include/net/tcp.h index 7301ca8..c34b823 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -230,7 +230,6 @@ extern int sysctl_tcp_fack; extern int sysctl_tcp_reordering; extern int sysctl_tcp_ecn; extern int sysctl_tcp_dsack; -extern long sysctl_tcp_mem[3]; extern int sysctl_tcp_wmem[3]; extern int sysctl_tcp_rmem[3]; extern int sysctl_tcp_app_win; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f14d7d2..63360f8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -395,6 +395,7 @@ static inline bool mem_cgroup_is_root(struct mem_cgroup *mem) #ifdef CONFIG_INET #include <net/sock.h> #include <net/ip.h> +#include <linux/nsproxy.h> void sock_update_memcg(struct sock *sk) { @@ -526,14 +527,15 @@ static void tcp_create_cgroup(struct mem_cgroup *cg, struct cgroup_subsys *ss) int tcp_init_cgroup(…
creator: Glauber Costa
date: 2011-11-07T15:26:30-00:00

[PATCH v5 06/10] tcp buffer limitation: per-cgroup limit
type: item
description: This patch uses the "tcp.limit_in_bytes" field of the kmem_cgroup to effectively control the amount of kernel memory pinned by a cgroup. This value is ignored in the root cgroup, and in all others, caps the value specified by the admin in the net namespaces' view of tcp_sysctl_mem. If namespaces are being used, the admin is allowed to set a value bigger than cgroup's maximum, the same way it is allowed to set pretty much unlimited values in a real box. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: David S. Miller <davem@davemloft.net> CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com> CC: Eric W. Biederman <ebiederm@xmission.com> --- Documentation/cgroups/memory.txt | 1 + include/linux/memcontrol.h | 9 ++++ mm/memcontrol.c | 76 +++++++++++++++++++++++++++++++++++++- net/ipv4/sysctl_net_ipv4.c | 14 +++++++ 4 files changed, 99 insertions(+), 1 deletions(-) diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt index bf00cd2..c1db134 100644 --- a/Documentation/cgroups/memory.txt +++ b/Documentation/cgroups/memory.txt @@ -78,6 +78,7 @@ Brief summary of control files. memory.independent_kmem_limit # select whether or not kernel memory limits are independent of user limits + memory.kmem.tcp.limit_in_bytes # set/show hard limit for tcp buf memory 1. History diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 994a06a..d025979 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -402,10 +402,19 @@ void memcg_memory_allocated_sub(struct mem_cgroup *memcg, struct cg_proto *prot, unsigned long amt); u64 memcg_memory_allocated_read(struct mem_cgroup *memcg, struct cg_proto *prot); +unsigned long long tcp_max_memory(const struct mem_cgroup *memcg); +void tcp_prot_mem(struct mem_cgroup *memcg, long val, int idx); #else static inline void sock_update_memcg(struct sock *sk) { } +static inline unsigned long long tcp_max_memory(const struct mem_cgroup *memcg) +{ + return 0; +} +static inline void t…
creator: Glauber Costa
date: 2011-11-07T15:26:31-00:00

[PATCH v5 07/10] Display current tcp memory allocation in kmem cgroup
type: item
description: This patch introduces kmem.tcp.usage_in_bytes file, living in the kmem_cgroup filesystem. It is a simple read-only file that displays the amount of kernel memory currently consumed by the cgroup. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: David S. Miller <davem@davemloft.net> CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com> CC: Eric W. Biederman <ebiederm@xmission.com> --- Documentation/cgroups/memory.txt | 1 + mm/memcontrol.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Documentation/cgroups/memory.txt b/Documentation/cgroups/memory.txt index c1db134..00f1a88 100644 --- a/Documentation/cgroups/memory.txt +++ b/Documentation/cgroups/memory.txt @@ -79,6 +79,7 @@ Brief summary of control files. memory.independent_kmem_limit # select whether or not kernel memory limits are independent of user limits 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 1. History diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ee122a6..51b5a55 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -528,6 +528,11 @@ static struct cftype tcp_files[] = { .read_u64 = mem_cgroup_read, .private = MEMFILE_PRIVATE(_KMEM_TCP, RES_LIMIT), }, + { + .name = "kmem.tcp.usage_in_bytes", + .read_u64 = mem_cgroup_read, + .private = MEMFILE_PRIVATE(_KMEM_TCP, RES_USAGE), + }, }; static void tcp_create_cgroup(struct mem_cgroup *cg, struct cgroup_subsys *ss) @@ -4126,9 +4131,12 @@ static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft) #if defined(CONFIG_CGROUP_MEM_RES_CTLR_KMEM) && defined(CONFIG_INET) case _KMEM_TCP: /* Be explicit: tcp root does not have a res_counter */ - if (mem_cgroup_is_root(mem)) - val = RESOURCE_MAX; - else + if (mem_cgroup_is_root(mem)) { + if (name == RES_USAGE) + val = atomic_long_read(&tcp_memory_allocated) << PAGE_SHIFT; + else + val = RESOURCE_MAX; + } else val = res_counter_read_u64(&mem->tcp.tcp_memory_alloc…
creator: Glauber Costa
date: 2011-11-07T15:26:32-00:00

[PATCH v5 08/10] Display current tcp memory allocation in kmem cgroup
type: item
description: This patch introduces kmem.tcp.failcnt file, living in the kmem_cgroup filesystem. Following the pattern in the other memcg resources, this files keeps a counter of how many times allocation failed due to limits being hit in this cgroup. The root cgroup will always show a failcnt of 0. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: David S. Miller <davem@davemloft.net> CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com> CC: Eric W. Biederman <ebiederm@xmission.com> --- mm/memcontrol.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 51b5a55..9394224 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -517,6 +517,7 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, const char *buffer); static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft); +static int mem_cgroup_reset(struct cgroup *cont, unsigned int event); /* * We need those things internally in pages, so don't reuse * mem_cgroup_{read,write} @@ -533,6 +534,12 @@ static struct cftype tcp_files[] = { .read_u64 = mem_cgroup_read, .private = MEMFILE_PRIVATE(_KMEM_TCP, RES_USAGE), }, + { + .name = "kmem.tcp.failcnt", + .private = MEMFILE_PRIVATE(_KMEM_TCP, RES_FAILCNT), + .trigger = mem_cgroup_reset, + .read_u64 = mem_cgroup_read, + }, }; static void tcp_create_cgroup(struct mem_cgroup *cg, struct cgroup_subsys *ss) @@ -4134,6 +4141,8 @@ static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft) if (mem_cgroup_is_root(mem)) { if (name == RES_USAGE) val = atomic_long_read(&tcp_memory_allocated) << PAGE_SHIFT; + else if (name == RES_FAILCNT) + val = 0; else val = RESOURCE_MAX; } else @@ -4251,6 +4260,10 @@ static int mem_cgroup_reset(struct cgroup *cont, unsigned int event) case RES_FAILCNT: if (type == _MEM) res_counter_reset_failcnt(&mem->res); +#if defined(CONFIG_CGROUP_MEM_RES_CTLR_KMEM) && defined(CONFIG_INET) + else if (type == _KMEM_TCP) + res_counter_reset_failcnt(&mem->tcp.tcp_mem…
creator: Glauber Costa
date: 2011-11-07T15:26:33-00:00

[PATCH v5 09/10] Display current tcp memory allocation in kmem cgroup
type: item
description: This patch introduces kmem.tcp.max_usage_in_bytes file, living in the kmem_cgroup filesystem. The root cgroup will display a value equal to RESOURCE_MAX. This is to avoid introducing any locking schemes in the network paths when cgroups are not being actively used. All others, will see the maximum memory ever used by this cgroup. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: David S. Miller <davem@davemloft.net> CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com> CC: Eric W. Biederman <ebiederm@xmission.com> --- mm/memcontrol.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9394224..b532f91 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -540,6 +540,12 @@ static struct cftype tcp_files[] = { .trigger = mem_cgroup_reset, .read_u64 = mem_cgroup_read, }, + { + .name = "kmem.tcp.max_usage_in_bytes", + .private = MEMFILE_PRIVATE(_KMEM_TCP, RES_MAX_USAGE), + .trigger = mem_cgroup_reset, + .read_u64 = mem_cgroup_read, + }, }; static void tcp_create_cgroup(struct mem_cgroup *cg, struct cgroup_subsys *ss) @@ -4254,6 +4260,10 @@ static int mem_cgroup_reset(struct cgroup *cont, unsigned int event) case RES_MAX_USAGE: if (type == _MEM) res_counter_reset_max(&mem->res); +#if defined(CONFIG_CGROUP_MEM_RES_CTLR_KMEM) && defined(CONFIG_INET) + else if (type == _KMEM_TCP) + res_counter_reset_max(&mem->tcp.tcp_memory_allocated); +#endif else res_counter_reset_max(&mem->memsw); break; -- 1.7.6.4
creator: Glauber Costa
date: 2011-11-07T15:26:34-00:00

[PATCH v5 10/10] Disable task moving when using kernel memory accounting
type: item
description: Since this code is still experimental, we are leaving the exact details of how to move tasks between cgroups when kernel memory accounting is used as future work. For now, we simply disallow movement if there are any pending accounted memory. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com> --- mm/memcontrol.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b532f91..248f92d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5690,10 +5690,19 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss, { int ret = 0; struct mem_cgroup *mem = mem_cgroup_from_cont(cgroup); + struct mem_cgroup *from = mem_cgroup_from_task(p); + +#if defined(CONFIG_CGROUP_MEM_RES_CTLR_KMEM) && defined(CONFIG_INET) + if (from != mem && !mem_cgroup_is_root(from) && + res_counter_read_u64(&from->tcp.tcp_memory_allocated, RES_USAGE)) { + printk(KERN_WARNING "Can't move tasks between cgroups: " + "Kernel memory held. task: %s\n", p->comm); + return 1; + } +#endif if (mem->move_charge_at_immigrate) { struct mm_struct *mm; - struct mem_cgroup *from = mem_cgroup_from_task(p); VM_BUG_ON(from == mem); @@ -5861,6 +5870,18 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss, struct cgroup *cgroup, struct task_struct *p) { + struct mem_cgroup *mem = mem_cgroup_from_cont(cgroup); + struct mem_cgroup *from = mem_cgroup_from_task(p); + +#if defined(CONFIG_CGROUP_MEM_RES_CTLR_KMEM) && defined(CONFIG_INET) + if (from != mem && !mem_cgroup_is_root(from) && + res_counter_read_u64(&from->tcp.tcp_memory_allocated, RES_USAGE)) { + printk(KERN_WARNING "Can't move tasks between cgroups: " + "Kernel memory held. task: %s\n", p->comm); + return 1; + } +#endif + return 0; } static void mem_cgroup_cancel_attach(struct cgroup_subsys *ss, -- 1.7.6.4
creator: Glauber Costa
date: 2011-11-07T15:26:35-00:00

RE: [PATCH v5 04/10] per-cgroup tcp buffers control
type: item
description: Ok, I forgot to change the temporary name I was using for the jump label. Shame on me :) --- Mensagem Original --- De: Glauber Costa <glommer@parallels.com> Enviado: 7 de novembro de 2011 07/11/11 Para: linux-kernel@vger.kernel.org Cc: paul@paulmenage.org, lizf@cn.fujitsu.com, kamezawa.hiroyu@jp.fujitsu.com, ebiederm@xmission.com, davem@davemloft.net, gthelen@google.com, netdev@vger.kernel.org, linux-mm@kvack.org, kirill@shutemov.name, Andrey Vagin <avagin@parallels.com>, devel@openvz.org, eric.dumazet@gmail.com, Glauber Costa <glommer@parallels.com>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujtisu.com> Assunto: [PATCH v5 04/10] per-cgroup tcp buffers control With all the infrastructure in place, this patch implements per-cgroup control for tcp memory pressure handling. A resource conter is used to control allocated memory, except for the root cgroup, that will keep using global counters. This patch is the one that actually enables/disables the jump labels controlling cgroup. To this point, they were always disabled. Signed-off-by: Glauber Costa <glommer@parallels.com> CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujtisu.com> CC: David S. Miller <davem@davemloft.net> CC: Eric W. Biederman <ebiederm@xmission.com> CC: Eric Dumazet <eric.dumazet@gmail.com> --- include/net/tcp.h | 18 +++++++ include/net/transp_v6.h | 1 + mm/memcontrol.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++- net/core/sock.c | 46 +++++++++++++++-- net/ipv4/af_inet.c | 3 + net/ipv4/tcp_ipv4.c | 12 +++++ net/ipv6/af_inet6.c | 3 + net/ipv6/tcp_ipv6.c | 10 ++++ 8 files changed, 211 insertions(+), 7 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index ccaa3b6..7301ca8 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -253,6 +253,22 @@ extern int sysctl_tcp_cookie_size; extern int sysctl_tcp_thin_linear_timeouts; extern int sysctl_tcp_thin_dupack; +struct tcp_memcontrol { + /* per-cgroup tcp memory pressure knobs */ + struct res_counter tcp_memory_allocated; + struct percpu_c…
creator: Glauber Costa
date: 2011-11-07T17:28:50-00:00

Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: On 11/07/2011 01:26 PM, Glauber Costa wrote: > Hi all, > > This is my new attempt at implementing per-cgroup tcp memory pressure. > I am particularly interested in what the network folks have to comment on > it: my main goal is to achieve the least impact possible in the network code. > > Here's a brief description of my approach: > > When only the root cgroup is present, the code should behave the same way as > before - with the exception of the inclusion of an extra field in struct sock, > and one in struct proto. All tests are patched out with static branch, and we > still access addresses directly - the same as we did before. > > When a cgroup other than root is created, we patch in the branches, and account > resources for that cgroup. The variables in the root cgroup are still updated. > If we were to try to be 100 % coherent with the memcg code, that should depend > on use_hierarchy. However, I feel that this is a good compromise in terms of > leaving the network code untouched, and still having a global vision of its > resources. I also do not compute max_usage for the root cgroup, for a similar > reason. > > Please let me know what you think of it. Dave, Eric, Can you let me know what you think of the general approach I've followed in this series? The impact on the common case should be minimal, or at least as expensive as a static branch (0 in most arches, I believe). I am mostly interested in knowing if this a valid pursue path. I'll be happy to address any specific concerns you have once you're ok with the general approach. Thanks!
creator: Glauber Costa
date: 2011-11-09T18:02:55-00:00

Re: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: On Wed, 2011-11-09 at 16:02 -0200, Glauber Costa wrote: > On 11/07/2011 01:26 PM, Glauber Costa wrote: > > Hi all, > > > > This is my new attempt at implementing per-cgroup tcp memory pressure. > > I am particularly interested in what the network folks have to comment on > > it: my main goal is to achieve the least impact possible in the network code. > > > > Here's a brief description of my approach: > > > > When only the root cgroup is present, the code should behave the same way as > > before - with the exception of the inclusion of an extra field in struct sock, > > and one in struct proto. All tests are patched out with static branch, and we > > still access addresses directly - the same as we did before. > > > > When a cgroup other than root is created, we patch in the branches, and account > > resources for that cgroup. The variables in the root cgroup are still updated. > > If we were to try to be 100 % coherent with the memcg code, that should depend > > on use_hierarchy. However, I feel that this is a good compromise in terms of > > leaving the network code untouched, and still having a global vision of its > > resources. I also do not compute max_usage for the root cgroup, for a similar > > reason. > > > > Please let me know what you think of it. > > Dave, Eric, > > Can you let me know what you think of the general approach I've followed > in this series? The impact on the common case should be minimal, or at > least as expensive as a static branch (0 in most arches, I believe). > > I am mostly interested in knowing if this a valid pursue path. I'll be > happy to address any specific concerns you have once you're ok with the > general approach. Ping on this, please. We're blocked on this patch set until we can get an ack that the approach is acceptable to network people. Thanks, James
creator: James Bottomley
date: 2011-11-15T18:27:12-00:00

Re: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: From: James Bottomley <jbottomley@parallels.com> Date: Tue, 15 Nov 2011 18:27:12 +0000 > Ping on this, please. We're blocked on this patch set until we can get > an ack that the approach is acceptable to network people. __sk_mem_schedule is now more expensive, because instead of short-circuiting the majority of the function's logic when "allocated <= prot->sysctl_mem[0]" and immediately returning 1, the whole rest of the function is run. The static branch protecting all of the cgroup code seems to be enabled if any memory based cgroup'ing is enabled. What if people use the memory cgroup facility but not for sockets? I am to understand that, of the very few people who are going to use this stuff in any capacity, this would be a common usage. TCP specific stuff in mm/memcontrol.c, at best that's not nice at all. Otherwise looks mostly good.
creator: davem
date: 2011-11-17T21:35:01-00:00

Re: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: On 11/17/2011 07:35 PM, David Miller wrote: > From: James Bottomley<jbottomley@parallels.com> > Date: Tue, 15 Nov 2011 18:27:12 +0000 > >> Ping on this, please. We're blocked on this patch set until we can get >> an ack that the approach is acceptable to network people. > > __sk_mem_schedule is now more expensive, because instead of short-circuiting > the majority of the function's logic when "allocated<= prot->sysctl_mem[0]" > and immediately returning 1, the whole rest of the function is run. Not the whole rest of the function. Rather, just the other two tests. But that's the behavior we need since if your parent is on pressure, you should be as well. How do you feel if we'd also provide two versions for this: 1) non-cgroup, try to return 1 as fast as we can 2) cgroup, also check your parents. That could be enclosed in the same static branch we're using right now. > The static branch protecting all of the cgroup code seems to be > enabled if any memory based cgroup'ing is enabled. What if people use > the memory cgroup facility but not for sockets? I am to understand > that, of the very few people who are going to use this stuff in any > capacity, this would be a common usage. How about we make the jump_label only used for sockets (which is basic what we have now, just need a clear name to indicate that), and then enable it not when the first non-root cgroup is created, but when the first one sets the limit to something different than unlimited? Of course to that point, we'd be accounting only to the root structures, but I guess this is not a big deal. > TCP specific stuff in mm/memcontrol.c, at best that's not nice at all. How crucial is that? Thing is that as far as I am concerned, all the memcg people really want the inner layout of struct mem_cgroup to be private to memcontrol.c This means that at some point, we need to have at least a wrapper in memcontrol.c that is able to calculate the offset of the tcp structure, and since most functions are actually quite…
creator: Glauber Costa
date: 2011-11-18T19:39:03-00:00

Re: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: From: Glauber Costa <glommer@parallels.com> Date: Fri, 18 Nov 2011 17:39:03 -0200 > On 11/17/2011 07:35 PM, David Miller wrote: >> From: James Bottomley<jbottomley@parallels.com> >> Date: Tue, 15 Nov 2011 18:27:12 +0000 >> >>> Ping on this, please. We're blocked on this patch set until we can >>> get >>> an ack that the approach is acceptable to network people. >> >> __sk_mem_schedule is now more expensive, because instead of >> short-circuiting >> the majority of the function's logic when "allocated<= >> prot->sysctl_mem[0]" >> and immediately returning 1, the whole rest of the function is run. > > Not the whole rest of the function. Rather, just the other two > tests. But that's the behavior we need since if your parent is on > pressure, you should be as well. How do you feel if we'd also provide > two versions for this: > 1) non-cgroup, try to return 1 as fast as we can > 2) cgroup, also check your parents. Fair enough. > How about we make the jump_label only used for sockets (which is basic > what we have now, just need a clear name to indicate that), and then > enable it not when the first non-root cgroup is created, but when the > first one sets the limit to something different than unlimited? > > Of course to that point, we'd be accounting only to the root > structures, > but I guess this is not a big deal. This sounds good for now. >> TCP specific stuff in mm/memcontrol.c, at best that's not nice at all. > > How crucial is that? It's a big deal. We've been working for years to yank protocol specific things even out of net/core/*.c, it simply doesn't belong there. I'd even be happier if you had to create a net/ipv4/tcp_memcg.c and include/net/tcp_memcg.h > Thing is that as far as I am concerned, all the > memcg people ... What the memcg people want is entirely their problem, especially if it involves crapping up non-networking files with protocol specific junk.
creator: davem
date: 2011-11-18T19:51:07-00:00

Re: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: On Fri, 18 Nov 2011 17:39:03 -0200 Glauber Costa <glommer@parallels.com> wrote: > On 11/17/2011 07:35 PM, David Miller wrote: > > TCP specific stuff in mm/memcontrol.c, at best that's not nice at all. > > How crucial is that? Thing is that as far as I am concerned, all the > memcg people really want the inner layout of struct mem_cgroup to be > private to memcontrol.c This is just because memcg is just related to memory management and I don't want it be wide spreaded, 'struct mem_cgroup' has been changed often. But I don't like to have TCP code in memcgroup.c. New idea is welcome. > This means that at some point, we need to have > at least a wrapper in memcontrol.c that is able to calculate the offset > of the tcp structure, and since most functions are actually quite > simple, that would just make us do more function calls. > > Well, an alternative to that would be to use a void pointer in the newly > added struct cg_proto to an already parsed memcg-related field > (in this case tcp_memcontrol), that would be passed to the functions > instead of the whole memcg structure. Do you think this would be > preferable ? > like this ? struct mem_cgroup_sub_controls { struct mem_cgroup *mem; union { struct tcp_mem_control tcp; } data; }; /* for loosely coupled controls for memcg */ struct memcg_sub_controls_function { struct memcg_sub_controls (*create)(struct mem_cgroup *); struct memcg_sub_controls (*destroy)(struct mem_cgroup *); } int register_memcg_sub_controls(char *name, struct memcg_sub_controls_function *abis); struct mem_cgroup { ..... ..... /* Root memcg will have no sub_controls! */ struct memcg_sub_controls *sub_controls[NR_MEMCG_SUB_CONTROLS]; } Maybe some functions should be exported. Thanks, -Kame
creator: KAMEZAWA Hiroyuki
date: 2011-11-22T02:07:07-00:00

Re: Re: [PATCH v5 00/10] per-cgroup tcp memory pressure
type: item
description: On 11/22/2011 12:07 AM, KAMEZAWA Hiroyuki wrote: > On Fri, 18 Nov 2011 17:39:03 -0200 > Glauber Costa<glommer@parallels.com> wrote: > >> On 11/17/2011 07:35 PM, David Miller wrote: >>> TCP specific stuff in mm/memcontrol.c, at best that's not nice at all. >> >> How crucial is that? Thing is that as far as I am concerned, all the >> memcg people really want the inner layout of struct mem_cgroup to be >> private to memcontrol.c > > This is just because memcg is just related to memory management and I don't > want it be wide spreaded, 'struct mem_cgroup' has been changed often. > > But I don't like to have TCP code in memcgroup.c. > > New idea is welcome. I don't like it either, but it seemed like an acceptable idea when I first wrote it, compared to the options. But I'm happy it was strongly pointed out, I gave this some extra thought, and managed to come up with a more elegant solution for this. Unfortunately, right now I still have some very small tcp glue code I am trying to get rid of - maybe the suggestion you give below can be used >> This means that at some point, we need to have >> at least a wrapper in memcontrol.c that is able to calculate the offset >> of the tcp structure, and since most functions are actually quite >> simple, that would just make us do more function calls. >> >> Well, an alternative to that would be to use a void pointer in the newly >> added struct cg_proto to an already parsed memcg-related field >> (in this case tcp_memcontrol), that would be passed to the functions >> instead of the whole memcg structure. Do you think this would be >> preferable ? >> In the patch I have now, I changed cg_proto's role a bit. It now have pointers to the variables directly as well, and a parent pointer. It allows much of the code to be simplified, and the remainder to live outside memcontrol.c without major problems. But I still need a tcp control structure and a method to calculate its address from a mem_cgroup structure. > like this ? > > struct mem_cg…
creator: Glauber Costa
date: 2011-11-23T10:25:17-00:00