per-cgroup tcp memory pressure
Subsystems (7)
v5 cover per-cgroup tcp memory pressure
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 | 11 +- net/ipv4/tcp_input.c | 12 +- net/ipv4/tcp_ipv4.c | 17 ++- net/ipv4/tcp_output.c | 2 +- net/ipv4/tcp_timer.c | 2 +- net/ipv6/af_inet6.c | 5 + net/ipv6/tcp_ipv6.c | 13 +- 19 files changed, 962 insertions(+), 87 deletions(-)
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 1/10 Basic kernel memory functionality for the Memory Controller
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)
--- Documentation/cgroups/memory.txt | 36 ++++++++++++- init/Kconfig | 14 +++++ mm/memcontrol.c | 104 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 147 insertions(+), 7 deletions(-)
Documentation/cgroups/memory.txt +34 -2
@@ -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,31 @@ 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. +Kernel memory limits are not imposed for the root cgroup. + +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. + +CAUTION: As of this writing, the kmem extention may prevent tasks from moving +among cgroups. If a task has kmem accounting in a cgroup, the task cannot be +moved until the kmem resource is released. Also, until the resource is fully +released, the cgroup cannot be destroyed. So, please consider your use cases +and set kmem extention config option carefully. + 3. User Interface 0. Configuration
init/Kconfig +14 -0
@@ -689,6 +689,20 @@ config CGROUP_MEM_RES_CTLR_SWAP_ENABLED For those who want to have the feature enabled by default should select this option (if, for some reason, they need to disable it then swapaccount=0 does the trick). +config CGROUP_MEM_RES_CTLR_KMEM + bool "Memory Resource Controller Kernel Memory accounting (EXPERIMENTAL)" + depends on CGROUP_MEM_RES_CTLR && EXPERIMENTAL + default n + help + The Kernel Memory extension for Memory Resource Controller can limit + the amount of memory used by kernel objects in the system. Those are + fundamentally different from the entities handled by the standard + Memory Controller, which are page-based, and can be swapped. Users of + the kmem extension can use it to guarantee that no group of processes + will ever exhaust kernel resources alone. + + WARNING: The current experimental implementation does not allow a + task to move among different cgroups with a kmem resource being held. config CGROUP_PERF bool "Enable perf_event per-cpu per-container group (cgroup) monitoring"
mm/memcontrol.c +99 -5
166 lines not on this page · raw message
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 2/10 foundations of per-cgroup memory pressure controlling.
In reply to Glauber CostaThis 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.
--- 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(-)
include/linux/memcontrol.h +4 -0
@@ -362,6 +362,10 @@ static inlinevoid 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 )
include/net/sock.h +76 -10
116 lines not on this page · raw message
include/net/tcp.h +2 -1
@@ -44,6 +44,7 @@#include <net/dst.h> #include <linux/seq_file.h> +#include <linux/memcontrol.h> extern struct inet_hashinfo tcp_hashinfo;
@@ -285,7 +286,7 @@ static inline bool tcp_too_many_orphans(struct sock *sk, int shift) }if (sk->sk_wmem_queued >SOCK_MIN_SNDBUF && -atomic_long_read (&tcp_memory_allocated) > sysctl_tcp_mem[2 ]) +sk_memory_allocated (sk) >sk_prot_mem (sk,2 ))return true;return false; }
net/core/sock.c +33 -22
118 lines not on this page · raw message
net/ipv4/proc.c +4 -3
@@ -52,20 +52,21 @@ static int sockstat_seq_show(struct seq_file *seq, void *v) {struct net *net = seq->private;int orphans, sockets; +struct mem_cgroup *cg =mem_cgroup_from_task (current);local_bh_disable (); orphans =percpu_counter_sum_positive (&tcp_orphan_count); - sockets =percpu_counter_sum_positive (&tcp_sockets_allocated); + sockets =kcg_sockets_allocated_sum_positive (&tcp_prot, cg);local_bh_enable ();socket_seq_show (seq);seq_printf (seq,"TCP: inuse %d orphan %d tw %d alloc %d mem %ld\n" ,sock_prot_inuse_get (net, &tcp_prot), orphans, tcp_death_row.tw_count, sockets, -atomic_long_read (&tcp_memory_allocated)); +kcg_memory_allocated (&tcp_prot, cg));seq_printf (seq,"UDP: inuse %d mem %ld\n" ,sock_prot_inuse_get (net, &udp_prot), -atomic_long_read (&udp_memory_allocated)); +kcg_memory_allocated (&udp_prot, cg));seq_printf (seq,"UDPLITE: inuse %d\n" ,sock_prot_inuse_get (net, &udplite_prot)); seq_printf(seq, "RAW: inuse %d\n",
net/ipv4/tcp_input.c +6 -6
@@ -322,7 +322,7 @@ static void tcp_grow_window(struct sock *sk, const struct sk_buff *skb)/* Check #1 */ if (tp->rcv_ssthresh < tp->window_clamp && (int )tp->rcv_ssthresh <tcp_space (sk) && - !tcp_memory_pressure) { + !sk_memory_pressure (sk)) {int incr;/* Check #2. Increase window, if skb with such overhead
@@ -411,8 +411,8 @@ static void tcp_clamp_window(struct sock *sk)if (sk->sk_rcvbuf < sysctl_tcp_rmem[2 ] && !(sk->sk_userlocks &SOCK_RCVBUF_LOCK ) && - !tcp_memory_pressure && -atomic_long_read (&tcp_memory_allocated) < sysctl_tcp_mem[0 ]) { + !sk_memory_pressure (sk) && +sk_memory_allocated (sk) <sk_prot_mem (sk,0 )) { sk->sk_rcvbuf =min (atomic_read (&sk->sk_rmem_alloc), sysctl_tcp_rmem[2 ]); }
@@ -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); -else if (tcp_memory_pressure) +else if (sk_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)return 0 ;/* If we are under global TCP memory pressure, do not expand. */ -if (tcp_memory_pressure) +if (sk_memory_pressure (sk))return 0 ;/* 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 (sk,0 ))return 0 ;/* If we filled the congestion window, do not expand. */
net/ipv4/tcp_ipv4.c +2 -2
@@ -1914,7 +1914,7 @@ static int tcp_v4_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 ();return 0 ;
@@ -1970,7 +1970,7 @@ void tcp_v4_destroy_sock(struct sock *sk) tp->cookie_values =NULL ; } -percpu_counter_dec (&tcp_sockets_allocated); +sk_sockets_allocated_dec (sk); }EXPORT_SYMBOL (tcp_v4_destroy_sock);
net/ipv4/tcp_output.c +1 -1
@@ -1919,7 +1919,7 @@ u32 __tcp_select_window(struct sock *sk)if (free_space < (full_space >>1 )) { icsk->icsk_ack.quick =0 ; -if (tcp_memory_pressure) +if (sk_memory_pressure (sk)) tp->rcv_ssthresh =min (tp->rcv_ssthresh,4U * tp->advmss);
net/ipv4/tcp_timer.c +1 -1
@@ -261,7 +261,7 @@ static void tcp_delack_timer(unsigned long data) } out: -if (tcp_memory_pressure) +if (sk_memory_pressure (sk))sk_mem_reclaim (sk); out_unlock:bh_unlock_sock (sk);
net/ipv6/tcp_ipv6.c +1 -1
@@ -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 ();return 0 ;
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 3/10 socket: initial cgroup code.
In reply to Glauber CostaThe 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.
--- 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(-)
include/linux/memcontrol.h +27 -0
@@ -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 inline void sock_update_memcg (struct sock *sk) +{ +} +#endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */ +#endif /* CONFIG_INET */ #endif /* _LINUX_MEMCONTROL_H */
include/net/sock.h +148 -3
253 lines not on this page · raw message
mm/memcontrol.c +79 -6
97 lines not on this page · raw message
net/core/sock.c +27 -9
@@ -111,6 +111,7 @@#include <linux/init.h> #include <linux/highmem.h> #include <linux/user_namespace.h> +#include <linux/jump_label.h> #include <asm/uaccess.h> #include <asm/system.h>
@@ -141,6 +142,9 @@static struct lock_class_key af_family_keys[AF_MAX ];static struct lock_class_key af_family_slock_keys[AF_MAX ]; +struct jump_label_key cgroup_crap_enabled; +EXPORT_SYMBOL (cgroup_crap_enabled); +/* * Make lock validator output more readable. (we pre-construct these * strings build-time, so that runtime initialization of socket
@@ -1678,26 +1682,27 @@ int __sk_mem_schedule(struct sock *sk, int size, int kind)int amt =sk_mem_pages (size);long allocated;int *memory_pressure; +int parent_status =UNDER_LIMIT ; sk->sk_forward_alloc += amt *SK_MEM_QUANTUM ; memory_pressure =sk_memory_pressure (sk); - allocated =sk_memory_allocated_add (sk, amt); + allocated =sk_memory_allocated_add (sk, amt, &parent_status); + +/* Over hard limit (we or our parents) */ +if ((parent_status ==OVER_LIMIT ) || (allocated >sk_prot_mem (sk,2 ))) + goto suppress_allocation;/* Under limit. */ if (allocated <=sk_prot_mem (sk,0 ))if (memory_pressure && *memory_pressure) *memory_pressure =0 ; -/* Under pressure. */ -if (allocated >sk_prot_mem (sk,1 )) +/* Under pressure. (we or our parents) */ +if ((parent_status ==SOFT_LIMIT ) || allocated >sk_prot_mem (sk,1 ))if (prot->enter_memory_pressure) prot->enter_memory_pressure (sk); -/* Over hard limit. */ -if (allocated >sk_prot_mem (sk,2 )) - goto suppress_allocation; -/* guarantee minimum buffer size under pressure */ if (kind ==SK_MEM_RECV ) {if (atomic_read (&sk->sk_rmem_alloc) < prot->sysctl_rmem[0 ])
@@ -1742,7 +1747,7 @@ suppress_allocation:/* Alas. Undo changes. */ sk->sk_forward_alloc -= amt *SK_MEM_QUANTUM ; -sk_memory_allocated_sub (sk, amt); +sk_memory_allocated_sub (sk, amt, parent_status);return 0 ; }
@@ -1757,7 +1762,7 @@ void __sk_mem_reclaim(struct sock *sk)int *memory_pressure =sk_memory_pressure (sk);sk_memory_allocated_sub (sk, - sk->sk_forward_alloc >>SK_MEM_QUANTUM_SHIFT ); + sk->sk_forward_alloc >>SK_MEM_QUANTUM_SHIFT ,0 ); sk->sk_forward_alloc &=SK_MEM_QUANTUM -1 ; if (memory_pressure && *memory_pressure &&
@@ -2257,6 +2262,9 @@ EXPORT_SYMBOL(sk_common_release);static DEFINE_RWLOCK (proto_list_lock);static LIST_HEAD (proto_list); +static DEFINE_RWLOCK (cg_proto_list_lock); +static LIST_HEAD (cg_proto_list); +#ifdef CONFIG_PROC_FS #define PROTO_INUSE_NR 64/* should be enough for the first time */ struct prot_inuse {
@@ -2358,6 +2366,16 @@ static inline void release_proto_idx(struct proto *prot) }#endif +void cg_proto_register (struct cg_proto *prot,struct proto *parent) +{ +write_lock (&cg_proto_list_lock); +list_add (&prot->node, &cg_proto_list); +write_unlock (&cg_proto_list_lock); + + parent->cg_proto = prot; +} +EXPORT_SYMBOL (cg_proto_register); +int proto_register (struct proto *prot,int alloc_slab) {if (alloc_slab) {
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 4/10 per-cgroup tcp buffers control
In reply to Glauber CostaWith 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.
--- 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(-)
include/net/tcp.h +18 -0
@@ -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,6 +321,7 @@ static inline int tcp_synq_no_recent_overflow(const struct sock *sk) }extern struct proto tcp_prot; +extern struct cg_proto tcp_cg_prot;#define TCP_INC_STATS (net, field) SNMP_INC_STATS((net)->mib.tcp_statistics, field)#define TCP_INC_STATS_BH (net, field) SNMP_INC_STATS_BH((net)->mib.tcp_statistics, field)
@@ -1022,6 +1039,7 @@ static inline void tcp_openreq_init(struct request_sock *req, ireq->loc_port =tcp_hdr (skb)->dest; } +extern void tcp_enter_memory_pressure_cg (struct sock *sk);extern void tcp_enter_memory_pressure (struct sock *sk);static inline int keepalive_intvl_when (const struct tcp_sock *tp)
include/net/transp_v6.h +1 -0
@@ -11,6 +11,7 @@ extern struct proto rawv6_prot;extern struct proto udpv6_prot;extern struct proto udplitev6_prot;extern struct proto tcpv6_prot; +extern struct cg_proto tcpv6_cg_prot;struct flowi6 ;
mm/memcontrol.c +124 -1
184 lines not on this page · raw message
net/core/sock.c +40 -6
58 lines not on this page · raw message
net/ipv4/af_inet.c +3 -0
@@ -1661,6 +1661,9 @@ static int __init inet_init(void)if (rc) goto out_unregister_raw_proto; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +cg_proto_register (&tcp_cg_prot, &tcp_prot); +#endif /* * Tell SOCKET that we are alive... */
net/ipv4/tcp_ipv4.c +12 -0
@@ -1917,6 +1917,7 @@ static int tcp_v4_init_sock(struct sock *sk)sk_sockets_allocated_inc (sk);local_bh_enable (); +sock_update_memcg (sk);return 0 ; }
@@ -2632,6 +2633,17 @@ struct proto tcp_prot = { };EXPORT_SYMBOL (tcp_prot); +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +struct cg_proto tcp_cg_prot = { + .memory_allocated = memory_allocated_tcp, + .memory_pressure = memory_pressure_tcp, + .sockets_allocated = sockets_allocated_tcp, + .prot_mem = sysctl_mem_tcp, + .init_cgroup = tcp_init_cgroup, + .destroy_cgroup = tcp_destroy_cgroup, +}; +EXPORT_SYMBOL (tcp_cg_prot); +#endif static int __net_init tcp_sk_init (struct net *net) {
net/ipv6/af_inet6.c +3 -0
@@ -1103,6 +1103,9 @@ static int __init inet6_init(void)if (err) goto out_unregister_raw_proto; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +cg_proto_register (&tcpv6_cg_prot, &tcpv6_prot); +#endif /* Register the family here so that the init calls below will * be able to create sockets. (?? is this dangerous ??) */
net/ipv6/tcp_ipv6.c +10 -0
@@ -2224,6 +2224,16 @@ struct proto tcpv6_prot = {#endif }; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +struct cg_proto tcpv6_cg_prot = { + .memory_allocated = memory_allocated_tcp, + .memory_pressure = memory_pressure_tcp, + .sockets_allocated = sockets_allocated_tcp, + .prot_mem = sysctl_mem_tcp, +}; +EXPORT_SYMBOL (tcpv6_cg_prot); +#endif +static const struct inet6_protocol tcpv6_protocol = { .handler = tcp_v6_rcv, .err_handler = tcp_v6_err,
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 5/10 per-netns ipv4 sysctl_tcp_mem
In reply to Glauber CostaThis 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.
--- 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(-)
include/net/netns/ipv4.h +1 -0
@@ -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;
include/net/tcp.h +0 -1
@@ -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;
mm/memcontrol.c +5 -3
@@ -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 (struct cgroup *cgrp,struct cgroup_subsys *ss) {struct mem_cgroup *memcg =mem_cgroup_from_cont (cgrp); +struct net *net = current->nsproxy->net_ns;/* * We need to initialize it at populate, not create time. * This is because net sysctl tables are not up until much * later */ - memcg->tcp.tcp_prot_mem[0 ] = sysctl_tcp_mem[0 ]; - memcg->tcp.tcp_prot_mem[1 ] = sysctl_tcp_mem[1 ]; - memcg->tcp.tcp_prot_mem[2 ] = sysctl_tcp_mem[2 ]; + memcg->tcp.tcp_prot_mem[0 ] = net->ipv4.sysctl_tcp_mem[0 ]; + memcg->tcp.tcp_prot_mem[1 ] = net->ipv4.sysctl_tcp_mem[1 ]; + memcg->tcp.tcp_prot_mem[2 ] = net->ipv4.sysctl_tcp_mem[2 ];return 0 ; }
net/ipv4/af_inet.c +2 -0
@@ -1674,6 +1674,8 @@ static int __init inet_init(void)ip_static_sysctl_init ();#endif + tcp_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem; +/* * Add all the base protocols. */
net/ipv4/sysctl_net_ipv4.c +44 -7
87 lines not on this page · raw message
net/ipv4/tcp.c +2 -9
@@ -282,11 +282,9 @@ int sysctl_tcp_fin_timeout __read_mostly = TCP_FIN_TIMEOUT;struct percpu_counter tcp_orphan_count;EXPORT_SYMBOL_GPL (tcp_orphan_count); -long sysctl_tcp_mem[3 ]__read_mostly ;int sysctl_tcp_wmem[3 ]__read_mostly ;int sysctl_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 = ((unsigned long )sysctl_tcp_mem[1 ]) << (PAGE_SHIFT -7 ); + limit = ((unsigned long )init_net.ipv4.sysctl_tcp_mem[1 ]) + << (PAGE_SHIFT -7 ); max_share =min (4UL *1024 *1024 , limit); sysctl_tcp_wmem[0 ] =SK_MEM_QUANTUM ;
net/ipv4/tcp_ipv4.c +0 -1
@@ -2616,7 +2616,6 @@ struct proto tcp_prot = { .orphan_count = &tcp_orphan_count, .memory_allocated = &tcp_memory_allocated, .memory_pressure = &tcp_memory_pressure, - .sysctl_mem = sysctl_tcp_mem, .sysctl_wmem = sysctl_tcp_wmem, .sysctl_rmem = sysctl_tcp_rmem, .max_header = MAX_TCP_HEADER,
net/ipv6/af_inet6.c +2 -0
@@ -1118,6 +1118,8 @@ static int __init inet6_init(void)if (err) goto static_sysctl_fail;#endif + tcpv6_prot.sysctl_mem = init_net.ipv4.sysctl_tcp_mem; +/* * ipngwg API draft makes clear that the correct semantics * for TCP and UDP is to consider one TCP and UDP instance
net/ipv6/tcp_ipv6.c +0 -1
@@ -2208,7 +2208,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,
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 6/10 tcp buffer limitation: per-cgroup limit
In reply to Glauber CostaThis 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.
--- 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(-)
Documentation/cgroups/memory.txt +1 -0
@@ -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
include/linux/memcontrol.h +9 -0
@@ -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 tcp_prot_mem (struct mem_cgroup *memcg,long val,int idx) +{ +}#endif /* CONFIG_CGROUP_MEM_RES_CTLR_KMEM */ #endif /* CONFIG_INET */ #endif /* _LINUX_MEMCONTROL_H */
mm/memcontrol.c +75 -1
118 lines not on this page · raw message
net/ipv4/sysctl_net_ipv4.c +14 -0
@@ -14,6 +14,7 @@#include <linux/init.h> #include <linux/slab.h> #include <linux/nsproxy.h> +#include <linux/memcontrol.h> #include <linux/swap.h> #include <net/snmp.h> #include <net/icmp.h>
@@ -182,6 +183,9 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,int ret;unsigned long vec[3 ];struct net *net = current->nsproxy->net_ns; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +struct mem_cgroup *cg; +#endif ctl_table tmp = { .data = &vec,
@@ -198,6 +202,16 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,if (ret)return ret; +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +rcu_read_lock (); + cg =mem_cgroup_from_task (current); + +tcp_prot_mem (cg, vec[0 ],0 ); +tcp_prot_mem (cg, vec[1 ],1 ); +tcp_prot_mem (cg, vec[2 ],2 ); +rcu_read_unlock (); +#endif + net->ipv4.sysctl_tcp_mem[0 ] = vec[0 ]; net->ipv4.sysctl_tcp_mem[1 ] = vec[1 ]; net->ipv4.sysctl_tcp_mem[2 ] = vec[2 ];
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 7/10 Display current tcp memory allocation in kmem cgroup
In reply to Glauber CostaThis 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.
--- Documentation/cgroups/memory.txt | 1 + mm/memcontrol.c | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-)
Documentation/cgroups/memory.txt +1 -0
@@ -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
mm/memcontrol.c +11 -3
@@ -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_allocated, name);break ;#endif
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 8/10 Display current tcp memory allocation in kmem cgroup
In reply to Glauber CostaThis 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.
--- mm/memcontrol.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
mm/memcontrol.c +13 -0
@@ -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_memory_allocated); +#endif else res_counter_reset_failcnt(&mem->memsw);break ;
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 9/10 Display current tcp memory allocation in kmem cgroup
In reply to Glauber CostaThis 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.
--- mm/memcontrol.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
mm/memcontrol.c +10 -0
@@ -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 ;
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
PATCH v5 10/10 Disable task moving when using kernel memory accounting
In reply to Glauber CostaSince 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.
--- mm/memcontrol.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-)
mm/memcontrol.c +22 -1
@@ -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,
Signature · 8 lines
1.7.6.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. 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:"[email protected]"> [email protected] </a>
Quoted 21 lines · Glauber Costa
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 computemax_usagefor the root cgroup, for a similar reason.
Quoted 1 line
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!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>
T24gV2VkLCAyMDExLTExLTA5IGF0IDE2OjAyIC0wMjAwLCBHbGF1YmVyIENvc3RhIHdyb3RlOg0K PiBPbiAxMS8wNy8yMDExIDAxOjI2IFBNLCBHbGF1YmVyIENvc3RhIHdyb3RlOg0KPiA+IEhpIGFs bCwNCj4gPg0KPiA+IFRoaXMgaXMgbXkgbmV3IGF0dGVtcHQgYXQgaW1wbGVtZW50aW5nIHBlci1j Z3JvdXAgdGNwIG1lbW9yeSBwcmVzc3VyZS4NCj4gPiBJIGFtIHBhcnRpY3VsYXJseSBpbnRlcmVz dGVkIGluIHdoYXQgdGhlIG5ldHdvcmsgZm9sa3MgaGF2ZSB0byBjb21tZW50IG9uDQo+ID4gaXQ6 IG15IG1haW4gZ29hbCBpcyB0byBhY2hpZXZlIHRoZSBsZWFzdCBpbXBhY3QgcG9zc2libGUgaW4g dGhlIG5ldHdvcmsgY29kZS4NCj4gPg0KPiA+IEhlcmUncyBhIGJyaWVmIGRlc2NyaXB0aW9uIG9m IG15IGFwcHJvYWNoOg0KPiA+DQo+ID4gV2hlbiBvbmx5IHRoZSByb290IGNncm91cCBpcyBwcmVz ZW50LCB0aGUgY29kZSBzaG91bGQgYmVoYXZlIHRoZSBzYW1lIHdheSBhcw0KPiA+IGJlZm9yZSAt IHdpdGggdGhlIGV4Y2VwdGlvbiBvZiB0aGUgaW5jbHVzaW9uIG9mIGFuIGV4dHJhIGZpZWxkIGlu IHN0cnVjdCBzb2NrLA0KPiA+IGFuZCBvbmUgaW4gc3RydWN0IHByb3RvLiBBbGwgdGVzdHMgYXJl IHBhdGNoZWQgb3V0IHdpdGggc3RhdGljIGJyYW5jaCwgYW5kIHdlDQo+ID4gc3RpbGwgYWNjZXNz IGFkZHJlc3NlcyBkaXJlY3RseSAtIHRoZSBzYW1lIGFzIHdlIGRpZCBiZWZvcmUuDQo+ID4NCj4g PiBXaGVuIGEgY2dyb3VwIG90aGVyIHRoYW4gcm9vdCBpcyBjcmVhdGVkLCB3ZSBwYXRjaCBpbiB0 aGUgYnJhbmNoZXMsIGFuZCBhY2NvdW50DQo+ID4gcmVzb3VyY2VzIGZvciB0aGF0IGNncm91cC4g VGhlIHZhcmlhYmxlcyBpbiB0aGUgcm9vdCBjZ3JvdXAgYXJlIHN0aWxsIHVwZGF0ZWQuDQo+ID4g SWYgd2Ugd2VyZSB0byB0cnkgdG8gYmUgMTAwICUgY29oZXJlbnQgd2l0aCB0aGUgbWVtY2cgY29k ZSwgdGhhdCBzaG91bGQgZGVwZW5kDQo+ID4gb24gdXNlX2hpZXJhcmNoeS4gSG93ZXZlciwgSSBm ZWVsIHRoYXQgdGhpcyBpcyBhIGdvb2QgY29tcHJvbWlzZSBpbiB0ZXJtcyBvZg0KPiA+IGxlYXZp bmcgdGhlIG5ldHdvcmsgY29kZSB1bnRvdWNoZWQsIGFuZCBzdGlsbCBoYXZpbmcgYSBnbG9iYWwg dmlzaW9uIG9mIGl0cw0KPiA+IHJlc291cmNlcy4gSSBhbHNvIGRvIG5vdCBjb21wdXRlIG1heF91 c2FnZSBmb3IgdGhlIHJvb3QgY2dyb3VwLCBmb3IgYSBzaW1pbGFyDQo+ID4gcmVhc29uLg0KPiA+ DQo+ID4gUGxlYXNlIGxldCBtZSBrbm93IHdoYXQgeW91IHRoaW5rIG9mIGl0Lg0KPiANCj4gRGF2 ZSwgRXJpYywNCj4gDQo+IENhbiB5b3UgbGV0IG1lIGtub3cgd2hhdCB5b3UgdGhpbmsgb2YgdGhl IGdlbmVyYWwgYXBwcm9hY2ggSSd2ZSBmb2xsb3dlZCANCj4gaW4gdGhpcyBzZXJpZXM/IFRoZSBp bXBhY3Qgb24gdGhlIGNvbW1vbiBjYXNlIHNob3VsZCBiZSBtaW5pbWFsLCBvciBhdCANCj4gbGVh c3QgYXMgZXhwZW5zaXZlIGFzIGEgc3RhdGljIGJyYW5jaCAoMCBpbiBtb3N0IGFyY2hlcywgSSBi ZWxpZXZlKS4NCj4gDQo+IEkgYW0gbW9zdGx5IGludGVyZXN0ZWQgaW4ga25vd2luZyBpZiB0aGlz IGEgdmFsaWQgcHVyc3VlIHBhdGguIEknbGwgYmUgDQo+IGhhcHB5IHRvIGFkZHJlc3MgYW55IHNw ZWNpZmljIGNvbmNlcm5zIHlvdSBoYXZlIG9uY2UgeW91J3JlIG9rIHdpdGggdGhlIA0KPiBnZW5l cmFsIGFwcHJvYWNoLg0KDQpQaW5nIG9uIHRoaXMsIHBsZWFzZS4gIFdlJ3JlIGJsb2NrZWQgb24g dGhpcyBwYXRjaCBzZXQgdW50aWwgd2UgY2FuIGdldA0KYW4gYWNrIHRoYXQgdGhlIGFwcHJvYWNo IGlzIGFjY2VwdGFibGUgdG8gbmV0d29yayBwZW9wbGUuDQoNClRoYW5rcywNCg0KSmFtZXMNCg0K
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>
David Miller
maintainerFrom: James Bottomley <[email protected]>
Date: Tue, 15 Nov 2011 18:27:12 +0000
Quoted 2 lines
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.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>
Quoted 9 lines · David Miller
From: James Bottomley<[email protected]>
Date: Tue, 15 Nov 2011 18:27:12 +0000Quoted 2 lines
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_scheduleis 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.
Quoted 5 lines
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.
Quoted 1 line
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 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 ?
Quoted 1 line
Otherwise looks mostly good.
Thank you for your time.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>
David Miller
maintainerFrom: Glauber Costa <[email protected]>
Date: Fri, 18 Nov 2011 17:39:03 -0200
Quoted 14 lines · David Miller
Quoted 7 lines
From: James Bottomley<[email protected]>
Date: Tue, 15 Nov 2011 18:27:12 +0000Quoted 3 lines
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.Quoted 5 lines
__sk_mem_scheduleis 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.
Quoted 6 lines
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.
Quoted 8 lines
How about we make the
jump_labelonly 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.
Quoted 3 lines
Quoted 1 line
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
Quoted 2 lines
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.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>
Quoted 6 lines · On Fri, 18 Nov 2011 17:39:03 -0200 Glauber Costa <[email protected]> wrote:
Quoted 1 line · David Miller
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_cgroupto be private tomemcontrol.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.
Quoted 11 lines
This means that at some point, we need to have
at least a wrapper inmemcontrol.cthat 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_prototo an already parsed memcg-related field (in this casetcp_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
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>
Quoted 10 lines · KAMEZAWA Hiroyuki
Quoted 6 lines · On Fri, 18 Nov 2011 17:39:03 -0200 Glauber Costa<[email protected]> wrote:
Quoted 1 line · David Miller
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_cgroupto be private tomemcontrol.c
Quoted 6 lines
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
Quoted 11 lines
Quoted 11 lines
This means that at some point, we need to have
at least a wrapper inmemcontrol.cthat 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_prototo an already parsed memcg-related field (in this casetcp_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.
Quoted 27 lines
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]; }
Quoted 4 lines
Maybe some functions should be exported.
Thanks,
-Kame
This has the disadvantage that we now have to chase one more pointer (for sub_controls) instead of just accessing tcp_memcontrol directly as in
struct mem_cgroup {
...
struct tcp_memcontrol tcp;
};I see how it would be nice to get rid of all tcp references, but I don't think the above is worse that bundling struct tcp_memcontrol in an union. We also now have to allocate mem_cgroup_subcontrols separately, creating
another opportunity of failure (that's not the end of the world, but allocating it all inside memcg is still preferred, IMHO)
This could work if it was more generic than that, with a data pointer, instead of an union. But then we now have 3 pointers to chase.
My worry here is that we'll end up with a performance a lot worse than the raw network. Well, of course we'll be worse, but in the end of the day, we also want to be as fast as we can.
I wonder how bad it is to have just a tiny glue that calculates the address of the tcp structure in memcontrol.c, and then every other user is passed that structure?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. 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:"[email protected]"> [email protected] </a>