Commit 85b35fea authored by Zhang Yanfei's avatar Zhang Yanfei Committed by Linus Torvalds

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: default avatarZhang 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 071aee13
...@@ -268,8 +268,7 @@ extern int arch_add_memory(int nid, u64 start, u64 size); ...@@ -268,8 +268,7 @@ extern int arch_add_memory(int nid, u64 start, u64 size);
extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages); extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
extern bool is_memblock_offlined(struct memory_block *mem); extern bool is_memblock_offlined(struct memory_block *mem);
extern void remove_memory(int nid, u64 start, u64 size); extern void remove_memory(int nid, u64 start, u64 size);
extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn);
int nr_pages);
extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms); extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms);
extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
unsigned long pnum); unsigned long pnum);
......
...@@ -401,13 +401,12 @@ static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn) ...@@ -401,13 +401,12 @@ static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
static int __meminit __add_section(int nid, struct zone *zone, static int __meminit __add_section(int nid, struct zone *zone,
unsigned long phys_start_pfn) unsigned long phys_start_pfn)
{ {
int nr_pages = PAGES_PER_SECTION;
int ret; int ret;
if (pfn_valid(phys_start_pfn)) if (pfn_valid(phys_start_pfn))
return -EEXIST; return -EEXIST;
ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages); ret = sparse_add_one_section(zone, phys_start_pfn);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -590,16 +590,15 @@ void __init sparse_init(void) ...@@ -590,16 +590,15 @@ void __init sparse_init(void)
#ifdef CONFIG_MEMORY_HOTPLUG #ifdef CONFIG_MEMORY_HOTPLUG
#ifdef CONFIG_SPARSEMEM_VMEMMAP #ifdef CONFIG_SPARSEMEM_VMEMMAP
static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid)
unsigned long nr_pages)
{ {
/* This will make the necessary allocations eventually. */ /* This will make the necessary allocations eventually. */
return sparse_mem_map_populate(pnum, nid); return sparse_mem_map_populate(pnum, nid);
} }
static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) static void __kfree_section_memmap(struct page *memmap)
{ {
unsigned long start = (unsigned long)memmap; unsigned long start = (unsigned long)memmap;
unsigned long end = (unsigned long)(memmap + nr_pages); unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION);
vmemmap_free(start, end); vmemmap_free(start, end);
} }
...@@ -613,10 +612,10 @@ static void free_map_bootmem(struct page *memmap, unsigned long nr_pages) ...@@ -613,10 +612,10 @@ static void free_map_bootmem(struct page *memmap, unsigned long nr_pages)
} }
#endif /* CONFIG_MEMORY_HOTREMOVE */ #endif /* CONFIG_MEMORY_HOTREMOVE */
#else #else
static struct page *__kmalloc_section_memmap(unsigned long nr_pages) static struct page *__kmalloc_section_memmap(void)
{ {
struct page *page, *ret; struct page *page, *ret;
unsigned long memmap_size = sizeof(struct page) * nr_pages; unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION;
page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size)); page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size));
if (page) if (page)
...@@ -634,19 +633,18 @@ static struct page *__kmalloc_section_memmap(unsigned long nr_pages) ...@@ -634,19 +633,18 @@ static struct page *__kmalloc_section_memmap(unsigned long nr_pages)
return ret; return ret;
} }
static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid)
unsigned long nr_pages)
{ {
return __kmalloc_section_memmap(nr_pages); return __kmalloc_section_memmap();
} }
static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages) static void __kfree_section_memmap(struct page *memmap)
{ {
if (is_vmalloc_addr(memmap)) if (is_vmalloc_addr(memmap))
vfree(memmap); vfree(memmap);
else else
free_pages((unsigned long)memmap, free_pages((unsigned long)memmap,
get_order(sizeof(struct page) * nr_pages)); get_order(sizeof(struct page) * PAGES_PER_SECTION));
} }
#ifdef CONFIG_MEMORY_HOTREMOVE #ifdef CONFIG_MEMORY_HOTREMOVE
...@@ -684,8 +682,7 @@ static void free_map_bootmem(struct page *memmap, unsigned long nr_pages) ...@@ -684,8 +682,7 @@ static void free_map_bootmem(struct page *memmap, unsigned long nr_pages)
* set. If this is <=0, then that means that the passed-in * set. If this is <=0, then that means that the passed-in
* map was not consumed and must be freed. * map was not consumed and must be freed.
*/ */
int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn, int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn)
int nr_pages)
{ {
unsigned long section_nr = pfn_to_section_nr(start_pfn); unsigned long section_nr = pfn_to_section_nr(start_pfn);
struct pglist_data *pgdat = zone->zone_pgdat; struct pglist_data *pgdat = zone->zone_pgdat;
...@@ -702,12 +699,12 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn, ...@@ -702,12 +699,12 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
ret = sparse_index_init(section_nr, pgdat->node_id); ret = sparse_index_init(section_nr, pgdat->node_id);
if (ret < 0 && ret != -EEXIST) if (ret < 0 && ret != -EEXIST)
return ret; return ret;
memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages); memmap = kmalloc_section_memmap(section_nr, pgdat->node_id);
if (!memmap) if (!memmap)
return -ENOMEM; return -ENOMEM;
usemap = __kmalloc_section_usemap(); usemap = __kmalloc_section_usemap();
if (!usemap) { if (!usemap) {
__kfree_section_memmap(memmap, nr_pages); __kfree_section_memmap(memmap);
return -ENOMEM; return -ENOMEM;
} }
...@@ -719,7 +716,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn, ...@@ -719,7 +716,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
goto out; goto out;
} }
memset(memmap, 0, sizeof(struct page) * nr_pages); memset(memmap, 0, sizeof(struct page) * PAGES_PER_SECTION);
ms->section_mem_map |= SECTION_MARKED_PRESENT; ms->section_mem_map |= SECTION_MARKED_PRESENT;
...@@ -729,7 +726,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn, ...@@ -729,7 +726,7 @@ int __meminit sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
pgdat_resize_unlock(pgdat, &flags); pgdat_resize_unlock(pgdat, &flags);
if (ret <= 0) { if (ret <= 0) {
kfree(usemap); kfree(usemap);
__kfree_section_memmap(memmap, nr_pages); __kfree_section_memmap(memmap);
} }
return ret; return ret;
} }
...@@ -771,7 +768,7 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap) ...@@ -771,7 +768,7 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap)
if (PageSlab(usemap_page) || PageCompound(usemap_page)) { if (PageSlab(usemap_page) || PageCompound(usemap_page)) {
kfree(usemap); kfree(usemap);
if (memmap) if (memmap)
__kfree_section_memmap(memmap, PAGES_PER_SECTION); __kfree_section_memmap(memmap);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment