From: Jeff Liu <jeff.liu@oracle.com>
To: linux-mm@kvack.org
Cc: cgroups@vger.kernel.org, Glauber Costa <glommer@parallels.com>
Subject: [RFC PATCH 1/3] memcg: refactor pages allocation/free for swap_cgroup
Date: Tue, 04 Dec 2012 16:35:55 +0800 [thread overview]
Message-ID: <50BDB5EB.70909@oracle.com> (raw)
- Rename swap_cgroup_prepare to swap_cgroup_alloc_pages()
- Introduce a new helper swap_cgroup_free_pages() to free
pages from swap cgroup upon a given type.
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
CC: Glauber Costa <glommer@parallels.com>
CC: Michal Hocko <mhocko@suse.cz>
CC: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
CC: Johannes Weiner <hannes@cmpxchg.org>
CC: Mel Gorman <mgorman@suse.de>
CC: Andrew Morton <akpm@linux-foundation.org>
---
mm/page_cgroup.c | 44 ++++++++++++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 12 deletions(-)
diff --git a/mm/page_cgroup.c b/mm/page_cgroup.c
index 5ddad0c..76b1344 100644
--- a/mm/page_cgroup.c
+++ b/mm/page_cgroup.c
@@ -348,31 +348,51 @@ struct swap_cgroup {
*/
/*
- * allocate buffer for swap_cgroup.
+ * Allocate pages for swap_cgroup upon a given type.
*/
-static int swap_cgroup_prepare(int type)
+static int swap_cgroup_alloc_pages(int type)
{
- struct page *page;
struct swap_cgroup_ctrl *ctrl;
- unsigned long idx, max;
+ unsigned long i, length, max;
ctrl = &swap_cgroup_ctrl[type];
-
- for (idx = 0; idx < ctrl->length; idx++) {
- page = alloc_page(GFP_KERNEL | __GFP_ZERO);
+ length = ctrl->length;
+ for (i = 0; i < length; i++) {
+ struct page *page = alloc_page(GFP_KERNEL | __GFP_ZERO);
if (!page)
goto not_enough_page;
- ctrl->map[idx] = page;
+ ctrl->map[i] = page;
}
+
return 0;
+
not_enough_page:
- max = idx;
- for (idx = 0; idx < max; idx++)
- __free_page(ctrl->map[idx]);
+ max = i;
+ for (i = 0; i < max; i++)
+ __free_page(ctrl->map[i]);
return -ENOMEM;
}
+static void swap_cgroup_free_pages(int type)
+{
+ struct swap_cgroup_ctrl *ctrl;
+ struct page **map;
+
+ ctrl = &swap_cgroup_ctrl[type];
+ map = ctrl->map;
+ if (map) {
+ unsigned long length = ctrl->length;
+ unsigned long i;
+
+ for (i = 0; i < length; i++) {
+ struct page *page = map[i];
+ if (page)
+ __free_page(page);
+ }
+ }
+}
+
static struct swap_cgroup *lookup_swap_cgroup(swp_entry_t ent,
struct swap_cgroup_ctrl **ctrlp)
{
@@ -477,7 +497,7 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
ctrl->length = length;
ctrl->map = array;
spin_lock_init(&ctrl->lock);
- if (swap_cgroup_prepare(type)) {
+ if (swap_cgroup_alloc_pages(type)) {
/* memory shortage */
ctrl->map = NULL;
ctrl->length = 0;
--
1.7.9.5
--
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 reply other threads:[~2012-12-04 8:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-04 8:35 [RFC PATCH 0/3] Disable swap cgroup allocation at system boot stage Jeff Liu
2012-12-04 8:35 ` Jeff Liu [this message]
2012-12-04 10:11 ` [RFC PATCH 1/3] memcg: refactor pages allocation/free for swap_cgroup Michal Hocko
2012-12-04 10:46 ` Jeff Liu
2012-12-04 8:36 ` [RFC PATCH 2/3] memcg: disable pages allocation for swap cgroup on system booting up Jeff Liu
2012-12-04 11:17 ` Michal Hocko
[not found] ` <20121204111721.GB1343-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2012-12-04 11:22 ` Michal Hocko
2012-12-04 11:22 ` Michal Hocko
2012-12-04 12:34 ` Michal Hocko
2012-12-04 12:34 ` Michal Hocko
2012-12-04 12:51 ` Jeff Liu
2012-12-04 8:36 ` [RFC PATCH 3/3] memcg: allocate pages for swap cgroup until the first child memcg is alive Jeff Liu
[not found] ` <50BDB601.4090205-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-12-04 12:54 ` Michal Hocko
2012-12-04 12:54 ` Michal Hocko
2012-12-04 13:14 ` Jeff Liu
[not found] ` <50BDB5E0.7030906-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2012-12-04 13:18 ` [RFC PATCH 0/3] Disable swap cgroup allocation at system boot stage Michal Hocko
2012-12-04 13:18 ` Michal Hocko
2012-12-04 14:00 ` Jeff Liu
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=50BDB5EB.70909@oracle.com \
--to=jeff.liu@oracle.com \
--cc=cgroups@vger.kernel.org \
--cc=glommer@parallels.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.