From: Glauber Costa <hidden> Date: 2011-12-05 21:37:40
Hi,
This is my new attempt to fix all the concerns that were raised during
the last iteration.
I should highlight:
1) proc information is kept intact. (although I kept the wrapper functions)
it will be submitted as a follow up patch so it can get the attention it
deserves
2) sockets now hold a reference to memcg. sockets can be alive even after the
task is gone, so we don't bother with between cgroups movements.
To be able to release resources more easily in this cenario, the parent
pointer in struct cg_proto was replaced by a memcg object. We then iterate
through its pointer (which is cleaner anyway)
The rest should be mostly the same except for small fixes and style changes.
Glauber Costa (9):
Basic kernel memory functionality for the Memory Controller
foundations of per-cgroup memory pressure controlling.
socket: initial cgroup code.
tcp memory pressure controls
per-netns ipv4 sysctl_tcp_mem
tcp buffer limitation: per-cgroup limit
Display current tcp memory allocation in kmem cgroup
Display current tcp failcnt in kmem cgroup
Display maximum tcp memory allocation in kmem cgroup
Documentation/cgroups/memory.txt | 46 ++++++-
include/linux/memcontrol.h | 23 ++++
include/net/netns/ipv4.h | 1 +
include/net/sock.h | 239 +++++++++++++++++++++++++++++++++-
include/net/tcp.h | 4 +-
include/net/tcp_memcontrol.h | 19 +++
init/Kconfig | 11 ++
mm/memcontrol.c | 189 +++++++++++++++++++++++++-
net/core/sock.c | 118 ++++++++++++-----
net/ipv4/Makefile | 1 +
net/ipv4/af_inet.c | 2 +
net/ipv4/proc.c | 6 +-
net/ipv4/sysctl_net_ipv4.c | 65 ++++++++-
net/ipv4/tcp.c | 11 +--
net/ipv4/tcp_input.c | 12 +-
net/ipv4/tcp_ipv4.c | 14 ++-
net/ipv4/tcp_memcontrol.c | 272 ++++++++++++++++++++++++++++++++++++++
net/ipv4/tcp_output.c | 2 +-
net/ipv4/tcp_timer.c | 2 +-
net/ipv6/af_inet6.c | 2 +
net/ipv6/tcp_ipv6.c | 8 +-
21 files changed, 968 insertions(+), 79 deletions(-)
create mode 100644 include/net/tcp_memcontrol.h
create mode 100644 net/ipv4/tcp_memcontrol.c
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:37:48
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 <redacted>
Reviewed-by: Kirill A. Shutemov <redacted>
CC: Paul Menage <redacted>
CC: Greg Thelen <redacted>
---
Documentation/cgroups/memory.txt | 40 ++++++++++++++-
init/Kconfig | 11 ++++
mm/memcontrol.c | 103 ++++++++++++++++++++++++++++++++++++--
3 files changed, 147 insertions(+), 7 deletions(-)
@@ -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 usage recorded
@@ -72,6 +76,9 @@ 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.independent_kmem_limit # select whether or not kernel memory limits are+ independent of user limits+ 1. History The memory controller has a long history. A request for comments for the memory
@@ -255,6 +262,35 @@ When oom event notifier is registered, event will be delivered. per-zone-per-cgroup LRU (cgroup's private LRU) is just guarded by zone->lru_lock, it has no lock of its own.+2.7 Kernel Memory Extension (CONFIG_CGROUP_MEM_RES_CTLR_KMEM)++With the Kernel memory extension, the Memory Controller is able to limit+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.++Some kernel memory resources may be accounted and limited separately from the+main "kmem" resource. For instance, a slab cache that is considered important+enough to be limited separately may have its own knobs.++Kernel memory limits are not imposed for the root cgroup. Usage for the root+cgroup may or may not be accounted.++Memory limits as specified by the standard Memory Controller may or may not+take kernel memory into consideration. This is achieved through the file+memory.independent_kmem_limit. A Value different than 0 will allow for kernel+memory to be controlled separately.++When kernel memory limits are not independent, the limit values set in+memory.kmem files are ignored.++Currently no soft limit is implemented for kernel memory. It is future work+to trigger slab reclaim when those limits are reached.++2.7.1 Current Kernel Memory resources accounted++None+ 3. User Interface 0. Configuration
@@ -4978,6 +5067,10 @@ static int mem_cgroup_populate(struct cgroup_subsys *ss,if(!ret)ret=register_memsw_files(cont,ss);++if(!ret)+ret=register_kmem_files(cont,ss);+returnret;}
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:37:54
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 <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Hiroyouki Kamezawa <redacted>
CC: Eric W. Biederman <redacted>
CC: Eric Dumazet <redacted>
---
include/net/sock.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++++-
include/net/tcp.h | 3 +-
net/core/sock.c | 59 +++++++++++++++++-------------
net/ipv4/proc.c | 6 ++--
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 +-
9 files changed, 145 insertions(+), 41 deletions(-)
@@ -1679,28 +1679,26 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)longallocated;sk->sk_forward_alloc+=amt*SK_MEM_QUANTUM;-allocated=atomic_long_add_return(amt,prot->memory_allocated);++allocated=sk_memory_allocated_add(sk,amt);/* Under limit. */-if(allocated<=prot->sysctl_mem[0]){-if(prot->memory_pressure&&*prot->memory_pressure)-*prot->memory_pressure=0;-return1;-}+if(allocated<=sk_prot_mem_limits(sk,0))+sk_leave_memory_pressure(sk);/* Under pressure. */-if(allocated>prot->sysctl_mem[1])-if(prot->enter_memory_pressure)-prot->enter_memory_pressure(sk);+if(allocated>sk_prot_mem_limits(sk,1))+sk_enter_memory_pressure(sk);/* Over hard limit. */-if(allocated>prot->sysctl_mem[2])+if(allocated>sk_prot_mem_limits(sk,2))gotosuppress_allocation;/* guarantee minimum buffer size under pressure */if(kind==SK_MEM_RECV){if(atomic_read(&sk->sk_rmem_alloc)<prot->sysctl_rmem[0])return1;+}else{/* SK_MEM_SEND */if(sk->sk_type==SOCK_STREAM){if(sk->sk_wmem_queued<prot->sysctl_wmem[0])
@@ -1710,13 +1708,13 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)return1;}-if(prot->memory_pressure){+if(sk_has_memory_pressure(sk)){intalloc;-if(!*prot->memory_pressure)+if(!sk_under_memory_pressure(sk))return1;-alloc=percpu_counter_read_positive(prot->sockets_allocated);-if(prot->sysctl_mem[2]>alloc*+alloc=sk_sockets_allocated_read_positive(sk);+if(sk_prot_mem_limits(sk,2)>alloc*sk_mem_pages(sk->sk_wmem_queued+atomic_read(&sk->sk_rmem_alloc)+sk->sk_forward_alloc))
@@ -4864,7 +4864,7 @@ static int tcp_prune_queue(struct sock *sk)if(atomic_read(&sk->sk_rmem_alloc)>=sk->sk_rcvbuf)tcp_clamp_window(sk);-elseif(tcp_memory_pressure)+elseif(sk_under_memory_pressure(sk))tp->rcv_ssthresh=min(tp->rcv_ssthresh,4U*tp->advmss);tcp_collapse_ofo_queue(sk);
@@ -4930,11 +4930,11 @@ static int tcp_should_expand_sndbuf(const struct sock *sk)return0;/* If we are under global TCP memory pressure, do not expand. */-if(tcp_memory_pressure)+if(sk_under_memory_pressure(sk))return0;/* If we are under soft global TCP memory pressure, do not expand. */-if(atomic_long_read(&tcp_memory_allocated)>=sysctl_tcp_mem[0])+if(sk_memory_allocated(sk)>=sk_prot_mem_limits(sk,0))return0;/* If we filled the congestion window, do not expand. */
@@ -1995,7 +1995,7 @@ static int tcp_v6_init_sock(struct sock *sk)sk->sk_rcvbuf=sysctl_tcp_rmem[1];local_bh_disable();-percpu_counter_inc(&tcp_sockets_allocated);+sk_sockets_allocated_inc(sk);local_bh_enable();return0;
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:39:48
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 <redacted>
CC: Kirill A. Shutemov <redacted>
CC: KAMEZAWA Hiroyuki <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Eric W. Biederman <redacted>
CC: Eric Dumazet <redacted>
---
Documentation/cgroups/memory.txt | 4 +-
include/linux/memcontrol.h | 22 ++++++
include/net/sock.h | 151 ++++++++++++++++++++++++++++++++++++--
mm/memcontrol.c | 46 +++++++++++-
net/core/sock.c | 24 ++++--
5 files changed, 230 insertions(+), 17 deletions(-)
@@ -289,7 +289,9 @@ to trigger slab reclaim when those limits are reached. 2.7.1 Current Kernel Memory resources accounted-None+* sockets memory pressure: some sockets protocols have memory pressure+thresholds. The Memory Controller allows them to be controlled individually+per cgroup, instead of globally. 3. User Interface
@@ -834,6 +838,37 @@ struct proto {#ifdef SOCK_REFCNT_DEBUGatomic_tsocks;#endif+#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM+/*+*cgroupspecificinit/deinitfunctions.Calledonceforall+*protocolsthatimplementit,fromcgroupspopulatefunction.+*Thisfunctionhastosetupanyfilestheprotocolwantto+*appearinthekmemcgroupfilesystem.+*/+int(*init_cgroup)(structcgroup*cgrp,+structcgroup_subsys*ss);+void(*destroy_cgroup)(structcgroup*cgrp,+structcgroup_subsys*ss);+structcg_proto*(*proto_cgroup)(structmem_cgroup*memcg);+#endif+};++structcg_proto{+void(*enter_memory_pressure)(structsock*sk);+structres_counter*memory_allocated;/* Current allocated memory. */+structpercpu_counter*sockets_allocated;/* Current number of sockets. */+int*memory_pressure;+long*sysctl_mem;+/*+*memcgfieldisusedtofindwhichmemcgwebelongdirectly+*Eachmemcgstructcanholdmorethanonecg_proto,socontainer_of+*won'treallycut.+*+*Theelegantsolutionwouldbehavinganinversefunctionto+*proto_cgroupinstructproto,butthatmeanspollutingthestructure+*foreverybody,insteadofjustformemcgusers.+*/+structmem_cgroup*memcg;};externintproto_register(structproto*prot,intalloc_slab);
@@ -852,7 +887,7 @@ static inline void sk_refcnt_debug_dec(struct sock *sk)sk->sk_prot->name,sk,atomic_read(&sk->sk_prot->socks));}-staticinlinevoidsk_refcnt_debug_release(conststructsock*sk)+inlinevoidsk_refcnt_debug_release(conststructsock*sk){if(atomic_read(&sk->sk_refcnt)!=1)printk(KERN_DEBUG"Destruction of the %s socket %p delayed, refcnt=%d\n",
@@ -379,7 +379,48 @@ enum mem_type {staticvoidmem_cgroup_get(structmem_cgroup*memcg);staticvoidmem_cgroup_put(structmem_cgroup*memcg);-staticstructmem_cgroup*parent_mem_cgroup(structmem_cgroup*memcg);++/* Writing them here to avoid exposing memcg's inner layout */+#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM+#ifdef CONFIG_INET+#include<net/sock.h>++staticboolmem_cgroup_is_root(structmem_cgroup*memcg);+voidsock_update_memcg(structsock*sk)+{+/* A socket spends its whole life in the same cgroup */+if(sk->sk_cgrp){+WARN_ON(1);+return;+}+if(static_branch(&memcg_socket_limit_enabled)){+structmem_cgroup*memcg;++BUG_ON(!sk->sk_prot->proto_cgroup);++rcu_read_lock();+memcg=mem_cgroup_from_task(current);+if(!mem_cgroup_is_root(memcg)){+mem_cgroup_get(memcg);+sk->sk_cgrp=sk->sk_prot->proto_cgroup(memcg);+}+rcu_read_unlock();+}+}+EXPORT_SYMBOL(sock_update_memcg);++voidsock_release_memcg(structsock*sk)+{+if(static_branch(&memcg_socket_limit_enabled)&&sk->sk_cgrp){+structmem_cgroup*memcg;+WARN_ON(!sk->sk_cgrp->memcg);+memcg=sk->sk_cgrp->memcg;+mem_cgroup_put(memcg);+}+}+#endif /* CONFIG_INET */+#endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */+staticvoiddrain_all_stock_async(structmem_cgroup*memcg);staticstructmem_cgroup_per_zone*
@@ -1677,21 +1681,25 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)structproto*prot=sk->sk_prot;intamt=sk_mem_pages(size);longallocated;+intparent_status=UNDER_LIMIT;sk->sk_forward_alloc+=amt*SK_MEM_QUANTUM;-allocated=sk_memory_allocated_add(sk,amt);+allocated=sk_memory_allocated_add(sk,amt,&parent_status);/* Under limit. */-if(allocated<=sk_prot_mem_limits(sk,0))+if(parent_status==UNDER_LIMIT&&+allocated<=sk_prot_mem_limits(sk,0))sk_leave_memory_pressure(sk);-/* Under pressure. */-if(allocated>sk_prot_mem_limits(sk,1))+/* Under pressure. (we or our parents) */+if((parent_status>SOFT_LIMIT)||+allocated>sk_prot_mem_limits(sk,1))sk_enter_memory_pressure(sk);-/* Over hard limit. */-if(allocated>sk_prot_mem_limits(sk,2))+/* Over hard limit (we or our parents) */+if((parent_status==OVER_LIMIT)||+(allocated>sk_prot_mem_limits(sk,2)))gotosuppress_allocation;/* guarantee minimum buffer size under pressure */
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:40:05
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 <redacted>
CC: KAMEZAWA Hiroyuki <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Eric W. Biederman <redacted>
---
include/net/netns/ipv4.h | 1 +
include/net/tcp.h | 1 -
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/ipv4/tcp_memcontrol.c | 9 +++++--
net/ipv6/af_inet6.c | 2 +
net/ipv6/tcp_ipv6.c | 1 -
9 files changed, 57 insertions(+), 22 deletions(-)
@@ -769,6 +800,12 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)net->ipv4.sysctl_rt_cache_rebuild_count=4;+limit=nr_free_buffer_pages()/8;+limit=max(limit,128UL);+net->ipv4.sysctl_tcp_mem[0]=limit/4*3;+net->ipv4.sysctl_tcp_mem[1]=limit;+net->ipv4.sysctl_tcp_mem[2]=net->ipv4.sysctl_tcp_mem[0]*2;+net->ipv4.ipv4_hdr=register_net_sysctl_table(net,net_ipv4_ctl_path,table);if(net->ipv4.ipv4_hdr==NULL)
@@ -282,11 +282,9 @@ int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;structpercpu_countertcp_orphan_count;EXPORT_SYMBOL_GPL(tcp_orphan_count);-longsysctl_tcp_mem[3]__read_mostly;intsysctl_tcp_wmem[3]__read_mostly;intsysctl_tcp_rmem[3]__read_mostly;-EXPORT_SYMBOL(sysctl_tcp_mem);EXPORT_SYMBOL(sysctl_tcp_rmem);EXPORT_SYMBOL(sysctl_tcp_wmem);
@@ -3272,14 +3270,9 @@ void __init tcp_init(void)sysctl_tcp_max_orphans=cnt/2;sysctl_max_syn_backlog=max(128,cnt/256);-limit=nr_free_buffer_pages()/8;-limit=max(limit,128UL);-sysctl_tcp_mem[0]=limit/4*3;-sysctl_tcp_mem[1]=limit;-sysctl_tcp_mem[2]=sysctl_tcp_mem[0]*2;-/* Set per-socket limits to no more than 1/128 the pressure threshold */-limit=((unsignedlong)sysctl_tcp_mem[1])<<(PAGE_SHIFT-7);+limit=((unsignedlong)init_net.ipv4.sysctl_tcp_mem[1])+<<(PAGE_SHIFT-7);max_share=min(4UL*1024*1024,limit);sysctl_tcp_wmem[0]=SK_MEM_QUANTUM;
@@ -2216,7 +2216,6 @@ struct proto tcpv6_prot = {.memory_allocated=&tcp_memory_allocated,.memory_pressure=&tcp_memory_pressure,.orphan_count=&tcp_orphan_count,-.sysctl_mem=sysctl_tcp_mem,.sysctl_wmem=sysctl_tcp_wmem,.sysctl_rmem=sysctl_tcp_rmem,.max_header=MAX_TCP_HEADER,
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:40:12
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 <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Hiroyouki Kamezawa <redacted>
CC: Eric W. Biederman <redacted>
---
Documentation/cgroups/memory.txt | 1 +
include/net/tcp_memcontrol.h | 2 +
net/ipv4/sysctl_net_ipv4.c | 14 ++++
net/ipv4/tcp_memcontrol.c | 137 +++++++++++++++++++++++++++++++++++++-
4 files changed, 152 insertions(+), 2 deletions(-)
@@ -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
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:40:23
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 <redacted>
Reviewed-by: Hiroyouki Kamezawa <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Eric W. Biederman <redacted>
---
Documentation/cgroups/memory.txt | 1 +
net/ipv4/tcp_memcontrol.c | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)
@@ -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
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:40:28
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 <redacted>
Reviewed-by: Hiroyouki Kamezawa <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Eric W. Biederman <redacted>
---
net/ipv4/tcp_memcontrol.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-05 21:40:39
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 <redacted>
Reviewed-by: Hiroyouki Kamezawa <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Eric W. Biederman <redacted>
---
net/ipv4/tcp_memcontrol.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
@@ -226,6 +233,9 @@ static int tcp_cgroup_reset(struct cgroup *cont, unsigned int event)tcp=tcp_from_cgproto(cg_proto);switch(event){+caseRES_MAX_USAGE:+res_counter_reset_max(&tcp->tcp_memory_allocated);+break;caseRES_FAILCNT:res_counter_reset_failcnt(&tcp->tcp_memory_allocated);break;
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
@@ -293,6 +293,8 @@ to trigger slab reclaim when those limits are reached. thresholds. The Memory Controller allows them to be controlled individually per cgroup, instead of globally.+* tcp memory pressure: sockets memory pressure for the tcp protocol.+ 3. User Interface 0. Configuration
@@ -0,0 +1,17 @@+#ifndef _TCP_MEMCG_H+#define _TCP_MEMCG_H++structtcp_memcontrol{+structcg_protocg_proto;+/* per-cgroup tcp memory pressure knobs */+structres_countertcp_memory_allocated;+structpercpu_countertcp_sockets_allocated;+/* those two are read-mostly, leave them at the end */+longtcp_prot_mem[3];+inttcp_memory_pressure;+};++structcg_proto*tcp_proto_cgroup(structmem_cgroup*memcg);+inttcp_init_cgroup(structcgroup*cgrp,structcgroup_subsys*ss);+voidtcp_destroy_cgroup(structcgroup*cgrp,structcgroup_subsys*ss);+#endif /* _TCP_MEMCG_H */
@@ -2256,9 +2296,6 @@ void sk_common_release(struct sock *sk)}EXPORT_SYMBOL(sk_common_release);-staticDEFINE_RWLOCK(proto_list_lock);-staticLIST_HEAD(proto_list);-#ifdef CONFIG_PROC_FS#define PROTO_INUSE_NR 64 /* should be enough for the first time */structprot_inuse{
@@ -1995,6 +1996,7 @@ static int tcp_v6_init_sock(struct sock *sk)sk->sk_rcvbuf=sysctl_tcp_rmem[1];local_bh_disable();+sock_update_memcg(sk);sk_sockets_allocated_inc(sk);local_bh_enable();
@@ -2228,6 +2230,9 @@ struct proto tcpv6_prot = {.compat_setsockopt=compat_tcp_setsockopt,.compat_getsockopt=compat_tcp_getsockopt,#endif+#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM+.proto_cgroup=tcp_proto_cgroup,+#endif};staticconststructinet6_protocoltcpv6_protocol={
--
1.7.6.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-07 11:07:12
On 12/05/2011 07:34 PM, Glauber Costa wrote:
Hi,
This is my new attempt to fix all the concerns that were raised during
the last iteration.
I should highlight:
1) proc information is kept intact. (although I kept the wrapper functions)
it will be submitted as a follow up patch so it can get the attention it
deserves
2) sockets now hold a reference to memcg. sockets can be alive even after the
task is gone, so we don't bother with between cgroups movements.
To be able to release resources more easily in this cenario, the parent
pointer in struct cg_proto was replaced by a memcg object. We then iterate
through its pointer (which is cleaner anyway)
The rest should be mostly the same except for small fixes and style changes.
Kame,
Does this one address your previous concerns?
Thanks
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 7 Dec 2011 09:06:17 -0200
Glauber Costa [off-list ref] wrote:
On 12/05/2011 07:34 PM, Glauber Costa wrote:
quoted
Hi,
This is my new attempt to fix all the concerns that were raised during
the last iteration.
I should highlight:
1) proc information is kept intact. (although I kept the wrapper functions)
it will be submitted as a follow up patch so it can get the attention it
deserves
2) sockets now hold a reference to memcg. sockets can be alive even after the
task is gone, so we don't bother with between cgroups movements.
To be able to release resources more easily in this cenario, the parent
pointer in struct cg_proto was replaced by a memcg object. We then iterate
through its pointer (which is cleaner anyway)
The rest should be mostly the same except for small fixes and style changes.
Kame,
Does this one address your previous concerns?
Your highlight seems good. I'll look into details.
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
On Mon, 5 Dec 2011 19:34:55 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
Reviewed-by: Kirill A. Shutemov <redacted>
CC: Paul Menage <redacted>
CC: Greg Thelen <redacted>
As I wrote, please CC Johannes and Michal Hocko for memcg related parts.
A few questions.
==
+ val = !!val;
+
+ if (parent && parent->use_hierarchy &&
+ (val != parent->kmem_independent_accounting))
+ return -EINVAL;
==
Hm, why you check val != parent->kmem_independent_accounting ?
if (parent && parent->use_hierarchy)
return -EINVAL;
?
BTW, you didn't check this cgroup has children or not.
I think
if (this_cgroup->use_hierarchy &&
!list_empty(this_cgroup->childlen))
return -EINVAL;
==
+ /*
+ * TODO: We need to handle the case in which we are doing
+ * independent kmem accounting as authorized by our parent,
+ * but then our parent changes its parameter.
+ */
+ cgroup_lock();
+ memcg->kmem_independent_accounting = val;
+ cgroup_unlock();
Do we need cgroup_lock() here ?
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
On Mon, 5 Dec 2011 19:34:56 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
CC: David S. Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
CC: Hiroyouki Kamezawa <redacted>
CC: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
CC: Eric Dumazet <redacted>
please get ack from network guys.
from me.
Reviewed-by: KAMEZAWA Hiroyuki <redacted>
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, 5 Dec 2011 19:34:57 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
CC: Kirill A. Shutemov <redacted>
CC: KAMEZAWA Hiroyuki <redacted>
CC: David S. Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
CC: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
CC: Eric Dumazet <redacted>
Reviewed-by: KAMEZAWA Hiroyuki <redacted>
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, 5 Dec 2011 19:34:58 -0200
Glauber Costa [off-list ref] wrote:
This patch introduces memory pressure controls for the tcp
protocol. It uses the generic socket memory pressure code
introduced in earlier patches, and fills in the
necessary data in cg_proto struct.
Signed-off-by: Glauber Costa <redacted>
CC: KAMEZAWA Hiroyuki <redacted>
CC: Eric W. Biederman <redacted>
Reviewed-by: KAMEZAWA Hiroyuki <redacted>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
On Mon, 5 Dec 2011 19:34:59 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
CC: KAMEZAWA Hiroyuki <redacted>
CC: David S. Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
CC: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Reviewed-by: KAMEZAWA Hiroyuki <redacted>
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, 5 Dec 2011 19:35:00 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Hiroyouki Kamezawa <redacted>
CC: Eric W. Biederman <redacted>
Reviewed-by: KAMEZAWA Hiroyuki <redacted>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
On Mon, 5 Dec 2011 19:35:01 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
Reviewed-by: Hiroyouki Kamezawa <redacted>
CC: David S. Miller <davem@davemloft.net>
CC: Eric W. Biederman <redacted>
Reviewed-by: KAMEZAWA Hiroyuki <redacted>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
On Mon, 5 Dec 2011 19:35:03 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
Reviewed-by: Hiroyouki Kamezawa <redacted>
CC: David S. Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
CC: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Reviewed-by: KAMEZAWA Hiroyuki <redacted>
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, 5 Dec 2011 19:34:57 -0200
Glauber Costa [off-list ref] wrote:
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 <redacted>
CC: Kirill A. Shutemov <redacted>
CC: KAMEZAWA Hiroyuki <redacted>
CC: David S. Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
CC: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
CC: Eric Dumazet <redacted>
I already replied Reviewed-by: but...
+/* Writing them here to avoid exposing memcg's inner layout */
+#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
+#ifdef CONFIG_INET
+#include <net/sock.h>
+
+static bool mem_cgroup_is_root(struct mem_cgroup *memcg);
+void sock_update_memcg(struct sock *sk)
+{
+ /* A socket spends its whole life in the same cgroup */
+ if (sk->sk_cgrp) {
+ WARN_ON(1);
+ return;
+ }
+ if (static_branch(&memcg_socket_limit_enabled)) {
+ struct mem_cgroup *memcg;
+
+ BUG_ON(!sk->sk_prot->proto_cgroup);
+
+ rcu_read_lock();
+ memcg = mem_cgroup_from_task(current);
+ if (!mem_cgroup_is_root(memcg)) {
+ mem_cgroup_get(memcg);
+ sk->sk_cgrp = sk->sk_prot->proto_cgroup(memcg);
+ }
+ rcu_read_unlock();
+ }
+}
Here, you do mem_cgroup_get() if !mem_cgroup_is_root().
You don't check !mem_cgroup_is_root(). Hm, root memcg will not be freed
by this ?
Thanks,
-Kame
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Glauber Costa <hidden> Date: 2011-12-09 12:40:57
On 12/08/2011 11:21 PM, KAMEZAWA Hiroyuki wrote:
On Mon, 5 Dec 2011 19:34:55 -0200
Glauber Costa[off-list ref] wrote:
quoted
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<redacted>
Reviewed-by: Kirill A. Shutemov<redacted>
CC: Paul Menage<redacted>
CC: Greg Thelen<redacted>
As I wrote, please CC Johannes and Michal Hocko for memcg related parts.
I forgot to add them to the patch itself, but they are in the CC list of
the messages.
So they did get the mail.
A few questions.
==
quoted
+ val = !!val;
+
+ if (parent&& parent->use_hierarchy&&
+ (val != parent->kmem_independent_accounting))
+ return -EINVAL;
==
Hm, why you check val != parent->kmem_independent_accounting ?
if (parent&& parent->use_hierarchy)
return -EINVAL;
?
Because I thought that making sure that everybody in the chain is
consistent, it will make things simpler for us. But I am happy to change
that if you prefer.
BTW, you didn't check this cgroup has children or not.
I think
if (this_cgroup->use_hierarchy&&
!list_empty(this_cgroup->childlen))
return -EINVAL;
Noted.
==
quoted
+ /*
+ * TODO: We need to handle the case in which we are doing
+ * independent kmem accounting as authorized by our parent,
+ * but then our parent changes its parameter.
+ */
+ cgroup_lock();
+ memcg->kmem_independent_accounting = val;
+ cgroup_unlock();
Do we need cgroup_lock() here ?
Well, I removed almost all instances of it from previous patches, so I
guess this one can go as well.
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Glauber Costa <hidden> Date: 2011-12-09 12:41:40
On 12/08/2011 11:24 PM, KAMEZAWA Hiroyuki wrote:
On Mon, 5 Dec 2011 19:34:56 -0200
Glauber Costa[off-list ref] wrote:
quoted
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<redacted>
CC: David S. Miller<davem@davemloft.net>
CC: Hiroyouki Kamezawa<redacted>
CC: Eric W. Biederman<redacted>
CC: Eric Dumazet<redacted>
please get ack from network guys.
from me.
Reviewed-by: KAMEZAWA Hiroyuki<redacted>
Ok.
I think that now with all the Reviewed-by:'s I will resend it as a
Request for Inclusion for Dave (plus fixing the problem you noted in
patch 1)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-09 12:43:38
On 12/09/2011 12:05 AM, KAMEZAWA Hiroyuki wrote:
On Mon, 5 Dec 2011 19:34:57 -0200
Glauber Costa[off-list ref] wrote:
quoted
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<redacted>
CC: Kirill A. Shutemov<redacted>
CC: KAMEZAWA Hiroyuki<redacted>
CC: David S. Miller<davem@davemloft.net>
CC: Eric W. Biederman<redacted>
CC: Eric Dumazet<redacted>
I already replied Reviewed-by: but...
Feel free. Reviews, the more, the merrier.
quoted
+/* Writing them here to avoid exposing memcg's inner layout */
+#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
+#ifdef CONFIG_INET
+#include<net/sock.h>
+
+static bool mem_cgroup_is_root(struct mem_cgroup *memcg);
+void sock_update_memcg(struct sock *sk)
+{
+ /* A socket spends its whole life in the same cgroup */
+ if (sk->sk_cgrp) {
+ WARN_ON(1);
+ return;
+ }
+ if (static_branch(&memcg_socket_limit_enabled)) {
+ struct mem_cgroup *memcg;
+
+ BUG_ON(!sk->sk_prot->proto_cgroup);
+
+ rcu_read_lock();
+ memcg = mem_cgroup_from_task(current);
+ if (!mem_cgroup_is_root(memcg)) {
+ mem_cgroup_get(memcg);
+ sk->sk_cgrp = sk->sk_prot->proto_cgroup(memcg);
+ }
+ rcu_read_unlock();
+ }
+}
Here, you do mem_cgroup_get() if !mem_cgroup_is_root().
You don't check !mem_cgroup_is_root(). Hm, root memcg will not be freed
by this ?
No, I don't. But I check if sk->sk_cgrp is filled. So it is implied,
because we only fill in this value if !mem_cgroup_is_root().
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-09 14:38:12
On 12/08/2011 11:21 PM, KAMEZAWA Hiroyuki wrote:
Hm, why you check val != parent->kmem_independent_accounting ?
if (parent&& parent->use_hierarchy)
return -EINVAL;
?
BTW, you didn't check this cgroup has children or not.
I think
if (this_cgroup->use_hierarchy&&
!list_empty(this_cgroup->childlen))
return -EINVAL;
How about this?
val = !!val;
/*
* This follows the same hierarchy restrictions than
* mem_cgroup_hierarchy_write()
*/
if (!parent || !parent->use_hierarchy) {
if (list_empty(&cgroup->children))
memcg->kmem_independent_accounting = val;
else
return -EBUSY;
}
else
return -EINVAL;
return 0;
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
From: David Laight <hidden> Date: 2011-12-09 14:45:01
How about this?
val = !!val;
/*
* This follows the same hierarchy restrictions than
* mem_cgroup_hierarchy_write()
*/
if (!parent || !parent->use_hierarchy) {
if (list_empty(&cgroup->children))
memcg->kmem_independent_accounting = val;
else
return -EBUSY;
}
else
return -EINVAL;
return 0;
Inverting the tests gives easier to read code:
if (parent && parent->user_hierarchy)
return -EINVAL;
if (!list_empty(&cgroup->children))
return -EBUSY;
memcg->kmem_independent_accounting = val != 0;
return 0;
NFI about the logic...
On the face of it the tests don't seem related to each other
or to the assignment!
David
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
From: Glauber Costa <hidden> Date: 2011-12-09 14:48:56
On 12/09/2011 12:44 PM, David Laight wrote:
quoted
How about this?
val = !!val;
/*
* This follows the same hierarchy restrictions than
* mem_cgroup_hierarchy_write()
*/
if (!parent || !parent->use_hierarchy) {
if (list_empty(&cgroup->children))
memcg->kmem_independent_accounting = val;
else
return -EBUSY;
}
else
return -EINVAL;
return 0;
Inverting the tests gives easier to read code:
if (parent&& parent->user_hierarchy)
return -EINVAL;
if (!list_empty(&cgroup->children))
return -EBUSY;
memcg->kmem_independent_accounting = val != 0;
return 0;
On the other hand, inconsistent with mem_cgroup_hierarchy_write(), which
applies the logic in the same way I did here.
NFI about the logic...
On the face of it the tests don't seem related to each other
or to the assignment!
How so?
If parent's use_hierarchy is set, we can't set this value (we need to
have a parent for that to even matter).
We also can't set it if we already have any children - otherwise all the
on-the-fly adjustments become hell-on-earth.
As for = val != 0, sorry, but I completely disagree this is easier than
!!val. Not to mention the !!val notation is already pretty widespread in
the kernel.
David
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email:<a href=ilto:"dont@kvack.org"> email@kvack.org</a>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
On Fri, 9 Dec 2011 10:43:00 -0200
Glauber Costa [off-list ref] wrote:
On 12/09/2011 12:05 AM, KAMEZAWA Hiroyuki wrote:
quoted
On Mon, 5 Dec 2011 19:34:57 -0200
Glauber Costa[off-list ref] wrote:
quoted
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<redacted>
CC: Kirill A. Shutemov<redacted>
CC: KAMEZAWA Hiroyuki<redacted>
CC: David S. Miller<davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
CC: Eric W. Biederman<ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
CC: Eric Dumazet<redacted>
I already replied Reviewed-by: but...
Feel free. Reviews, the more, the merrier.
quoted
quoted
+/* Writing them here to avoid exposing memcg's inner layout */
+#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM
+#ifdef CONFIG_INET
+#include<net/sock.h>
+
+static bool mem_cgroup_is_root(struct mem_cgroup *memcg);
+void sock_update_memcg(struct sock *sk)
+{
+ /* A socket spends its whole life in the same cgroup */
+ if (sk->sk_cgrp) {
+ WARN_ON(1);
+ return;
+ }
+ if (static_branch(&memcg_socket_limit_enabled)) {
+ struct mem_cgroup *memcg;
+
+ BUG_ON(!sk->sk_prot->proto_cgroup);
+
+ rcu_read_lock();
+ memcg = mem_cgroup_from_task(current);
+ if (!mem_cgroup_is_root(memcg)) {
+ mem_cgroup_get(memcg);
+ sk->sk_cgrp = sk->sk_prot->proto_cgroup(memcg);
+ }
+ rcu_read_unlock();
+ }
+}
Here, you do mem_cgroup_get() if !mem_cgroup_is_root().
You don't check !mem_cgroup_is_root(). Hm, root memcg will not be freed
by this ?
No, I don't. But I check if sk->sk_cgrp is filled. So it is implied,
because we only fill in this value if !mem_cgroup_is_root().
Ah, ok. thank you.
-Kame
--
To unsubscribe from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, 9 Dec 2011 12:37:23 -0200
Glauber Costa [off-list ref] wrote:
On 12/08/2011 11:21 PM, KAMEZAWA Hiroyuki wrote:
quoted
Hm, why you check val != parent->kmem_independent_accounting ?
if (parent&& parent->use_hierarchy)
return -EINVAL;
?
BTW, you didn't check this cgroup has children or not.
I think
if (this_cgroup->use_hierarchy&&
!list_empty(this_cgroup->childlen))
return -EINVAL;
How about this?
val = !!val;
/*
* This follows the same hierarchy restrictions than
* mem_cgroup_hierarchy_write()
*/
if (!parent || !parent->use_hierarchy) {
if (list_empty(&cgroup->children))
memcg->kmem_independent_accounting = val;
else
return -EBUSY;
}
else
return -EINVAL;
return 0;
seems good to me.
Thanks,
-Kame
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>