Re: [PATCH v2 2/7] socket: initial cgroup code.
From: Glauber Costa <hidden>
Date: 2011-09-18 03:33:19
Also in:
lkml, netdev
On 09/17/2011 02:52 PM, Kirill A. Shutemov wrote:
On Wed, Sep 14, 2011 at 10:46:10PM -0300, Glauber Costa wrote:quoted
We aim to control the amount of kernel memory pinned at any time by tcp sockets. To lay the foundations for this work, this patch adds a pointer to the kmem_cgroup to the socket structure. Signed-off-by: Glauber Costa<redacted> CC: David S. Miller<davem@davemloft.net> CC: Hiroyouki Kamezawa<redacted> CC: Eric W. Biederman<redacted> --- include/linux/memcontrol.h | 38 ++++++++++++++++++++++++++++++++++++++ include/net/sock.h | 2 ++ net/core/sock.c | 3 +++ 3 files changed, 43 insertions(+), 0 deletions(-)diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 3b535db..be457ce 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h@@ -395,5 +395,43 @@ mem_cgroup_print_bad_page(struct page *page) } #endif +#ifdef CONFIG_INET +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_KMEM +#include<net/sock.h> +static inline void sock_update_memcg(struct sock *sk) +{ + /* right now a socket spends its whole life in the same cgroup */ + BUG_ON(sk->sk_cgrp); + + rcu_read_lock(); + sk->sk_cgrp = mem_cgroup_from_task(current); + + /* + * We don't need to protect against anything task-related, because + * we are basically stuck with the sock pointer that won't change, + * even if the task that originated the socket changes cgroups. + * + * What we do have to guarantee, is that the chain leading us to + * the top level won't change under our noses. Incrementing the + * reference count via cgroup_exclude_rmdir guarantees that. + */ + cgroup_exclude_rmdir(mem_cgroup_css(sk->sk_cgrp)); + rcu_read_unlock(); +} + +static inline void sock_release_memcg(struct sock *sk) +{ + cgroup_release_and_wakeup_rmdir(mem_cgroup_css(sk->sk_cgrp)); +}Do we really need to have these functions in the header?
No, I can move it to memcontrol.c -- 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>