Commit 17295c88a160c6eea3fcf46cec9d08a0fcb02db9
Committed by
Linus Torvalds
1 parent
dfe076b097
Exists in
master
and in
4 other branches
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>
Showing 1 changed file with 3 additions and 6 deletions Side-by-side Diff
mm/memcontrol.c
... | ... | @@ -4216,13 +4216,11 @@ |
4216 | 4216 | */ |
4217 | 4217 | if (!node_state(node, N_NORMAL_MEMORY)) |
4218 | 4218 | tmp = -1; |
4219 | - pn = kmalloc_node(sizeof(*pn), GFP_KERNEL, tmp); | |
4219 | + pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp); | |
4220 | 4220 | if (!pn) |
4221 | 4221 | return 1; |
4222 | 4222 | |
4223 | 4223 | mem->info.nodeinfo[node] = pn; |
4224 | - memset(pn, 0, sizeof(*pn)); | |
4225 | - | |
4226 | 4224 | for (zone = 0; zone < MAX_NR_ZONES; zone++) { |
4227 | 4225 | mz = &pn->zoneinfo[zone]; |
4228 | 4226 | for_each_lru(l) |
4229 | 4227 | |
4230 | 4228 | |
... | ... | @@ -4246,14 +4244,13 @@ |
4246 | 4244 | |
4247 | 4245 | /* Can be very big if MAX_NUMNODES is very big */ |
4248 | 4246 | if (size < PAGE_SIZE) |
4249 | - mem = kmalloc(size, GFP_KERNEL); | |
4247 | + mem = kzalloc(size, GFP_KERNEL); | |
4250 | 4248 | else |
4251 | - mem = vmalloc(size); | |
4249 | + mem = vzalloc(size); | |
4252 | 4250 | |
4253 | 4251 | if (!mem) |
4254 | 4252 | return NULL; |
4255 | 4253 | |
4256 | - memset(mem, 0, size); | |
4257 | 4254 | mem->stat = alloc_percpu(struct mem_cgroup_stat_cpu); |
4258 | 4255 | if (!mem->stat) |
4259 | 4256 | goto out_free; |