mm/sparse: introduce alloc_usemap_and_memmap
After commit 9bdac91424
("sparsemem: Put mem map for one node
together."), vmemmap for one node will be allocated together, its logic
is similar as memory allocation for pageblock flags. This patch
introduces alloc_usemap_and_memmap to extract the same logic of memory
alloction for pageblock flags and vmemmap.
Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Cc: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
6e543d5780
commit
187320932d
147
mm/sparse.c
147
mm/sparse.c
|
@ -339,13 +339,14 @@ static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_MEMORY_HOTREMOVE */
|
#endif /* CONFIG_MEMORY_HOTREMOVE */
|
||||||
|
|
||||||
static void __init sparse_early_usemaps_alloc_node(unsigned long**usemap_map,
|
static void __init sparse_early_usemaps_alloc_node(void *data,
|
||||||
unsigned long pnum_begin,
|
unsigned long pnum_begin,
|
||||||
unsigned long pnum_end,
|
unsigned long pnum_end,
|
||||||
unsigned long usemap_count, int nodeid)
|
unsigned long usemap_count, int nodeid)
|
||||||
{
|
{
|
||||||
void *usemap;
|
void *usemap;
|
||||||
unsigned long pnum;
|
unsigned long pnum;
|
||||||
|
unsigned long **usemap_map = (unsigned long **)data;
|
||||||
int size = usemap_size();
|
int size = usemap_size();
|
||||||
|
|
||||||
usemap = sparse_early_usemaps_alloc_pgdat_section(NODE_DATA(nodeid),
|
usemap = sparse_early_usemaps_alloc_pgdat_section(NODE_DATA(nodeid),
|
||||||
|
@ -430,11 +431,12 @@ void __init sparse_mem_maps_populate_node(struct page **map_map,
|
||||||
#endif /* !CONFIG_SPARSEMEM_VMEMMAP */
|
#endif /* !CONFIG_SPARSEMEM_VMEMMAP */
|
||||||
|
|
||||||
#ifdef CONFIG_SPARSEMEM_ALLOC_MEM_MAP_TOGETHER
|
#ifdef CONFIG_SPARSEMEM_ALLOC_MEM_MAP_TOGETHER
|
||||||
static void __init sparse_early_mem_maps_alloc_node(struct page **map_map,
|
static void __init sparse_early_mem_maps_alloc_node(void *data,
|
||||||
unsigned long pnum_begin,
|
unsigned long pnum_begin,
|
||||||
unsigned long pnum_end,
|
unsigned long pnum_end,
|
||||||
unsigned long map_count, int nodeid)
|
unsigned long map_count, int nodeid)
|
||||||
{
|
{
|
||||||
|
struct page **map_map = (struct page **)data;
|
||||||
sparse_mem_maps_populate_node(map_map, pnum_begin, pnum_end,
|
sparse_mem_maps_populate_node(map_map, pnum_begin, pnum_end,
|
||||||
map_count, nodeid);
|
map_count, nodeid);
|
||||||
}
|
}
|
||||||
|
@ -460,88 +462,18 @@ void __attribute__((weak)) __meminit vmemmap_populate_print_last(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Allocate the accumulated non-linear sections, allocate a mem_map
|
* alloc_usemap_and_memmap - memory alloction for pageblock flags and vmemmap
|
||||||
* for each and record the physical to section mapping.
|
* @map: usemap_map for pageblock flags or mmap_map for vmemmap
|
||||||
*/
|
*/
|
||||||
void __init sparse_init(void)
|
static void __init alloc_usemap_and_memmap(void (*alloc_func)
|
||||||
|
(void *, unsigned long, unsigned long,
|
||||||
|
unsigned long, int), void *data)
|
||||||
{
|
{
|
||||||
unsigned long pnum;
|
unsigned long pnum;
|
||||||
struct page *map;
|
unsigned long map_count;
|
||||||
unsigned long *usemap;
|
|
||||||
unsigned long **usemap_map;
|
|
||||||
int size;
|
|
||||||
int nodeid_begin = 0;
|
int nodeid_begin = 0;
|
||||||
unsigned long pnum_begin = 0;
|
unsigned long pnum_begin = 0;
|
||||||
unsigned long usemap_count;
|
|
||||||
#ifdef CONFIG_SPARSEMEM_ALLOC_MEM_MAP_TOGETHER
|
|
||||||
unsigned long map_count;
|
|
||||||
int size2;
|
|
||||||
struct page **map_map;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* see include/linux/mmzone.h 'struct mem_section' definition */
|
|
||||||
BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
|
|
||||||
|
|
||||||
/* Setup pageblock_order for HUGETLB_PAGE_SIZE_VARIABLE */
|
|
||||||
set_pageblock_order();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* map is using big page (aka 2M in x86 64 bit)
|
|
||||||
* usemap is less one page (aka 24 bytes)
|
|
||||||
* so alloc 2M (with 2M align) and 24 bytes in turn will
|
|
||||||
* make next 2M slip to one more 2M later.
|
|
||||||
* then in big system, the memory will have a lot of holes...
|
|
||||||
* here try to allocate 2M pages continuously.
|
|
||||||
*
|
|
||||||
* powerpc need to call sparse_init_one_section right after each
|
|
||||||
* sparse_early_mem_map_alloc, so allocate usemap_map at first.
|
|
||||||
*/
|
|
||||||
size = sizeof(unsigned long *) * NR_MEM_SECTIONS;
|
|
||||||
usemap_map = alloc_bootmem(size);
|
|
||||||
if (!usemap_map)
|
|
||||||
panic("can not allocate usemap_map\n");
|
|
||||||
|
|
||||||
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
|
|
||||||
struct mem_section *ms;
|
|
||||||
|
|
||||||
if (!present_section_nr(pnum))
|
|
||||||
continue;
|
|
||||||
ms = __nr_to_section(pnum);
|
|
||||||
nodeid_begin = sparse_early_nid(ms);
|
|
||||||
pnum_begin = pnum;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
usemap_count = 1;
|
|
||||||
for (pnum = pnum_begin + 1; pnum < NR_MEM_SECTIONS; pnum++) {
|
|
||||||
struct mem_section *ms;
|
|
||||||
int nodeid;
|
|
||||||
|
|
||||||
if (!present_section_nr(pnum))
|
|
||||||
continue;
|
|
||||||
ms = __nr_to_section(pnum);
|
|
||||||
nodeid = sparse_early_nid(ms);
|
|
||||||
if (nodeid == nodeid_begin) {
|
|
||||||
usemap_count++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* ok, we need to take cake of from pnum_begin to pnum - 1*/
|
|
||||||
sparse_early_usemaps_alloc_node(usemap_map, pnum_begin, pnum,
|
|
||||||
usemap_count, nodeid_begin);
|
|
||||||
/* new start, update count etc*/
|
|
||||||
nodeid_begin = nodeid;
|
|
||||||
pnum_begin = pnum;
|
|
||||||
usemap_count = 1;
|
|
||||||
}
|
|
||||||
/* ok, last chunk */
|
|
||||||
sparse_early_usemaps_alloc_node(usemap_map, pnum_begin, NR_MEM_SECTIONS,
|
|
||||||
usemap_count, nodeid_begin);
|
|
||||||
|
|
||||||
#ifdef CONFIG_SPARSEMEM_ALLOC_MEM_MAP_TOGETHER
|
|
||||||
size2 = sizeof(struct page *) * NR_MEM_SECTIONS;
|
|
||||||
map_map = alloc_bootmem(size2);
|
|
||||||
if (!map_map)
|
|
||||||
panic("can not allocate map_map\n");
|
|
||||||
|
|
||||||
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
|
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
|
||||||
struct mem_section *ms;
|
struct mem_section *ms;
|
||||||
|
@ -567,16 +499,65 @@ void __init sparse_init(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* ok, we need to take cake of from pnum_begin to pnum - 1*/
|
/* ok, we need to take cake of from pnum_begin to pnum - 1*/
|
||||||
sparse_early_mem_maps_alloc_node(map_map, pnum_begin, pnum,
|
alloc_func(data, pnum_begin, pnum,
|
||||||
map_count, nodeid_begin);
|
map_count, nodeid_begin);
|
||||||
/* new start, update count etc*/
|
/* new start, update count etc*/
|
||||||
nodeid_begin = nodeid;
|
nodeid_begin = nodeid;
|
||||||
pnum_begin = pnum;
|
pnum_begin = pnum;
|
||||||
map_count = 1;
|
map_count = 1;
|
||||||
}
|
}
|
||||||
/* ok, last chunk */
|
/* ok, last chunk */
|
||||||
sparse_early_mem_maps_alloc_node(map_map, pnum_begin, NR_MEM_SECTIONS,
|
alloc_func(data, pnum_begin, NR_MEM_SECTIONS,
|
||||||
map_count, nodeid_begin);
|
map_count, nodeid_begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate the accumulated non-linear sections, allocate a mem_map
|
||||||
|
* for each and record the physical to section mapping.
|
||||||
|
*/
|
||||||
|
void __init sparse_init(void)
|
||||||
|
{
|
||||||
|
unsigned long pnum;
|
||||||
|
struct page *map;
|
||||||
|
unsigned long *usemap;
|
||||||
|
unsigned long **usemap_map;
|
||||||
|
int size;
|
||||||
|
#ifdef CONFIG_SPARSEMEM_ALLOC_MEM_MAP_TOGETHER
|
||||||
|
int size2;
|
||||||
|
struct page **map_map;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* see include/linux/mmzone.h 'struct mem_section' definition */
|
||||||
|
BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
|
||||||
|
|
||||||
|
/* Setup pageblock_order for HUGETLB_PAGE_SIZE_VARIABLE */
|
||||||
|
set_pageblock_order();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* map is using big page (aka 2M in x86 64 bit)
|
||||||
|
* usemap is less one page (aka 24 bytes)
|
||||||
|
* so alloc 2M (with 2M align) and 24 bytes in turn will
|
||||||
|
* make next 2M slip to one more 2M later.
|
||||||
|
* then in big system, the memory will have a lot of holes...
|
||||||
|
* here try to allocate 2M pages continuously.
|
||||||
|
*
|
||||||
|
* powerpc need to call sparse_init_one_section right after each
|
||||||
|
* sparse_early_mem_map_alloc, so allocate usemap_map at first.
|
||||||
|
*/
|
||||||
|
size = sizeof(unsigned long *) * NR_MEM_SECTIONS;
|
||||||
|
usemap_map = alloc_bootmem(size);
|
||||||
|
if (!usemap_map)
|
||||||
|
panic("can not allocate usemap_map\n");
|
||||||
|
alloc_usemap_and_memmap(sparse_early_usemaps_alloc_node,
|
||||||
|
(void *)usemap_map);
|
||||||
|
|
||||||
|
#ifdef CONFIG_SPARSEMEM_ALLOC_MEM_MAP_TOGETHER
|
||||||
|
size2 = sizeof(struct page *) * NR_MEM_SECTIONS;
|
||||||
|
map_map = alloc_bootmem(size2);
|
||||||
|
if (!map_map)
|
||||||
|
panic("can not allocate map_map\n");
|
||||||
|
alloc_usemap_and_memmap(sparse_early_mem_maps_alloc_node,
|
||||||
|
(void *)map_map);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
|
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
|
||||||
|
|
Loading…
Reference in New Issue