Skip to content

Commit 85b35fe

Browse files
Zhang Yanfeitorvalds
authored andcommitted
mm/sparsemem: use PAGES_PER_SECTION to remove redundant nr_pages parameter
For below functions, - sparse_add_one_section() - kmalloc_section_memmap() - __kmalloc_section_memmap() - __kfree_section_memmap() they are always invoked to operate on one memory section, so it is redundant to always pass a nr_pages parameter, which is the page numbers in one section. So we can directly use predefined macro PAGES_PER_SECTION instead of passing the parameter. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Cc: Wen Congyang <wency@cn.fujitsu.com> Cc: Tang Chen <tangchen@cn.fujitsu.com> Cc: Toshi Kani <toshi.kani@hp.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: Yinghai Lu <yinghai@kernel.org> Cc: Yasunori Goto <y-goto@jp.fujitsu.com> Cc: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 071aee1 commit 85b35fe

3 files changed

Lines changed: 17 additions & 22 deletions

File tree

‎include/linux/memory_hotplug.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ extern int arch_add_memory(int nid, u64 start, u64 size);
268268
extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
269269
extern bool is_memblock_offlined(struct memory_block *mem);
270270
extern void remove_memory(int nid, u64 start, u64 size);
271-
extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
272-
int nr_pages);
271+
extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn);
273272
extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms);
274273
extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
275274
unsigned long pnum);

‎mm/memory_hotplug.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,12 @@ static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
401401
static int __meminit __add_section(int nid, struct zone *zone,
402402
unsigned long phys_start_pfn)
403403
{
404-
int nr_pages = PAGES_PER_SECTION;
405404
int ret;
406405

407406
if (pfn_valid(phys_start_pfn))
408407
return -EEXIST;
409408

410-
ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages);
409+
ret = sparse_add_one_section(zone, phys_start_pfn);
411410

412411
if (ret < 0)
413412
return ret;

‎mm/sparse.c‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,15 @@ void __init sparse_init(void)
590590

591591
#ifdef CONFIG_MEMORY_HOTPLUG
592592
#ifdef CONFIG_SPARSEMEM_VMEMMAP
593-
static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid,
594-
unsigned long nr_pages)
593+
static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid)
595594
{
596595
/* This will make the necessary allocations eventually. */
597596
return sparse_mem_map_populate(pnum, nid);
598597
}
599-
static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
598+
static void __kfree_section_memmap(struct page *memmap)
600599
{
601600
unsigned long start = (unsigned long)memmap;
602-
unsigned long end = (unsigned long)(memmap + nr_pages);
601+
unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION);
603602

604603
vmemmap_free(start, end);
605604
}
@@ -613,10 +612,10 @@ static void free_map_bootmem(struct page *memmap, unsigned long nr_pages)
613612
}
614613
#endif /* CONFIG_MEMORY_HOTREMOVE */
615614
#else
616-
static struct page *__kmalloc_section_memmap(unsigned long nr_pages)
615+
static struct page *__kmalloc_section_memmap(void)
617616
{
618617
struct page *page, *ret;
619-
unsigned long memmap_size = sizeof(struct page) * nr_pages;
618+
unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION;
620619

621620
page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size));
622621
if (page)
@@ -634,19 +633,18 @@ static struct page *__kmalloc_section_memmap(unsigned long nr_pages)
634633
return ret;
635634
}
636635

637-
static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid,
638-
unsigned long nr_pages)
636+
static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid)
639637
{
640-
return __kmalloc_section_memmap(nr_pages);
638+
return __kmalloc_section_memmap();
641639
}
642640

643-
static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
641+
static void __kfree_section_memmap(struct page *memmap)
644642
{
645643
if (is_vmalloc_addr(memmap))
646644
vfree(memmap);
647645
else
648646
free_pages((unsigned long)memmap,
649-
get_order(sizeof(struct page) * nr_pages));
647+
get_order(sizeof(struct page) * PAGES_PER_SECTION));
650648
}
651649

652650
#ifdef CONFIG_MEMORY_HOTREMOVE
@@ -684,8 +682,7 @@ static void free_map_bootmem(struct page *memmap, unsigned long nr_pages)
684682
* set. If this is <=0, then that means that the passed-in
685683
* map was not consumed and must be freed.
686684
*/
687-
int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
688-
int nr_pages)
685+
int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn)
689686
{
690687
unsigned long section_nr = pfn_to_section_nr(start_pfn);
691688
struct pglist_data *pgdat = zone->zone_pgdat;
@@ -702,12 +699,12 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
702699
ret = sparse_index_init(section_nr, pgdat->node_id);
703700
if (ret < 0 && ret != -EEXIST)
704701
return ret;
705-
memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages);
702+
memmap = kmalloc_section_memmap(section_nr, pgdat->node_id);
706703
if (!memmap)
707704
return -ENOMEM;
708705
usemap = __kmalloc_section_usemap();
709706
if (!usemap) {
710-
__kfree_section_memmap(memmap, nr_pages);
707+
__kfree_section_memmap(memmap);
711708
return -ENOMEM;
712709
}
713710

@@ -719,7 +716,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
719716
goto out;
720717
}
721718

722-
memset(memmap, 0, sizeof(struct page) * nr_pages);
719+
memset(memmap, 0, sizeof(struct page) * PAGES_PER_SECTION);
723720

724721
ms->section_mem_map |= SECTION_MARKED_PRESENT;
725722

@@ -729,7 +726,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
729726
pgdat_resize_unlock(pgdat, &flags);
730727
if (ret <= 0) {
731728
kfree(usemap);
732-
__kfree_section_memmap(memmap, nr_pages);
729+
__kfree_section_memmap(memmap);
733730
}
734731
return ret;
735732
}
@@ -771,7 +768,7 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap)
771768
if (PageSlab(usemap_page) || PageCompound(usemap_page)) {
772769
kfree(usemap);
773770
if (memmap)
774-
__kfree_section_memmap(memmap, PAGES_PER_SECTION);
771+
__kfree_section_memmap(memmap);
775772
return;
776773
}
777774

0 commit comments

Comments
 (0)