From: Michal Hocko <mhocko@suse.cz>
To: Jeff Liu <jeff.liu@oracle.com>
Cc: linux-mm@kvack.org, Glauber Costa <glommer@parallels.com>,
cgroups@vger.kernel.org
Subject: Re: [PATCH v2 1/6] memcg: refactor swap_cgroup_swapon()
Date: Tue, 29 Jan 2013 14:41:37 +0100 [thread overview]
Message-ID: <20130129134137.GB29574@dhcp22.suse.cz> (raw)
In-Reply-To: <510658E6.9030108@oracle.com>
On Mon 28-01-13 18:54:30, Jeff Liu wrote:
> Refector swap_cgroup_swapon() to setup the number of pages only, and
> move the rest to swap_cgroup_prepare(), so that the later can be used
> for allocating buffers when creating the first non-root memcg.
>
> 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>
> CC: Sha Zhengju <handai.szj@taobao.com>
Makes sense and it even saves some lines.
Acked-by: Michal Hocko <mhocko@suse.cz>
>
> ---
> mm/page_cgroup.c | 17 ++++++-----------
> 1 file changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/mm/page_cgroup.c b/mm/page_cgroup.c
> index 6d757e3..c945254 100644
> --- a/mm/page_cgroup.c
> +++ b/mm/page_cgroup.c
> @@ -360,6 +360,9 @@ static int swap_cgroup_prepare(int type)
> unsigned long idx, max;
>
> ctrl = &swap_cgroup_ctrl[type];
> + ctrl->map = vzalloc(ctrl->length * sizeof(void *));
> + if (!ctrl->map)
> + goto nomem;
>
> for (idx = 0; idx < ctrl->length; idx++) {
> page = alloc_page(GFP_KERNEL | __GFP_ZERO);
> @@ -368,11 +371,13 @@ static int swap_cgroup_prepare(int type)
> ctrl->map[idx] = page;
> }
> return 0;
> +
> not_enough_page:
> max = idx;
> for (idx = 0; idx < max; idx++)
> __free_page(ctrl->map[idx]);
> -
> + ctrl->map = NULL;
> +nomem:
> return -ENOMEM;
> }
>
> @@ -460,8 +465,6 @@ unsigned short lookup_swap_cgroup_id(swp_entry_t ent)
>
> int swap_cgroup_swapon(int type, unsigned long max_pages)
> {
> - void *array;
> - unsigned long array_size;
> unsigned long length;
> struct swap_cgroup_ctrl *ctrl;
>
> @@ -469,23 +472,15 @@ int swap_cgroup_swapon(int type, unsigned long max_pages)
> return 0;
>
> length = DIV_ROUND_UP(max_pages, SC_PER_PAGE);
> - array_size = length * sizeof(void *);
> -
> - array = vzalloc(array_size);
> - if (!array)
> - goto nomem;
>
> ctrl = &swap_cgroup_ctrl[type];
> mutex_lock(&swap_cgroup_mutex);
> ctrl->length = length;
> - ctrl->map = array;
> spin_lock_init(&ctrl->lock);
> if (swap_cgroup_prepare(type)) {
> /* memory shortage */
> - ctrl->map = NULL;
> ctrl->length = 0;
> mutex_unlock(&swap_cgroup_mutex);
> - vfree(array);
> goto nomem;
> }
> mutex_unlock(&swap_cgroup_mutex);
> --
> 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>
--
Michal Hocko
SUSE Labs
--
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:[~2013-01-29 13:41 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-28 10:54 [PATCH v2 0/6] memcg: disable swap cgroup allocation at swapon Jeff Liu
2013-01-28 10:54 ` [PATCH v2 1/6] memcg: refactor swap_cgroup_swapon() Jeff Liu
2013-01-29 9:15 ` Lord Glauber Costa of Sealand
2013-01-29 13:41 ` Michal Hocko [this message]
2013-01-28 10:54 ` [PATCH v2 2/6] memcg: bypass swap accounting for the root memcg Jeff Liu
2013-01-29 10:18 ` Lord Glauber Costa of Sealand
2013-01-31 6:18 ` Jeff Liu
2013-01-29 14:13 ` Michal Hocko
2013-01-30 16:01 ` Jeff Liu
2013-01-30 16:29 ` Michal Hocko
2013-01-31 4:00 ` Jeff Liu
2013-01-28 10:54 ` [PATCH v2 3/6] memcg: introduce memsw_accounting_users Jeff Liu
2013-01-29 9:46 ` Lord Glauber Costa of Sealand
2013-01-29 10:52 ` Jeff Liu
2013-01-29 14:26 ` Michal Hocko
2013-01-29 14:24 ` Michal Hocko
2013-01-29 15:16 ` Jeff Liu
2013-01-28 10:54 ` [PATCH v2 4/6] memcg: export nr_swap_files Jeff Liu
2013-01-29 9:47 ` Lord Glauber Costa of Sealand
2013-01-29 14:31 ` Michal Hocko
2013-01-29 15:17 ` Jeff Liu
2013-01-28 10:54 ` [PATCH v2 5/6] memcg: introduce swap_cgroup_init()/swap_cgroup_free() Jeff Liu
2013-01-29 9:57 ` Lord Glauber Costa of Sealand
2013-01-29 10:21 ` Jeff Liu
2013-01-29 14:56 ` Michal Hocko
2013-01-29 15:51 ` Jeff Liu
2013-01-29 16:09 ` Michal Hocko
2013-01-28 10:54 ` [PATCH v2 6/6] memcg: init/free swap cgroup strucutres upon create/free child memcg Jeff Liu
2013-01-29 9:59 ` Lord Glauber Costa of Sealand
2013-01-29 10:27 ` Jeff Liu
2013-01-29 15:11 ` Michal Hocko
2013-01-29 15:15 ` [PATCH v2 0/6] memcg: disable swap cgroup allocation at swapon Michal Hocko
2013-01-29 16:50 ` 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=20130129134137.GB29574@dhcp22.suse.cz \
--to=mhocko@suse.cz \
--cc=cgroups@vger.kernel.org \
--cc=glommer@parallels.com \
--cc=jeff.liu@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).