linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
	"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>,
	"kosaki.motohiro@jp.fujitsu.com" <kosaki.motohiro@jp.fujitsu.com>
Subject: [RFC][PATCH 1/4] memcg: add softlimit interface and utilitiy function.
Date: Mon, 9 Mar 2009 16:39:07 +0900	[thread overview]
Message-ID: <20090309163907.a3cee183.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20090309163745.5e3805ba.kamezawa.hiroyu@jp.fujitsu.com>

From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Adds an interface for defining sotlimit per memcg. (no handler in this patch.)
softlimit.priority and queue for softlimit is added in the next patch.


Changelog v1->v2:
 - For refactoring, divided a patch into 2 part and this patch just
   involves memory.softlimit interface.
 - Removed governor-detect routine, it was buggy in design.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
 mm/memcontrol.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 2 deletions(-)

Index: develop/mm/memcontrol.c
===================================================================
--- develop.orig/mm/memcontrol.c
+++ develop/mm/memcontrol.c
@@ -175,7 +175,10 @@ struct mem_cgroup {
 	atomic_t	refcnt;
 
 	unsigned int	swappiness;
-
+	/*
+	 * Softlimit Params.
+	 */
+	u64		softlimit;
 	/*
 	 * statistics. This must be placed at the end of memcg.
 	 */
@@ -210,6 +213,8 @@ pcg_default_flags[NR_CHARGE_TYPE] = {
 #define MEMFILE_TYPE(val)	(((val) >> 16) & 0xffff)
 #define MEMFILE_ATTR(val)	((val) & 0xffff)
 
+#define _MEM_SOFTLIMIT		(0x10)
+
 static void mem_cgroup_get(struct mem_cgroup *mem);
 static void mem_cgroup_put(struct mem_cgroup *mem);
 static struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *mem);
@@ -1900,6 +1905,39 @@ int mem_cgroup_force_empty_write(struct 
 	return mem_cgroup_force_empty(mem_cgroup_from_cont(cont), true);
 }
 
+/*
+ * Softlimit Handling.
+ */
+
+/*
+ * A group under hierarchy has to check all ancestors.
+ * css's refcnt of "mem" should be in caller.
+ */
+static bool mem_cgroup_hit_softlimit(struct mem_cgroup *mem, void *data)
+{
+	struct mem_cgroup *tmp = mem;
+	struct cgroup *cg;
+	u64 usage;
+
+	do {
+		usage = res_counter_read_u64(&tmp->res, RES_USAGE);
+		if (tmp->res.usage > tmp->softlimit)
+			return true;
+		cg = tmp->css.cgroup;
+		if (!cg->parent)
+			break;
+		tmp = mem_cgroup_from_cont(cg);
+	} while (!tmp->use_hierarchy);
+
+	return false;
+}
+
+static int mem_cgroup_resize_softlimit(struct mem_cgroup *mem, u64 val)
+{
+	mem->softlimit = val;
+	return 0;
+}
+
 
 static u64 mem_cgroup_hierarchy_read(struct cgroup *cont, struct cftype *cft)
 {
@@ -1949,7 +1987,14 @@ static u64 mem_cgroup_read(struct cgroup
 	name = MEMFILE_ATTR(cft->private);
 	switch (type) {
 	case _MEM:
-		val = res_counter_read_u64(&mem->res, name);
+		switch (name) {
+		case _MEM_SOFTLIMIT:
+			val = mem->softlimit;
+			break;
+		default:
+			val = res_counter_read_u64(&mem->res, name);
+			break;
+		}
 		break;
 	case _MEMSWAP:
 		if (do_swap_account)
@@ -1986,6 +2031,12 @@ static int mem_cgroup_write(struct cgrou
 		else
 			ret = mem_cgroup_resize_memsw_limit(memcg, val);
 		break;
+	case _MEM_SOFTLIMIT:
+		ret = res_counter_memparse_write_strategy(buffer, &val);
+		if (ret)
+			break;
+		ret = mem_cgroup_resize_softlimit(memcg, val);
+		break;
 	default:
 		ret = -EINVAL; /* should be BUG() ? */
 		break;
@@ -2235,6 +2286,12 @@ static struct cftype mem_cgroup_files[] 
 		.read_u64 = mem_cgroup_read,
 	},
 	{
+		.name = "softlimit_in_bytes",
+		.private = MEMFILE_PRIVATE(_MEM, _MEM_SOFTLIMIT),
+		.write_string = mem_cgroup_write,
+		.read_u64 = mem_cgroup_read,
+	},
+	{
 		.name = "failcnt",
 		.private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT),
 		.trigger = mem_cgroup_reset,
@@ -2460,6 +2517,7 @@ mem_cgroup_create(struct cgroup_subsys *
 	}
 	mem->last_scanned_child = 0;
 	spin_lock_init(&mem->reclaim_param_lock);
+	mem->softlimit = ULLONG_MAX;
 
 	if (parent)
 		mem->swappiness = get_swappiness(parent);

--
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:[~2009-03-09  7:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-09  7:37 [RFC][PATCH] memcg: softlimit (Another one) v3 KAMEZAWA Hiroyuki
2009-03-09  7:39 ` KAMEZAWA Hiroyuki [this message]
2009-03-09  7:44   ` [RFC][PATCH 1/4] memcg: add softlimit interface and utilitiy function Balbir Singh
2009-03-09  7:55     ` KAMEZAWA Hiroyuki
2009-03-09  8:48       ` Balbir Singh
2009-03-10  5:53         ` KAMEZAWA Hiroyuki
2009-03-10  8:03           ` Balbir Singh
2009-03-10  8:31           ` Balbir Singh
2009-03-09  8:29     ` KAMEZAWA Hiroyuki
2009-03-09  8:54       ` Balbir Singh
2009-03-09  9:07         ` KAMEZAWA Hiroyuki
2009-03-09  7:41 ` [RFC][PATCH 2/4] memcg: softlimit priority and victim scheduler KAMEZAWA Hiroyuki
2009-03-09  7:42 ` [RFC][PATCH 3/4] memcg: softlimit caller via kswapd KAMEZAWA Hiroyuki
2009-03-10 19:02   ` Balbir Singh
2009-03-10 23:52     ` KAMEZAWA Hiroyuki
2009-03-12  0:05     ` KOSAKI Motohiro
2009-03-12  0:08       ` KAMEZAWA Hiroyuki
2009-03-09  7:43 ` [RFC][PATCH 4/4] memcg: softlimit documenation 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=20090309163907.a3cee183.kamezawa.hiroyu@jp.fujitsu.com \
    --to=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=nishimura@mxp.nes.nec.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