LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: linux-mm@kvack.org, YAMAMOTO Takashi <yamamoto@valinux.co.jp>,
	Paul Menage <menage@google.com>,
	lizf@cn.fujitsu.com, linux-kernel@vger.kernel.org,
	Nick Piggin <nickpiggin@yahoo.com.au>,
	David Rientjes <rientjes@google.com>,
	Pavel Emelianov <xemul@openvz.org>,
	Dhaval Giani <dhaval@linux.vnet.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: [patch 1/2] memcg: hierarchy, yet another one.
Date: Tue, 4 Nov 2008 18:21:55 +0900	[thread overview]
Message-ID: <20081104182155.f1b6cdbb.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20081101184812.2575.68112.sendpatchset@balbir-laptop>

This patch is a toy for showing idea,
how do you think ?

[1/2] ... res counter part
[2/2] ... for memcg (mem+swap controller)

based on mem+swap controller + synchronized lru + some fixes(not posted)
I'm just wondering how to support hirerachy and not indend to improve this now.

[1/2] ... hierachical res_counter 
==
Hierarchy support for res_coutner.

This patch adds following interface to res_counter.
 - res_counter_init_hierarchy().
 - res_counter_charge_hierarchy().
 - res_counter_uncharge_hierarchy().
 - res_counter_check_under_limit_hierarchy().

By this, if res_counter is properly intialized, a charge to res_counter
will be charged up to the root of res_counter.

root res_counter has is res_counter->parent pointer to be NULL.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

---
 include/linux/res_counter.h |   13 ++++++++
 kernel/res_counter.c        |   65 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 77 insertions(+), 1 deletion(-)

