提交 99ab7b19 编写于 作者: Y Yinghai Lu 提交者: Linus Torvalds

mm: sparse: fix usemap allocation above node descriptor section

After commit f5bf18fa ("bootmem/sparsemem: remove limit constraint
in alloc_bootmem_section"), usemap allocations may easily be placed
outside the optimal section that holds the node descriptor, even if
there is space available in that section.  This results in unnecessary
hotplug dependencies that need to have the node unplugged before the
section holding the usemap.

The reason is that the bootmem allocator doesn't guarantee a linear
search starting from the passed allocation goal but may start out at a
much higher address absent an upper limit.

Fix this by trying the allocation with the limit at the section end,
then retry without if that fails.  This keeps the fix from f5bf18fa
of not panicking if the allocation does not fit in the section, but
still makes sure to try to stay within the section at first.
Signed-off-by: NYinghai Lu <yinghai@kernel.org>
Signed-off-by: NJohannes Weiner <hannes@cmpxchg.org>
Cc: <stable@vger.kernel.org>	[3.3.x, 3.4.x]
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 07b4e2bc
...@@ -91,6 +91,11 @@ extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat, ...@@ -91,6 +91,11 @@ extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat,
unsigned long size, unsigned long size,
unsigned long align, unsigned long align,
unsigned long goal); unsigned long goal);
void *___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
unsigned long size,
unsigned long align,
unsigned long goal,
unsigned long limit);
extern void *__alloc_bootmem_low(unsigned long size, extern void *__alloc_bootmem_low(unsigned long size,
unsigned long align, unsigned long align,
unsigned long goal); unsigned long goal);
......
...@@ -698,7 +698,7 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align, ...@@ -698,7 +698,7 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align,
return ___alloc_bootmem(size, align, goal, limit); return ___alloc_bootmem(size, align, goal, limit);
} }
static void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat, void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
unsigned long size, unsigned long align, unsigned long size, unsigned long align,
unsigned long goal, unsigned long limit) unsigned long goal, unsigned long limit)
{ {
......
...@@ -274,7 +274,7 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align, ...@@ -274,7 +274,7 @@ void * __init __alloc_bootmem(unsigned long size, unsigned long align,
return ___alloc_bootmem(size, align, goal, limit); return ___alloc_bootmem(size, align, goal, limit);
} }
static void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat, void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
unsigned long size, unsigned long size,
unsigned long align, unsigned long align,
unsigned long goal, unsigned long goal,
......
...@@ -275,8 +275,9 @@ static unsigned long * __init ...@@ -275,8 +275,9 @@ static unsigned long * __init
sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
unsigned long size) unsigned long size)
{ {
pg_data_t *host_pgdat; unsigned long goal, limit;
unsigned long goal; unsigned long *p;
int nid;
/* /*
* A page may contain usemaps for other sections preventing the * A page may contain usemaps for other sections preventing the
* page being freed and making a section unremovable while * page being freed and making a section unremovable while
...@@ -288,9 +289,16 @@ sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat, ...@@ -288,9 +289,16 @@ sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
* this problem. * this problem.
*/ */
goal = __pa(pgdat) & (PAGE_SECTION_MASK << PAGE_SHIFT); goal = __pa(pgdat) & (PAGE_SECTION_MASK << PAGE_SHIFT);
host_pgdat = NODE_DATA(early_pfn_to_nid(goal >> PAGE_SHIFT)); limit = goal + (1UL << PA_SECTION_SHIFT);
return __alloc_bootmem_node_nopanic(host_pgdat, size, nid = early_pfn_to_nid(goal >> PAGE_SHIFT);
SMP_CACHE_BYTES, goal); again:
p = ___alloc_bootmem_node_nopanic(NODE_DATA(nid), size,
SMP_CACHE_BYTES, goal, limit);
if (!p && limit) {
limit = 0;
goto again;
}
return p;
} }
static void __init check_usemap_section_nr(int nid, unsigned long *usemap) static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册