linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
To: Linux Containers <containers@lists.osdl.org>,
	Linux MM <linux-mm@kvack.org>
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>,
	Pavel Emelyanov <xemul@openvz.org>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	YAMAMOTO Takashi <yamamoto@valinux.co.jp>,
	Hugh Dickins <hugh@veritas.com>,
	"IKEDA, Munehiro" <m-ikeda@ds.jp.nec.com>
Subject: [PATCH 1/4] swapcgroup: add cgroup files
Date: Thu, 22 May 2008 15:17:26 +0900	[thread overview]
Message-ID: <48350FF6.4040801@mxp.nes.nec.co.jp> (raw)
In-Reply-To: <48350F15.9070007@mxp.nes.nec.co.jp>

This patch add cgroup files(and a member to struct mem_cgroup)
for swapcgroup.

The files to be added are:

- memory.swap_usage_in_bytes
- memory.swap_max_usage_in_bytes
- memory.swap_limit_in_bytes
- memory.swap_failcnt

The meaning of those files are the same as memory cgroup.


Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>

---
 init/Kconfig    |    7 +++++
 mm/memcontrol.c |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/init/Kconfig b/init/Kconfig
index 6135d07..aabbb83 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -407,6 +407,13 @@ config CGROUP_MEM_RES_CTLR
 	  This config option also selects MM_OWNER config option, which
 	  could in turn add some fork/exit overhead.
 
+config CGROUP_SWAP_RES_CTLR
+	bool "Swap Resource Controller for Control Groups"
+	depends on CGROUP_MEM_RES_CTLR && SWAP
+	help
+	  Provides a swap resource controller that manages and limits swap usage.
+	  Implemented as a add-on to Memory Resource Controller.
+
 config SYSFS_DEPRECATED
 	bool
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a96577f..a837215 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -141,6 +141,12 @@ struct mem_cgroup {
 	 * statistics.
 	 */
 	struct mem_cgroup_stat stat;
+#ifdef CONFIG_CGROUP_SWAP_RES_CTLR
+	/*
+	 * the counter to account for swap usage
+	 */
+	struct res_counter swap_res;
+#endif
 };
 static struct mem_cgroup init_mem_cgroup;
 
@@ -960,6 +966,39 @@ static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft,
 	return 0;
 }
 
+#ifdef CONFIG_CGROUP_SWAP_RES_CTLR
+static u64 swap_cgroup_read(struct cgroup *cont, struct cftype *cft)
+{
+	return res_counter_read_u64(&mem_cgroup_from_cont(cont)->swap_res,
+				    cft->private);
+}
+
+static ssize_t swap_cgroup_write(struct cgroup *cont, struct cftype *cft,
+				struct file *file, const char __user *userbuf,
+				size_t nbytes, loff_t *ppos)
+{
+	return res_counter_write(&mem_cgroup_from_cont(cont)->swap_res,
+				cft->private, userbuf, nbytes, ppos,
+				mem_cgroup_write_strategy);
+}
+
+static int swap_cgroup_reset(struct cgroup *cont, unsigned int event)
+{
+	struct mem_cgroup *mem;
+
+	mem = mem_cgroup_from_cont(cont);
+	switch (event) {
+	case RES_MAX_USAGE:
+		res_counter_reset_max(&mem->swap_res);
+		break;
+	case RES_FAILCNT:
+		res_counter_reset_failcnt(&mem->swap_res);
+		break;
+	}
+	return 0;
+}
+#endif
+
 static struct cftype mem_cgroup_files[] = {
 	{
 		.name = "usage_in_bytes",
@@ -992,6 +1031,31 @@ static struct cftype mem_cgroup_files[] = {
 		.name = "stat",
 		.read_map = mem_control_stat_show,
 	},
+#ifdef CONFIG_CGROUP_SWAP_RES_CTLR
+	{
+		.name = "swap_usage_in_bytes",
+		.private = RES_USAGE,
+		.read_u64 = swap_cgroup_read,
+	},
+	{
+		.name = "swap_max_usage_in_bytes",
+		.private = RES_MAX_USAGE,
+		.trigger = swap_cgroup_reset,
+		.read_u64 = swap_cgroup_read,
+	},
+	{
+		.name = "swap_limit_in_bytes",
+		.private = RES_LIMIT,
+		.write = swap_cgroup_write,
+		.read_u64 = swap_cgroup_read,
+	},
+	{
+		.name = "swap_failcnt",
+		.private = RES_FAILCNT,
+		.trigger = swap_cgroup_reset,
+		.read_u64 = swap_cgroup_read,
+	},
+#endif
 };
 
 static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
@@ -1069,6 +1133,9 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
 	}
 
 	res_counter_init(&mem->res);
