All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	"xemul@openvz.org" <xemul@openvz.org>,
	lizf@cn.fujitsu.com, menage@google.com,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] use vmalloc for mem_cgroup allocation. v2
Date: Mon, 14 Apr 2008 19:17:30 -0700	[thread overview]
Message-ID: <20080414191730.7d13e619.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080415111038.ffac0e12.kamezawa.hiroyu@jp.fujitsu.com>

On Tue, 15 Apr 2008 11:10:38 +0900 KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:

> On ia64, this kmalloc() requires order-4 pages. But this is not
> necessary to be phisically contiguous. (and x86-32, which has
> small vmalloc area, has small mem_cgroup struct.)
> 
> For here, vmalloc is better.
> 
> Changelog: v1->v2
>  - added memset().
> 
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> 
> Index: mm-2.6.25-rc8-mm2/mm/memcontrol.c
> ===================================================================
> --- mm-2.6.25-rc8-mm2.orig/mm/memcontrol.c
> +++ mm-2.6.25-rc8-mm2/mm/memcontrol.c
> @@ -31,6 +31,7 @@
>  #include <linux/spinlock.h>
>  #include <linux/fs.h>
>  #include <linux/seq_file.h>
> +#include <linux/vmalloc.h>
>  
>  #include <asm/uaccess.h>
>  
> @@ -992,8 +993,10 @@ mem_cgroup_create(struct cgroup_subsys *
>  	if (unlikely((cont->parent) == NULL)) {
>  		mem = &init_mem_cgroup;
>  		page_cgroup_cache = KMEM_CACHE(page_cgroup, SLAB_PANIC);
> -	} else
> -		mem = kzalloc(sizeof(struct mem_cgroup), GFP_KERNEL);
> +	} else {
> +		mem = vmalloc(sizeof(struct mem_cgroup));
> +		memset(mem, 0, sizeof(*mem));
> +	}
>  
>  	if (mem == NULL)
>  		return ERR_PTR(-ENOMEM);
> @@ -1011,7 +1014,7 @@ free_out:
>  	for_each_node_state(node, N_POSSIBLE)
>  		free_mem_cgroup_per_zone_info(mem, node);
>  	if (cont->parent != NULL)
> -		kfree(mem);
> +		vfree(mem);
>  	return ERR_PTR(-ENOMEM);
>  }
>  
> @@ -1031,7 +1034,7 @@ static void mem_cgroup_destroy(struct cg
>  	for_each_node_state(node, N_POSSIBLE)
>  		free_mem_cgroup_per_zone_info(mem, node);
>  
> -	kfree(mem_cgroup_from_cont(cont));
> +	vfree(mem_cgroup_from_cont(cont));
>  }
>  
>  static int mem_cgroup_populate(struct cgroup_subsys *ss,

Well...  vmalloced memory is of course a little slower to use - additional
TLB pressure.

Do you think the memcgroup is accessed frequently enough to use vmalloc()
only on those architectures which actually need it?

Because it'd be pretty simple to implement:

	if (sizeof(struct mem_group) > PAGE_SIZE)
		vmalloc()
	else
		kmalloc()

	...

	if (sizeof(struct mem_group) > PAGE_SIZE)
		vfree()
	else
		kfree()

the compiler will optimise away the `if'.

WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: "balbir@linux.vnet.ibm.com" <balbir@linux.vnet.ibm.com>,
	"xemul@openvz.org" <xemul@openvz.org>,
	lizf@cn.fujitsu.com, menage@google.com,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] use vmalloc for mem_cgroup allocation. v2
Date: Mon, 14 Apr 2008 19:17:30 -0700	[thread overview]
Message-ID: <20080414191730.7d13e619.akpm@linux-foundation.org> (raw)
In-Reply-To: <20080415111038.ffac0e12.kamezawa.hiroyu@jp.fujitsu.com>

On Tue, 15 Apr 2008 11:10:38 +0900 KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> wrote:

> On ia64, this kmalloc() requires order-4 pages. But this is not
> necessary to be phisically contiguous. (and x86-32, which has
> small vmalloc area, has small mem_cgroup struct.)
> 
> For here, vmalloc is better.
> 
> Changelog: v1->v2
>  - added memset().
> 
> Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> 
> Index: mm-2.6.25-rc8-mm2/mm/memcontrol.c
> ===================================================================
> --- mm-2.6.25-rc8-mm2.orig/mm/memcontrol.c
> +++ mm-2.6.25-rc8-mm2/mm/memcontrol.c
> @@ -31,6 +31,7 @@
>  #include <linux/spinlock.h>
>  #include <linux/fs.h>
>  #include <linux/seq_file.h>
> +#include <linux/vmalloc.h>
>  
>  #include <asm/uaccess.h>
>  
> @@ -992,8 +993,10 @@ mem_cgroup_create(struct cgroup_subsys *
>  	if (unlikely((cont->parent) == NULL)) {
>  		mem = &init_mem_cgroup;
>  		page_cgroup_cache = KMEM_CACHE(page_cgroup, SLAB_PANIC);
> -	} else
> -		mem = kzalloc(sizeof(struct mem_cgroup), GFP_KERNEL);
> +	} else {
> +		mem = vmalloc(sizeof(struct mem_cgroup));
> +		memset(mem, 0, sizeof(*mem));
> +	}
>  
>  	if (mem == NULL)
>  		return ERR_PTR(-ENOMEM);
> @@ -1011,7 +1014,7 @@ free_out:
>  	for_each_node_state(node, N_POSSIBLE)
>  		free_mem_cgroup_per_zone_info(mem, node);
>  	if (cont->parent != NULL)
> -		kfree(mem);
> +		vfree(mem);
>  	return ERR_PTR(-ENOMEM);
>  }
>  
> @@ -1031,7 +1034,7 @@ static void mem_cgroup_destroy(struct cg
>  	for_each_node_state(node, N_POSSIBLE)
>  		free_mem_cgroup_per_zone_info(mem, node);
>  
> -	kfree(mem_cgroup_from_cont(cont));
> +	vfree(mem_cgroup_from_cont(cont));
>  }
>  
>  static int mem_cgroup_populate(struct cgroup_subsys *ss,

Well...  vmalloced memory is of course a little slower to use - additional
TLB pressure.

Do you think the memcgroup is accessed frequently enough to use vmalloc()
only on those architectures which actually need it?

Because it'd be pretty simple to implement:

	if (sizeof(struct mem_group) > PAGE_SIZE)
		vmalloc()
	else
		kmalloc()

	...

	if (sizeof(struct mem_group) > PAGE_SIZE)
		vfree()
	else
		kfree()

the compiler will optimise away the `if'.

--
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>

  parent reply	other threads:[~2008-04-15  2:23 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-15  1:54 [PATCH] use vmalloc for mem_cgroup allocation KAMEZAWA Hiroyuki
2008-04-15  1:54 ` KAMEZAWA Hiroyuki
2008-04-15  1:57 ` Li Zefan
2008-04-15  1:57   ` Li Zefan
2008-04-15  2:07   ` KAMEZAWA Hiroyuki
2008-04-15  2:07     ` KAMEZAWA Hiroyuki
2008-04-15  2:10 ` [PATCH] use vmalloc for mem_cgroup allocation. v2 KAMEZAWA Hiroyuki
2008-04-15  2:10   ` KAMEZAWA Hiroyuki
2008-04-15  2:08   ` Li Zefan
2008-04-15  2:08     ` Li Zefan
2008-04-15  2:20     ` Andrew Morton
2008-04-15  2:20       ` Andrew Morton
2008-04-15  2:28       ` Harvey Harrison
2008-04-15  2:28         ` Harvey Harrison
2008-04-15  3:12       ` KAMEZAWA Hiroyuki
2008-04-15  3:12         ` KAMEZAWA Hiroyuki
2008-04-15  2:17   ` Andrew Morton [this message]
2008-04-15  2:17     ` Andrew Morton
2008-04-15  3:16     ` KAMEZAWA Hiroyuki
2008-04-15  3:16       ` KAMEZAWA Hiroyuki
2008-04-15  3:14       ` Li Zefan
2008-04-15  3:14         ` Li Zefan
2008-04-15  3:22         ` KAMEZAWA Hiroyuki
2008-04-15  3:22           ` KAMEZAWA Hiroyuki
2008-04-15  5:12 ` [PATCH] use vmalloc for mem_cgroup allocation. v3 KAMEZAWA Hiroyuki
2008-04-15  5:12   ` KAMEZAWA Hiroyuki
2008-04-16 19:19 ` [PATCH] use vmalloc for mem_cgroup allocation Christoph Lameter
2008-04-16 19:19   ` Christoph Lameter

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=20080414191730.7d13e619.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=balbir@linux.vnet.ibm.com \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=menage@google.com \
    --cc=xemul@openvz.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.