aboutsummaryrefslogtreecommitdiffstats
path: root/mm/page_cgroup.c
diff options
context:
space:
mode:
authorMichal Hocko <mhocko@suse.cz>2011-03-23 19:42:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-03-23 22:46:32 -0400
commitdde79e005a769d800166687c9e00d50d93e411ff (patch)
treea38166f535b48063bd680deb64edbedf4395cfed /mm/page_cgroup.c
parent4be4489feae6da890765cc1bdc1af5e4f8c4b75f (diff)
page_cgroup: reduce allocation overhead for page_cgroup array for CONFIG_SPARSEMEM
Currently we are allocating a single page_cgroup array per memory section (stored in mem_section->base) when CONFIG_SPARSEMEM is selected. This is correct but memory inefficient solution because the allocated memory (unless we fall back to vmalloc) is not kmalloc friendly: - 32b - 16384 entries (20B per entry) fit into 327680B so the 524288B slab cache is used - 32b with PAE - 131072 entries with 2621440B fit into 4194304B - 64b - 32768 entries (40B per entry) fit into 2097152 cache This is ~37% wasted space per memory section and it sumps up for the whole memory. On a x86_64 machine it is something like 6MB per 1GB of RAM. We can reduce the internal fragmentation by using alloc_pages_exact which allocates PAGE_SIZE aligned blocks so we will get down to <4kB wasted memory per section which is much better. We still need a fallback to vmalloc because we have no guarantees that we will have a continuous memory of that size (order-10) later on during the hotplug events. [hannes@cmpxchg.org: do not define unused free_page_cgroup() without memory hotplug] Signed-off-by: Michal Hocko <mhocko@suse.cz> Cc: Dave Hansen <dave@linux.vnet.ibm.com> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Balbir Singh <balbir@in.ibm.com> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_cgroup.c')
-rw-r--r--mm/page_cgroup.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/mm/page_cgroup.c b/mm/page_cgroup.c
index 6c3f7a6a481a..8e7577cdf5e4 100644
--- a/mm/page_cgroup.c
+++ b/mm/page_cgroup.c
@@ -130,7 +130,38 @@ struct page *lookup_cgroup_page(struct page_cgroup *pc)
130 return page; 130 return page;
131} 131}
132 132
133/* __alloc_bootmem...() is protected by !slab_available() */ 133static void *__init_refok alloc_page_cgroup(size_t size, int nid)
134{
135 void *addr = NULL;
136
137 addr = alloc_pages_exact(size, GFP_KERNEL | __GFP_NOWARN);
138 if (addr)
139 return addr;
140
141 if (node_state(nid, N_HIGH_MEMORY))
142 addr = vmalloc_node(size, nid);
143 else
144 addr = vmalloc(size);
145
146 return addr;
147}
148
149#ifdef CONFIG_MEMORY_HOTPLUG
150static void free_page_cgroup(void *addr)
151{
152 if (is_vmalloc_addr(addr)) {
153 vfree(addr);
154 } else {
155 struct page *page = virt_to_page(addr);
156 if (!PageReserved(page)) { /* Is bootmem ? */
157 size_t table_size =
158 sizeof(struct page_cgroup) * PAGES_PER_SECTION;
159 free_pages_exact(addr, table_size);
160 }
161 }
162}
163#endif
164
134static int __init_refok init_section_page_cgroup(unsigned long pfn) 165static int __init_refok init_section_page_cgroup(unsigned long pfn)
135{ 166{
136 struct page_cgroup *base, *pc; 167 struct page_cgroup *base, *pc;
@@ -147,17 +178,8 @@ static int __init_refok init_section_page_cgroup(unsigned long pfn)
147 178
148 nid = page_to_nid(pfn_to_page(pfn)); 179 nid = page_to_nid(pfn_to_page(pfn));
149 table_size = sizeof(struct page_cgroup) * PAGES_PER_SECTION; 180 table_size = sizeof(struct page_cgroup) * PAGES_PER_SECTION;
150 VM_BUG_ON(!slab_is_available()); 181 base = alloc_page_cgroup(table_size, nid);
151 if (node_state(nid, N_HIGH_MEMORY)) { 182
152 base = kmalloc_node(table_size,
153 GFP_KERNEL | __GFP_NOWARN, nid);
154 if (!base)
155 base = vmalloc_node(table_size, nid);
156 } else {
157 base = kmalloc(table_size, GFP_KERNEL | __GFP_NOWARN);
158 if (!base)
159 base = vmalloc(table_size);
160 }
161 /* 183 /*
162 * The value stored in section->page_cgroup is (base - pfn) 184 * The value stored in section->page_cgroup is (base - pfn)
163 * and it does not point to the memory block allocated above, 185 * and it does not point to the memory block allocated above,
@@ -189,16 +211,8 @@ void __free_page_cgroup(unsigned long pfn)
189 if (!ms || !ms->page_cgroup) 211 if (!ms || !ms->page_cgroup)
190 return; 212 return;
191 base = ms->page_cgroup + pfn; 213 base = ms->page_cgroup + pfn;
192 if (is_vmalloc_addr(base)) { 214 free_page_cgroup(base);
193 vfree(base); 215 ms->page_cgroup = NULL;
194 ms->page_cgroup = NULL;
195 } else {
196 struct page *page = virt_to_page(base);
197 if (!PageReserved(page)) { /* Is bootmem ? */
198 kfree(base);
199 ms->page_cgroup = NULL;
200 }
201 }
202} 216}
203 217
204int __meminit online_page_cgroup(unsigned long start_pfn, 218int __meminit online_page_cgroup(unsigned long start_pfn,