From: Glauber Costa <glommer@parallels.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, containers@lists.osdl.org,
netdev@vger.kernel.org, xemul@parallels.com,
Glauber Costa <glommer@parallels.com>,
"David S. Miller" <davem@davemloft.net>,
Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com>,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH v2 4/9] function wrappers for upcoming socket
Date: Wed, 7 Sep 2011 01:23:14 -0300 [thread overview]
Message-ID: <1315369399-3073-5-git-send-email-glommer@parallels.com> (raw)
In-Reply-To: <1315369399-3073-1-git-send-email-glommer@parallels.com>
Instead of dealing with global values for memory pressure scenarios,
per-cgroup values will be needed. This patch just writes down the
acessor functions to be used later.
Signed-off-by: Glauber Costa <glommer@parallels.com>
CC: David S. Miller <davem@davemloft.net>
CC: Hiroyouki Kamezawa <kamezawa.hiroyu@jp.fujitsu.com>
CC: Eric W. Biederman <ebiederm@xmission.com>
---
include/linux/kmem_cgroup.h | 104 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/include/linux/kmem_cgroup.h b/include/linux/kmem_cgroup.h
index 77076d8..d983ba8 100644
--- a/include/linux/kmem_cgroup.h
+++ b/include/linux/kmem_cgroup.h
@@ -52,6 +52,110 @@ static inline struct kmem_cgroup *kcg_from_task(struct task_struct *tsk)
#ifdef CONFIG_INET
#include <net/sock.h>
+static inline int *sk_memory_pressure(struct sock *sk)
+{
+ int *ret = NULL;
+ if (sk->sk_prot->memory_pressure)
+ ret = sk->sk_prot->memory_pressure(sk->sk_cgrp);
+ return ret;
+}
+
+static inline long sk_prot_mem(struct sock *sk, int index)
+{
+ long *prot = sk->sk_prot->prot_mem(sk->sk_cgrp);
+ return prot[index];
+}
+
+static inline long
+sk_memory_allocated(struct sock *sk)
+{
+ struct proto *prot = sk->sk_prot;
+ struct kmem_cgroup *cg = sk->sk_cgrp;
+
+ return atomic_long_read(prot->memory_allocated(cg));
+}
+
+static inline long
+sk_memory_allocated_add(struct sock *sk, int amt, int *parent_failure)
+{
+ struct proto *prot = sk->sk_prot;
+ struct kmem_cgroup *cg = sk->sk_cgrp;
+ long allocated = atomic_long_add_return(amt, prot->memory_allocated(cg));
+
+#ifdef CONFIG_CGROUP_KMEM
+ for (cg = cg->parent; cg != NULL; cg = cg->parent) {
+ long alloc;
+ /*
+ * Large nestings are not the common case, and stopping in the
+ * middle would be complicated enough, that we bill it all the
+ * way through the root, and if needed, unbill everything later
+ */
+ alloc = atomic_long_add_return(amt, prot->memory_allocated(cg));
+ *parent_failure |= (alloc > sk_prot_mem(sk, 2));
+ }
+#endif
+ return allocated;
+}
+
+static inline void
+sk_memory_allocated_sub(struct sock *sk, int amt)
+{
+ struct proto *prot = sk->sk_prot;
+ struct kmem_cgroup *cg = sk->sk_cgrp;
+
+ atomic_long_sub(amt, prot->memory_allocated(cg));
+
+#ifdef CONFIG_CGROUP_KMEM
+ for (cg = sk->sk_cgrp->parent; cg != NULL; cg = cg->parent)
+ atomic_long_sub(amt, prot->memory_allocated(cg));
+#endif
+}
+
+static inline void sk_sockets_allocated_dec(struct sock *sk)
+{
+ struct proto *prot = sk->sk_prot;
+ struct kmem_cgroup *cg = sk->sk_cgrp;
+
+ percpu_counter_dec(prot->sockets_allocated(cg));
+#ifdef CONFIG_CGROUP_KMEM
+ for (cg = sk->sk_cgrp->parent; cg; cg = cg->parent)
+ percpu_counter_dec(prot->sockets_allocated(cg));
+#endif
+}
+
+static inline void sk_sockets_allocated_inc(struct sock *sk)
+{
+ struct proto *prot = sk->sk_prot;
+ struct kmem_cgroup *cg = sk->sk_cgrp;
+
+ percpu_counter_inc(prot->sockets_allocated(cg));
+#ifdef CONFIG_CGROUP_KMEM
+ for (cg = sk->sk_cgrp->parent; cg; cg = cg->parent)
+ percpu_counter_inc(prot->sockets_allocated(cg));
+#endif
+}
+
+static inline int
+sk_sockets_allocated_read_positive(struct sock *sk)
+{
+ struct proto *prot = sk->sk_prot;
+ struct kmem_cgroup *cg = sk->sk_cgrp;
+
+ return percpu_counter_sum_positive(prot->sockets_allocated(cg));
+}
+
+static inline int
+kcg_sockets_allocated_sum_positive(struct proto *prot, struct kmem_cgroup *cg)
+{
+ return percpu_counter_sum_positive(prot->sockets_allocated(cg));
+}
+
+static inline long
+kcg_memory_allocated(struct proto *prot, struct kmem_cgroup *cg)
+{
+ return atomic_long_read(prot->memory_allocated(cg));
+}
+
static inline void sock_update_kmem_cgrp(struct sock *sk)
{
#ifdef CONFIG_CGROUP_KMEM
--
1.7.6
--
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>
next prev parent reply other threads:[~2011-09-07 4:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-07 4:23 [PATCH v2 0/9] per-cgroup tcp buffers limitation Glauber Costa
2011-09-07 4:23 ` [PATCH v2 1/9] per-netns ipv4 sysctl_tcp_mem Glauber Costa
2011-09-09 2:47 ` KAMEZAWA Hiroyuki
2011-09-09 4:19 ` Glauber Costa
2011-09-07 4:23 ` [PATCH v2 2/9] Kernel Memory cgroup Glauber Costa
2011-09-07 5:24 ` Paul Menage
2011-09-07 5:55 ` Glauber Costa
2011-09-07 4:23 ` [PATCH v2 3/9] socket: initial cgroup code Glauber Costa
2011-09-07 5:26 ` Paul Menage
2011-09-07 5:59 ` Glauber Costa
2011-09-07 22:17 ` Kirill A. Shutemov
2011-09-08 4:54 ` Glauber Costa
2011-09-08 5:35 ` Kirill A. Shutemov
2011-09-08 12:41 ` Glauber Costa
2011-09-07 4:23 ` Glauber Costa [this message]
2011-09-07 4:23 ` [PATCH v2 5/9] foundations of per-cgroup memory pressure controlling Glauber Costa
2011-09-07 4:23 ` [PATCH v2 6/9] per-cgroup tcp buffers control Glauber Costa
2011-09-07 7:32 ` Li Zefan
2011-09-07 13:02 ` Glauber Costa
2011-09-09 3:12 ` KAMEZAWA Hiroyuki
2011-09-09 12:01 ` Glauber Costa
2011-09-12 10:31 ` KAMEZAWA Hiroyuki
2011-09-07 4:23 ` [PATCH v2 7/9] tcp buffer limitation: per-cgroup limit Glauber Costa
2011-09-07 4:23 ` [PATCH v2 8/9] Display current tcp memory allocation in kmem cgroup Glauber Costa
2011-09-07 4:23 ` [PATCH v2 9/9] Add documentation about kmem_cgroup Glauber Costa
2011-09-08 17:46 ` Randy Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1315369399-3073-5-git-send-email-glommer@parallels.com \
--to=glommer@parallels.com \
--cc=containers@lists.osdl.org \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=xemul@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox