1 From: Jan Blunck <jblunck@suse.de>
2 Subject: Dynamically allocate struct mem_cgroup_stat_cpu memory
4 When increasing NR_CPUS to 4096 the size of struct mem_cgroup is growing to
5 507904 bytes per instance on x86_64. This patch changes the allocation of
6 these structures to use nr_cpu_ids instead. Although the init_mem_cgroup still
7 is that huge since it stays statically allocated.
9 Signed-off-by: Jan Blunck <jblunck@suse.de>
11 mm/memcontrol.c | 49 +++++++++++++++++++++++++++++++++++++++++--------
12 1 file changed, 41 insertions(+), 8 deletions(-)
14 Index: b/mm/memcontrol.c
15 ===================================================================
18 @@ -59,7 +59,7 @@ struct mem_cgroup_stat_cpu {
19 } ____cacheline_aligned_in_smp;
21 struct mem_cgroup_stat {
22 - struct mem_cgroup_stat_cpu cpustat[NR_CPUS];
23 + struct mem_cgroup_stat_cpu *cpustat;
27 @@ -143,6 +143,7 @@ struct mem_cgroup {
28 struct mem_cgroup_stat stat;
30 static struct mem_cgroup init_mem_cgroup;
31 +static struct mem_cgroup_stat_cpu init_mem_cgroup_stat_cpu[NR_CPUS];
34 * We use the lower bit of the page->page_cgroup pointer as a bit spin
35 @@ -1097,23 +1098,54 @@ static void free_mem_cgroup_per_zone_inf
36 static struct mem_cgroup *mem_cgroup_alloc(void)
38 struct mem_cgroup *mem;
39 + struct mem_cgroup_stat_cpu *cpustat;
40 + size_t statsize = nr_cpu_ids * sizeof(*cpustat);
42 - if (sizeof(*mem) < PAGE_SIZE)
43 - mem = kmalloc(sizeof(*mem), GFP_KERNEL);
45 + if (sizeof(*mem) > PAGE_SIZE) {
46 mem = vmalloc(sizeof(*mem));
51 memset(mem, 0, sizeof(*mem));
53 + mem = kzalloc(sizeof(*mem), GFP_KERNEL);
58 + if (statsize > PAGE_SIZE) {
59 + cpustat = vmalloc(statsize);
62 + memset(cpustat, 0, statsize);
64 + cpustat = kzalloc(statsize, GFP_KERNEL);
69 + mem->stat.cpustat = cpustat;
73 + if (is_vmalloc_addr(mem))
81 static void mem_cgroup_free(struct mem_cgroup *mem)
83 - if (sizeof(*mem) < PAGE_SIZE)
85 + if (is_vmalloc_addr(mem->stat.cpustat))
86 + vfree(mem->stat.cpustat);
88 + kfree(mem->stat.cpustat);
90 + if (is_vmalloc_addr(mem))
97 @@ -1125,6 +1157,7 @@ mem_cgroup_create(struct cgroup_subsys *
99 if (unlikely((cont->parent) == NULL)) {
100 mem = &init_mem_cgroup;
101 + mem->stat.cpustat = &init_mem_cgroup_stat_cpu[0];
102 page_cgroup_cache = KMEM_CACHE(page_cgroup, SLAB_PANIC);
104 mem = mem_cgroup_alloc();