Skip to content

Commit e70260a

Browse files
Yasunori Gototorvalds
authored andcommitted
memory hotplug: make alloc_bootmem_section()
alloc_bootmem_section() can allocate specified section's area. This is used for usemap to keep same section with pgdat by later patch. Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com> Cc: Badari Pulavarty <pbadari@us.ibm.com> Cc: Yinghai Lu <yhlu.kernel@gmail.com> Cc: Yasunori Goto <y-goto@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9d99217 commit e70260a

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎include/linux/bootmem.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ extern void reserve_bootmem_node(pg_data_t *pgdat,
101101
extern void free_bootmem_node(pg_data_t *pgdat,
102102
unsigned long addr,
103103
unsigned long size);
104+
extern void *alloc_bootmem_section(unsigned long size,
105+
unsigned long section_nr);
104106

105107
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
106108
#define alloc_bootmem_node(pgdat, x) \

‎mm/bootmem.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,37 @@ void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
545545
return __alloc_bootmem(size, align, goal);
546546
}
547547

548+
#ifdef CONFIG_SPARSEMEM
549+
void * __init alloc_bootmem_section(unsigned long size,
550+
unsigned long section_nr)
551+
{
552+
void *ptr;
553+
unsigned long limit, goal, start_nr, end_nr, pfn;
554+
struct pglist_data *pgdat;
555+
556+
pfn = section_nr_to_pfn(section_nr);
557+
goal = PFN_PHYS(pfn);
558+
limit = PFN_PHYS(section_nr_to_pfn(section_nr + 1)) - 1;
559+
pgdat = NODE_DATA(early_pfn_to_nid(pfn));
560+
ptr = __alloc_bootmem_core(pgdat->bdata, size, SMP_CACHE_BYTES, goal,
561+
limit);
562+
563+
if (!ptr)
564+
return NULL;
565+
566+
start_nr = pfn_to_section_nr(PFN_DOWN(__pa(ptr)));
567+
end_nr = pfn_to_section_nr(PFN_DOWN(__pa(ptr) + size));
568+
if (start_nr != section_nr || end_nr != section_nr) {
569+
printk(KERN_WARNING "alloc_bootmem failed on section %ld.\n",
570+
section_nr);
571+
free_bootmem_core(pgdat->bdata, __pa(ptr), size);
572+
ptr = NULL;
573+
}
574+
575+
return ptr;
576+
}
577+
#endif
578+
548579
#ifndef ARCH_LOW_ADDRESS_LIMIT
549580
#define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
550581
#endif

0 commit comments

Comments
 (0)