aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorJesper Juhl <jj@chaosbits.net>2011-01-13 18:47:42 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 20:32:51 -0500
commit17295c88a160c6eea3fcf46cec9d08a0fcb02db9 (patch)
tree35fe45824b5ddd6d406d2d7d7562438a4725e57e /mm
parentdfe076b0971a783469bc2066e85d46e23c8acb1c (diff)
memcg: use [kv]zalloc[_node] rather than [kv]malloc+memset
In mem_cgroup_alloc() we currently do either kmalloc() or vmalloc() then followed by memset() to zero the memory. This can be more efficiently achieved by using kzalloc() and vzalloc(). There's also one situation where we can use kzalloc_node() - this is what's new in this version of the patch. Signed-off-by: Jesper Juhl <jj@chaosbits.net> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Minchan Kim <minchan.kim@gmail.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Cc: Balbir Singh <balbir@linux.vnet.ibm.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/memcontrol.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index c339d7431bda..6424ba0fce83 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4216,13 +4216,11 @@ static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
4216 */ 4216 */
4217 if (!node_state(node, N_NORMAL_MEMORY)) 4217 if (!node_state(node, N_NORMAL_MEMORY))
4218 tmp = -1; 4218 tmp = -1;
4219 pn = kmalloc_node(sizeof(*pn), GFP_KERNEL, tmp); 4219 pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp);
4220 if (!pn) 4220 if (!pn)
4221 return 1; 4221 return 1;
4222 4222
4223 mem->info.nodeinfo[node] = pn; 4223 mem->info.nodeinfo[node] = pn;
4224 memset(pn, 0, sizeof(*pn));
4225
4226 for (zone = 0; zone < MAX_NR_ZONES; zone++) { 4224 for (zone = 0; zone < MAX_NR_ZONES; zone++) {
4227 mz = &pn->zoneinfo[zone]; 4225 mz = &pn->zoneinfo[zone];
4228 for_each_lru(l) 4226 for_each_lru(l)
@@ -4246,14 +4244,13 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
4246 4244
4247 /* Can be very big if MAX_NUMNODES is very big */ 4245 /* Can be very big if MAX_NUMNODES is very big */
4248 if (size < PAGE_SIZE) 4246 if (size < PAGE_SIZE)
4249 mem = kmalloc(size, GFP_KERNEL); 4247 mem = kzalloc(size, GFP_KERNEL);
4250 else 4248 else
4251 mem = vmalloc(size); 4249 mem = vzalloc(size);
4252 4250
4253 if (!mem) 4251 if (!mem)
4254 return NULL; 4252 return NULL;
4255 4253
4256 memset(mem, 0, size);
4257 mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu); 4254 mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu);
4258 if (!mem->stat) 4255 if (!mem->stat)
4259 goto out_free; 4256 goto out_free;