Index: mmotm-2.6.28-rc2+/include/linux/res_counter.h
===================================================================
--- mmotm-2.6.28-rc2+.orig/include/linux/res_counter.h
+++ mmotm-2.6.28-rc2+/include/linux/res_counter.h
@@ -39,6 +39,10 @@ struct res_counter {
 	 */
 	unsigned long long failcnt;
 	/*
+         * The parent sharing resource.
+         */
+	struct res_counter *parent;
+	/*
 	 * the lock to protect all of the above.
 	 * the routines below consider this to be IRQ-safe
 	 */
@@ -88,6 +92,8 @@ enum {
  */
 
 void res_counter_init(struct res_counter *counter);
+void res_counter_init_hierarchy(struct res_counter *counter,
+				struct res_counter *parent);
 
 /*
  * charge - try to consume more resource.
@@ -105,6 +111,8 @@ int __must_check res_counter_charge_lock
 int __must_check res_counter_charge(struct res_counter *counter,
 		unsigned long val);
 
+int __must_check res_counter_charge_hierarchy(struct res_counter *counter,
+		      unsigned long val, struct res_counter **fail);
 /*
  * uncharge - tell that some portion of the resource is released
  *
@@ -118,6 +126,9 @@ int __must_check res_counter_charge(stru
 void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val);
 void res_counter_uncharge(struct res_counter *counter, unsigned long val);
 
+void res_counter_uncharge_hierarchy(struct res_counter *counter,
+		unsigned long val);
+
 static inline bool res_counter_limit_check_locked(struct res_counter *cnt)
 {
 	if (cnt->usage < cnt->limit)
@@ -126,6 +137,8 @@ static inline bool res_counter_limit_che
 	return false;
 }
 
+bool res_counter_check_under_limit_hierarchy(struct res_counter *cnt,
+					     struct res_counter **fail);
 /*
  * Helper function to detect if the cgroup is within it's limit or
  * not. It's currently called from cgroup_rss_prepare()
Index: mmotm-2.6.28-rc2+/kernel/res_counter.c
===================================================================
--- mmotm-2.6.28-rc2+.orig/kernel/res_counter.c
+++ mmotm-2.6.28-rc2+/kernel/res_counter.c
@@ -15,10 +15,17 @@
 #include <linux/uaccess.h>
 #include <linux/mm.h>
 
-void res_counter_init(struct res_counter *counter)
+void res_counter_init_hierarchy(struct res_counter *counter,
+				struct res_counter *parent)
 {
 	spin_lock_init(&counter->lock);
 	counter->limit = (unsigned long long)LLONG_MAX;
+	counter->parent = parent;
+}
+
+void res_counter_init(struct res_counter *counter)
+{
+	res_counter_init_hierarchy(counter, NULL);
 }
 
 int res_counter_charge_locked(struct res_counter *counter, unsigned long val)
@@ -45,6 +52,7 @@ int res_counter_charge(struct res_counte
 	return ret;
 }
 
+
 void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val)
 {
 	if (WARN_ON(counter->usage < val))
@@ -62,6 +70,61 @@ void res_counter_uncharge(struct res_cou
 	spin_unlock_irqrestore(&counter->lock, flags);
 }
 
+/**
+ * res_counter_charge_hierarchy - hierarchical resource charging.
+ * @counter: an res_counter to be charged.
+ * @val: value to be charged.
+ * @fail: a pointer to *res_counter for returning where we failed.
+ *
+ * charge "val" to res_counter and all ancestors of it. If fails, a pointer
+ * to res_counter which failed to be charged is returned to "fail".
+ */
+int res_counter_charge_hierarchy(struct res_counter *counter,
+				 unsigned long val,
+				 struct res_counter **fail)
+{
+	struct res_counter *tmp, *undo;
+	int ret = 0;
+
+	for (tmp = counter; tmp != NULL; tmp = tmp->parent) {
+		ret = res_counter_charge(tmp, val);
+		if (ret)
+			break;
+	}
+	if (!ret)
+		return ret;
+
+	*fail = tmp;
+	for (undo = tmp, tmp = counter; tmp != undo; tmp = tmp->parent)
+		res_counter_uncharge(tmp, val);
+
+	return ret;
+}
+
+
+void res_counter_uncharge_hierarchy(struct res_counter *counter,
+				    unsigned long  val)
+{
+	struct res_counter *tmp;
+
+	for (tmp = counter; tmp != NULL; tmp = tmp->parent)
+		res_counter_uncharge(tmp, val);
+}
+
+bool res_counter_check_under_limit_hierarchy(struct res_counter *counter,
+					     struct res_counter **fail)
+{
+	struct res_counter *tmp;
+	for (tmp = counter; tmp != NULL; tmp = tmp->parent)
+		if (!res_counter_check_under_limit(tmp))
+			break;
+
+	if (!tmp)
+		return true;
+	*fail = tmp;
+	return false;
+}
+
 
 static inline unsigned long long *
 res_counter_member(struct res_counter *counter, int member)


  parent reply	other threads:[~2008-11-04  9:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-01 18:48 [mm][PATCH 0/4] Memory cgroup hierarchy introduction Balbir Singh
2008-11-01 18:48 ` [mm] [PATCH 1/4] Memory cgroup hierarchy documentation Balbir Singh
2008-11-04  6:25   ` Paul Menage
2008-11-04  6:26     ` Paul Menage
2008-11-05 13:55       ` Balbir Singh
2008-11-01 18:48 ` [mm] [PATCH 2/4] Memory cgroup resource counters for hierarchy Balbir Singh
2008-11-02  5:42   ` KAMEZAWA Hiroyuki
2008-11-02  5:49     ` Balbir Singh
2008-11-02  5:56       ` KAMEZAWA Hiroyuki
2008-11-02 11:46         ` Balbir Singh
2008-11-01 18:48 ` [mm] [PATCH 3/4] Memory cgroup hierarchical reclaim Balbir Singh
2008-11-02  5:37   ` KAMEZAWA Hiroyuki
2008-11-02  5:44     ` Balbir Singh
2008-11-04  2:17       ` KAMEZAWA Hiroyuki
2008-11-05 13:34         ` Balbir Singh
2008-11-05 16:20           ` KAMEZAWA Hiroyuki
2008-11-06 14:00             ` Balbir Singh
2008-11-01 18:49 ` [mm] [PATCH 4/4] Memory cgroup hierarchy feature selector Balbir Singh
2008-11-02  5:38   ` KAMEZAWA Hiroyuki
2008-11-02  6:03     ` Balbir Singh
2008-11-02  6:24       ` KAMEZAWA Hiroyuki
2008-11-02 15:52         ` Balbir Singh
2008-11-04  6:37           ` Paul Menage
2008-11-06  7:00             ` Balbir Singh
2008-11-06  7:01               ` Balbir Singh
2008-11-06  6:56         ` Balbir Singh
2008-11-06  7:30           ` KAMEZAWA Hiroyuki
2008-11-04  0:15 ` [mm][PATCH 0/4] Memory cgroup hierarchy introduction KAMEZAWA Hiroyuki
2008-11-05 13:51   ` Balbir Singh
2008-11-05 16:33     ` KAMEZAWA Hiroyuki
2008-11-05 17:52       ` Balbir Singh
2008-11-06  0:22         ` KAMEZAWA Hiroyuki
2008-11-04  9:21 ` KAMEZAWA Hiroyuki [this message]
2008-11-04  9:25 ` [patch 1/2] memcg: hierarchy, yet another one KAMEZAWA Hiroyuki

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=20081104182155.f1b6cdbb.kamezawa.hiroyu@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=dhaval@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.com \
    --cc=nickpiggin@yahoo.com.au \
    --cc=rientjes@google.com \
    --cc=xemul@openvz.org \
    --cc=yamamoto@valinux.co.jp \
    --subject='Re: [patch 1/2] memcg: hierarchy, yet another one.' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).