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>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
"kosaki.motohiro@jp.fujitsu.com" <kosaki.motohiro@jp.fujitsu.com>
Subject: [RFC][PATCH 5/9] add more hooks and check in lazy manner
Date: Fri, 3 Apr 2009 17:13:49 +0900 [thread overview]
Message-ID: <20090403171349.aa598593.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20090403170835.a2d6cbc3.kamezawa.hiroyu@jp.fujitsu.com>
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Adds 2 more soft limit update hooks.
- uncharge
- write to memory.soft_limit_in_bytes file.
And fixes issues under hierarchy. (This is the most complicated part...)
Because ucharge() can be called under very busy spin_lock, all checks should be
done in lazy. We can use this lazy work to charge() part and make use of it.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
mm/memcontrol.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 55 insertions(+), 11 deletions(-)
Index: softlimit-test2/mm/memcontrol.c
===================================================================
--- softlimit-test2.orig/mm/memcontrol.c
+++ softlimit-test2/mm/memcontrol.c
@@ -200,6 +200,8 @@ struct mem_cgroup {
#define SL_ANON (0)
#define SL_FILE (1)
atomic_t soft_limit_update;
+ struct work_struct soft_limit_work;
+
/*
* statistics. This must be placed at the end of memcg.
*/
@@ -989,6 +991,23 @@ static int mem_cgroup_soft_limit_prio(st
return __calc_soft_limit_prio(max_excess);
}
+static struct mem_cgroup *
+mem_cgroup_soft_limit_need_check(struct mem_cgroup *mem)
+{
+ struct res_counter *c = &mem->res;
+ unsigned long excess, prio;
+
+ do {
+ excess = res_counter_soft_limit_excess(c) >> PAGE_SHIFT;
+ prio = __calc_soft_limit_prio(excess);
+ mem = container_of(c, struct mem_cgroup, res);
+ if (mem->soft_limit_priority != prio)
+ return mem;
+ c = c->parent;
+ } while (c);
+ return NULL;
+}
+
static void __mem_cgroup_requeue(struct mem_cgroup *mem, int prio)
{
/* enqueue to softlimit queue */
@@ -1028,18 +1047,36 @@ __mem_cgroup_update_soft_limit_cb(struct
return 0;
}
-static void mem_cgroup_update_soft_limit(struct mem_cgroup *mem)
+static void mem_cgroup_update_soft_limit_work(struct work_struct *work)
{
- int priority;
+ struct mem_cgroup *mem;
+
+ mem = container_of(work, struct mem_cgroup, soft_limit_work);
+
+ mem_cgroup_walk_tree(mem, NULL, __mem_cgroup_update_soft_limit_cb);
+ atomic_set(&mem->soft_limit_update, 0);
+ css_put(&mem->css);
+}
+
+static void mem_cgroup_update_soft_limit_lazy(struct mem_cgroup *mem)
+{
+ int ret, priority;
+ struct mem_cgroup * root;
+
+ /*
+ * check status change under hierarchy.
+ */
+ root = mem_cgroup_soft_limit_need_check(mem);
+ if (!root)
+ return;
+
+ if (atomic_inc_return(&root->soft_limit_update) > 1)
+ return;
+ css_get(&root->css);
+ ret = schedule_work(&root->soft_limit_work);
+ if (!ret)
+ css_put(&root->css);
- /* check status change */
- priority = mem_cgroup_soft_limit_prio(mem);
- if (priority != mem->soft_limit_priority &&
- atomic_inc_return(&mem->soft_limit_update) > 1) {
- mem_cgroup_walk_tree(mem, NULL,
- __mem_cgroup_update_soft_limit_cb);
- atomic_set(&mem->soft_limit_update, 0);
- }
return;
}
@@ -1145,7 +1182,7 @@ static int __mem_cgroup_try_charge(struc
}
if (soft_fail && mem_cgroup_soft_limit_check(mem))
- mem_cgroup_update_soft_limit(mem);
+ mem_cgroup_update_soft_limit_lazy(mem);
return 0;
nomem:
@@ -1625,6 +1662,9 @@ __mem_cgroup_uncharge_common(struct page
mz = page_cgroup_zoneinfo(pc);
unlock_page_cgroup(pc);
+ if (mem->soft_limit_priority && mem_cgroup_soft_limit_check(mem))
+ mem_cgroup_update_soft_limit_lazy(mem);
+
/* at swapout, this memcg will be accessed to record to swap */
if (ctype != MEM_CGROUP_CHARGE_TYPE_SWAPOUT)
css_put(&mem->css);
@@ -2163,6 +2203,9 @@ static int mem_cgroup_write(struct cgrou
ret = res_counter_set_soft_limit(&memcg->res, val);
else
ret = -EINVAL;
+ if (!ret)
+ mem_cgroup_update_soft_limit_lazy(memcg);
+
break;
default:
ret = -EINVAL; /* should be BUG() ? */
@@ -2648,6 +2691,7 @@ mem_cgroup_create(struct cgroup_subsys *
INIT_LIST_HEAD(&mem->soft_limit_list[SL_ANON]);
INIT_LIST_HEAD(&mem->soft_limit_list[SL_FILE]);
spin_lock_init(&mem->reclaim_param_lock);
+ INIT_WORK(&mem->soft_limit_work, mem_cgroup_update_soft_limit_work);
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>
next prev parent reply other threads:[~2009-04-03 8:15 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-03 8:08 [RFC][PATCH 0/9] memcg soft limit v2 (new design) KAMEZAWA Hiroyuki
2009-04-03 8:09 ` [RFC][PATCH 1/9] " KAMEZAWA Hiroyuki
2009-04-03 8:10 ` [RFC][PATCH 2/9] soft limit framework for memcg KAMEZAWA Hiroyuki
2009-04-03 8:12 ` [RFC][PATCH 3/9] soft limit update filter KAMEZAWA Hiroyuki
2009-04-06 9:43 ` Balbir Singh
2009-04-07 0:04 ` KAMEZAWA Hiroyuki
2009-04-07 2:26 ` Balbir Singh
2009-04-03 8:12 ` [RFC][PATCH 4/9] soft limit queue and priority KAMEZAWA Hiroyuki
2009-04-06 11:05 ` Balbir Singh
2009-04-06 23:55 ` KAMEZAWA Hiroyuki
2009-04-06 18:42 ` Balbir Singh
2009-04-06 23:54 ` KAMEZAWA Hiroyuki
2009-04-03 8:13 ` KAMEZAWA Hiroyuki [this message]
2009-04-03 8:14 ` [RFC][PATCH 6/9] active inactive ratio for private KAMEZAWA Hiroyuki
2009-04-03 8:15 ` [RFC][PATCH 7/9] vicitim selection logic KAMEZAWA Hiroyuki
2009-04-03 8:17 ` [RFC][PATCH 8/9] lru reordering KAMEZAWA Hiroyuki
2009-04-03 8:18 ` [RFC][PATCH 9/9] more event filter depend on priority KAMEZAWA Hiroyuki
2009-04-03 8:24 ` [RFC][PATCH ex/9] for debug KAMEZAWA Hiroyuki
2009-04-06 9:08 ` [RFC][PATCH 0/9] memcg soft limit v2 (new design) Balbir Singh
2009-04-07 0:16 ` KAMEZAWA Hiroyuki
2009-04-24 12:24 ` Balbir Singh
2009-04-24 15:19 ` 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=20090403171349.aa598593.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-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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