Skip to content

Commit a4322e1

Browse files
Yinghai LuH. Peter Anvin
authored andcommitted
sparsemem: Put usemap for one node together
Could save some buffer space instead of applying one by one. Could help that system that is going to use early_res instead of bootmem less entries in early_res make search more faster on system with more memory. Signed-off-by: Yinghai Lu <yinghai@kernel.org> LKML-Reference: <1265793639-15071-18-git-send-email-yinghai@kernel.org> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent 0867721 commit a4322e1

1 file changed

Lines changed: 66 additions & 18 deletions

File tree

‎mm/sparse.c‎

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ static unsigned long *__kmalloc_section_usemap(void)
271271

272272
#ifdef CONFIG_MEMORY_HOTREMOVE
273273
static unsigned long * __init
274-
sparse_early_usemap_alloc_pgdat_section(struct pglist_data *pgdat)
274+
sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
275+
unsigned long count)
275276
{
276277
unsigned long section_nr;
277278

@@ -286,7 +287,7 @@ sparse_early_usemap_alloc_pgdat_section(struct pglist_data *pgdat)
286287
* this problem.
287288
*/
288289
section_nr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT);
289-
return alloc_bootmem_section(usemap_size(), section_nr);
290+
return alloc_bootmem_section(usemap_size() * count, section_nr);
290291
}
291292

292293
static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
@@ -329,7 +330,8 @@ static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
329330
}
330331
#else
331332
static unsigned long * __init
332-
sparse_early_usemap_alloc_pgdat_section(struct pglist_data *pgdat)
333+
sparse_early_usemaps_alloc_pgdat_section(struct pglist_data *pgdat,
334+
unsigned long count)
333335
{
334336
return NULL;
335337
}
@@ -339,27 +341,40 @@ static void __init check_usemap_section_nr(int nid, unsigned long *usemap)
339341
}
340342
#endif /* CONFIG_MEMORY_HOTREMOVE */
341343

342-
static unsigned long *__init sparse_early_usemap_alloc(unsigned long pnum)
344+
static void __init sparse_early_usemaps_alloc_node(unsigned long**usemap_map,
345+
unsigned long pnum_begin,
346+
unsigned long pnum_end,
347+
unsigned long usemap_count, int nodeid)
343348
{
344-
unsigned long *usemap;
345-
struct mem_section *ms = __nr_to_section(pnum);
346-
int nid = sparse_early_nid(ms);
347-
348-
usemap = sparse_early_usemap_alloc_pgdat_section(NODE_DATA(nid));
349-
if (usemap)
350-
return usemap;
349+
void *usemap;
350+
unsigned long pnum;
351+
int size = usemap_size();
351352

352-
usemap = alloc_bootmem_node(NODE_DATA(nid), usemap_size());
353+
usemap = sparse_early_usemaps_alloc_pgdat_section(NODE_DATA(nodeid),
354+
usemap_count);
353355
if (usemap) {
354-
check_usemap_section_nr(nid, usemap);
355-
return usemap;
356+
for (pnum = pnum_begin; pnum < pnum_end; pnum++) {
357+
if (!present_section_nr(pnum))
358+
continue;
359+
usemap_map[pnum] = usemap;
360+
usemap += size;
361+
}
362+
return;
356363
}
357364

358-
/* Stupid: suppress gcc warning for SPARSEMEM && !NUMA */
359-
nid = 0;
365+
usemap = alloc_bootmem_node(NODE_DATA(nodeid), size * usemap_count);
366+
if (usemap) {
367+
for (pnum = pnum_begin; pnum < pnum_end; pnum++) {
368+
if (!present_section_nr(pnum))
369+
continue;
370+
usemap_map[pnum] = usemap;
371+
usemap += size;
372+
check_usemap_section_nr(nodeid, usemap_map[pnum]);
373+
}
374+
return;
375+
}
360376

361377
printk(KERN_WARNING "%s: allocation failed\n", __func__);
362-
return NULL;
363378
}
364379

365380
#ifndef CONFIG_SPARSEMEM_VMEMMAP
@@ -396,6 +411,7 @@ static struct page __init *sparse_early_mem_map_alloc(unsigned long pnum)
396411
void __attribute__((weak)) __meminit vmemmap_populate_print_last(void)
397412
{
398413
}
414+
399415
/*
400416
* Allocate the accumulated non-linear sections, allocate a mem_map
401417
* for each and record the physical to section mapping.
@@ -407,6 +423,9 @@ void __init sparse_init(void)
407423
unsigned long *usemap;
408424
unsigned long **usemap_map;
409425
int size;
426+
int nodeid_begin = 0;
427+
unsigned long pnum_begin = 0;
428+
unsigned long usemap_count;
410429

411430
/*
412431
* map is using big page (aka 2M in x86 64 bit)
@@ -425,10 +444,39 @@ void __init sparse_init(void)
425444
panic("can not allocate usemap_map\n");
426445

427446
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
447+
struct mem_section *ms;
448+
428449
if (!present_section_nr(pnum))
429450
continue;
430-
usemap_map[pnum] = sparse_early_usemap_alloc(pnum);
451+
ms = __nr_to_section(pnum);
452+
nodeid_begin = sparse_early_nid(ms);
453+
pnum_begin = pnum;
454+
break;
455+
}
456+
usemap_count = 1;
457+
for (pnum = pnum_begin + 1; pnum < NR_MEM_SECTIONS; pnum++) {
458+
struct mem_section *ms;
459+
int nodeid;
460+
461+
if (!present_section_nr(pnum))
462+
continue;
463+
ms = __nr_to_section(pnum);
464+
nodeid = sparse_early_nid(ms);
465+
if (nodeid == nodeid_begin) {
466+
usemap_count++;
467+
continue;
468+
}
469+
/* ok, we need to take cake of from pnum_begin to pnum - 1*/
470+
sparse_early_usemaps_alloc_node(usemap_map, pnum_begin, pnum,
471+
usemap_count, nodeid_begin);
472+
/* new start, update count etc*/
473+
nodeid_begin = nodeid;
474+
pnum_begin = pnum;
475+
usemap_count = 1;
431476
}
477+
/* ok, last chunk */
478+
sparse_early_usemaps_alloc_node(usemap_map, pnum_begin, NR_MEM_SECTIONS,
479+
usemap_count, nodeid_begin);
432480

433481
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
434482
if (!present_section_nr(pnum))

0 commit comments

Comments
 (0)