+#ifdef CONFIG_CGROUP_SWAP_RES_CTLR
+	res_counter_init(&mem->swap_res);
+#endif
 
 	for_each_node_state(node, N_POSSIBLE)
 		if (alloc_mem_cgroup_per_zone_info(mem, node))


--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2008-05-22  6:17 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22  6:13 [PATCH 0/4] swapcgroup(v2) Daisuke Nishimura
2008-05-22  6:17 ` Daisuke Nishimura [this message]
2008-05-22  6:18 ` [PATCH 2/4] swapcgroup: add member to swap_info_struct for cgroup Daisuke Nishimura
2008-05-22  7:23   ` KAMEZAWA Hiroyuki
2008-05-22  8:46     ` Daisuke Nishimura
2008-05-22  9:35       ` KAMEZAWA Hiroyuki
2008-05-22  6:20 ` [PATCH 3/4] swapcgroup: implement charge/uncharge Daisuke Nishimura
2008-05-22  7:37   ` KAMEZAWA Hiroyuki
2008-05-23 11:52     ` Daisuke Nishimura
2008-05-26  0:57       ` KAMEZAWA Hiroyuki
2008-05-27 13:42         ` KAMEZAWA Hiroyuki
2008-05-22  6:22 ` [PATCH 4/4] swapcgroup: modify vm_swap_full for cgroup Daisuke Nishimura
2008-05-22  6:45   ` YAMAMOTO Takashi
2008-05-22 12:34     ` Daisuke Nishimura
2008-05-25 23:35       ` YAMAMOTO Takashi
2008-05-22  7:39   ` KAMEZAWA Hiroyuki
2008-05-22  8:00   ` KOSAKI Motohiro
2008-05-22 12:22     ` Daisuke Nishimura
2008-05-22 12:32       ` KOSAKI Motohiro
2008-05-23 12:26         ` Daisuke Nishimura
2008-05-22  7:44 ` [PATCH 0/4] swapcgroup(v2) KAMEZAWA Hiroyuki
2008-05-23  2:10   ` Daisuke Nishimura
2008-05-23  2:42     ` Daisuke Nishimura
2008-05-22 21:27 ` Balbir Singh
2008-05-23  4:27   ` Daisuke Nishimura
2008-05-27  7:31     ` YAMAMOTO Takashi
2008-05-27  7:42       ` Balbir Singh
2008-05-27  8:30         ` Daisuke Nishimura
2008-05-27 13:18           ` Balbir Singh
2008-05-27 13:42             ` Daisuke Nishimura
2008-05-27 13:46               ` Balbir Singh
2008-05-27 14:00                 ` Daisuke Nishimura
2008-05-23  2:26 ` Rik van Riel
2008-05-23  3:10   ` KAMEZAWA Hiroyuki
2008-05-23  3:32     ` Rik van Riel
2008-05-23  3:59     ` Balbir Singh
2008-05-23  4:30       ` KOSAKI Motohiro
2008-05-23  4:51         ` Balbir Singh
2008-05-23  5:23           ` KAMEZAWA Hiroyuki
2008-05-23  5:29           ` David Singleton
2008-05-23  6:00             ` KOSAKI Motohiro
2008-05-23  6:45               ` Balbir Singh

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=48350FF6.4040801@mxp.nes.nec.co.jp \
    --to=nishimura@mxp.nes.nec.co.jp \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=hugh@veritas.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=m-ikeda@ds.jp.nec.com \
    --cc=xemul@openvz.org \
    --cc=yamamoto@valinux.co.jp \
    /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