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>,
LKML <linux-kernel@vger.kernel.org>,
"menage@google.com" <menage@google.com>,
"balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
"xemul@openvz.org" <xemul@openvz.org>,
"yamamoto@valinux.co.jp" <yamamoto@valinux.co.jp>,
"nishimura@mxp.nes.nec.co.jp" <nishimura@mxp.nes.nec.co.jp>,
"lizf@cn.fujitsu.com" <lizf@cn.fujitsu.com>
Subject: [PATCH 2/6] memcg: handle limit change
Date: Fri, 13 Jun 2008 18:30:15 +0900 [thread overview]
Message-ID: <20080613183015.e2b67415.kamezawa.hiroyu@jp.fujitsu.com> (raw)
In-Reply-To: <20080613182714.265fe6d2.kamezawa.hiroyu@jp.fujitsu.com>
Add callback for resize_limit().
After this patch, memcg's usage will be reduced to new limit.
If it cannot, -EBUSY will be return to write() syscall.
And this patch tries to free all pages at force_empty by reusing
shrink function.
Change log: xxx -> v4
- cut out from memcg hierarhcy patch set.
- added retry_count as new arguments.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
Documentation/controllers/memory.txt | 3 --
mm/memcontrol.c | 47 ++++++++++++++++++++++++++++++++---
2 files changed, 45 insertions(+), 5 deletions(-)
Index: linux-2.6.26-rc5-mm3/mm/memcontrol.c
===================================================================
--- linux-2.6.26-rc5-mm3.orig/mm/memcontrol.c
+++ linux-2.6.26-rc5-mm3/mm/memcontrol.c
@@ -779,6 +779,44 @@ int mem_cgroup_shrink_usage(struct mm_st
}
/*
+ * A callback for shrinking limit, Always GFP_KERNEL.
+ */
+int mem_cgroup_shrink_usage_to(struct res_counter *res, unsigned long long val,
+ int retry_count)
+{
+ struct mem_cgroup *memcg = container_of(res, struct mem_cgroup, res);
+
+ if (retry_count > MEM_CGROUP_RECLAIM_RETRIES)
+ return -EBUSY;
+
+retry:
+ if (res_counter_check_under_val(res, val))
+ return 0;
+
+ cond_resched();
+ if (try_to_free_mem_cgroup_pages(memcg, GFP_KERNEL) == 0)
+ return 0; /* no progress...*/
+
+ goto retry;
+}
+
+/*
+ * Must be called under there is no users on this cgroup.
+ */
+static void memcg_shrink_usage_all(struct mem_cgroup *memcg)
+{
+ int retry_count = 0;
+ int ret = 0;
+
+ while (!ret && !res_counter_check_under_val(&memcg->res, 0)) {
+ ret = mem_cgroup_shrink_usage_to(&memcg->res, 0, retry_count);
+ retry_count++;
+ }
+
+ return;
+}
+
+/*
* This routine traverse page_cgroup in given list and drop them all.
* *And* this routine doesn't reclaim page itself, just removes page_cgroup.
*/
@@ -835,9 +873,10 @@ static int mem_cgroup_force_empty(struct
* active_list <-> inactive_list while we don't take a lock.
* So, we have to do loop here until all lists are empty.
*/
- while (mem->res.usage > 0) {
+ while (!res_counter_check_under_val(&mem->res, 0)) {
if (atomic_read(&mem->css.cgroup->count) > 0)
goto out;
+ memcg_shrink_usage_all(mem);
for_each_node_state(node, N_POSSIBLE)
for (zid = 0; zid < MAX_NR_ZONES; zid++) {
struct mem_cgroup_per_zone *mz;
@@ -1046,13 +1085,15 @@ static void mem_cgroup_free(struct mem_c
vfree(mem);
}
+struct res_counter_ops root_ops = {
+ .shrink_usage = mem_cgroup_shrink_usage_to,
+};
static struct cgroup_subsys_state *
mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
{
struct mem_cgroup *mem;
int node;
-
if (unlikely((cont->parent) == NULL)) {
mem = &init_mem_cgroup;
page_cgroup_cache = KMEM_CACHE(page_cgroup, SLAB_PANIC);
@@ -1062,7 +1103,7 @@ mem_cgroup_create(struct cgroup_subsys *
return ERR_PTR(-ENOMEM);
}
- res_counter_init(&mem->res);
+ res_counter_init_ops(&mem->res, &root_ops);
for_each_node_state(node, N_POSSIBLE)
if (alloc_mem_cgroup_per_zone_info(mem, node))
Index: linux-2.6.26-rc5-mm3/Documentation/controllers/memory.txt
===================================================================
--- linux-2.6.26-rc5-mm3.orig/Documentation/controllers/memory.txt
+++ linux-2.6.26-rc5-mm3/Documentation/controllers/memory.txt
@@ -242,8 +242,7 @@ rmdir() if there are no tasks.
1. Add support for accounting huge pages (as a separate controller)
2. Make per-cgroup scanner reclaim not-shared pages first
3. Teach controller to account for shared-pages
-4. Start reclamation when the limit is lowered
-5. Start reclamation in the background when the limit is
+4. Start reclamation in the background when the limit is
not yet hit but the usage is getting closer
Summary
--
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:[~2008-06-13 9:30 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-13 9:27 [PATCH 0/6] memcg: hierarchy updates (v4) KAMEZAWA Hiroyuki
2008-06-13 9:29 ` [PATCH 1/6] res_counter: handle limit change KAMEZAWA Hiroyuki
2008-06-16 6:38 ` Pavel Emelyanov
2008-06-16 7:39 ` kamezawa.hiroyu
2008-06-16 7:51 ` Pavel Emelyanov
2008-06-16 8:17 ` kamezawa.hiroyu
2008-06-16 8:23 ` Pavel Emelyanov
2008-06-16 8:32 ` kamezawa.hiroyu
2008-06-16 8:47 ` Pavel Emelyanov
2008-06-16 9:01 ` kamezawa.hiroyu
2008-06-16 8:53 ` kamezawa.hiroyu
2008-06-16 9:00 ` Pavel Emelyanov
2008-06-16 8:57 ` Balbir Singh
2008-06-16 8:59 ` Pavel Emelyanov
2008-06-16 9:04 ` kamezawa.hiroyu
2008-06-16 12:29 ` Balbir Singh
2008-06-16 13:26 ` kamezawa.hiroyu
2008-06-20 5:09 ` Paul Menage
2008-06-23 22:40 ` Randy Dunlap
2008-06-13 9:30 ` KAMEZAWA Hiroyuki [this message]
2008-06-13 9:31 ` [PATCH 3/6] memcg: reset limit at rmdir KAMEZAWA Hiroyuki
2008-06-13 9:34 ` [PATCH 4/6] res_counter: basic hierarchy support KAMEZAWA Hiroyuki
2008-06-23 22:37 ` Randy Dunlap
2008-06-13 9:36 ` [PATCH 5/6] res_counter: HARDWALL hierarchy KAMEZAWA Hiroyuki
2008-06-13 9:37 ` [PATCH 6/6] memcg: " KAMEZAWA Hiroyuki
2008-06-23 22:29 ` Randy Dunlap
2008-06-24 3:37 ` 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=20080613183015.e2b67415.kamezawa.hiroyu@jp.fujitsu.com \
--to=kamezawa.hiroyu@jp.fujitsu.com \
--cc=balbir@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=nishimura@mxp.nes.nec.co.jp \
--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