Skip to content

Commit 3072e41

Browse files
Michal Hockotorvalds
Michal Hocko
authored andcommitted
mm/memory_hotplug: introduce add_pages
There are new users of memory hotplug emerging. Some of them require different subset of arch_add_memory. There are some which only require allocation of struct pages without mapping those pages to the kernel address space. We currently have __add_pages for that purpose. But this is rather lowlevel and not very suitable for the code outside of the memory hotplug. E.g. x86_64 wants to update max_pfn which should be done by the caller. Introduce add_pages() which should care about those details if they are needed. Each architecture should define its implementation and select CONFIG_ARCH_HAS_ADD_PAGES. All others use the currently existing __add_pages. Link: http://lkml.kernel.org/r/20170817000548.32038-7-jglisse@redhat.com Signed-off-by: Michal Hocko <mhocko@suse.com> Signed-off-by: Jérôme Glisse <jglisse@redhat.com> Acked-by: Balbir Singh <bsingharora@gmail.com> Cc: Aneesh Kumar <aneesh.kumar@linux.vnet.ibm.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Dan Williams <dan.j.williams@intel.com> Cc: David Nellans <dnellans@nvidia.com> Cc: Evgeny Baskakov <ebaskakov@nvidia.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Mark Hairgrove <mhairgrove@nvidia.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Cc: Sherry Cheung <SCheung@nvidia.com> Cc: Subhash Gutti <sgutti@nvidia.com> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Bob Liu <liubo95@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 74eee18 commit 3072e41

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

arch/x86/Kconfig

+4
Original file line numberDiff line numberDiff line change
@@ -2323,6 +2323,10 @@ source "kernel/livepatch/Kconfig"
23232323

23242324
endmenu
23252325

2326+
config ARCH_HAS_ADD_PAGES
2327+
def_bool y
2328+
depends on X86_64 && ARCH_ENABLE_MEMORY_HOTPLUG
2329+
23262330
config ARCH_ENABLE_MEMORY_HOTPLUG
23272331
def_bool y
23282332
depends on X86_64 || (X86_32 && HIGHMEM)

arch/x86/mm/init_64.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ void __init paging_init(void)
761761
* After memory hotplug the variables max_pfn, max_low_pfn and high_memory need
762762
* updating.
763763
*/
764-
static void update_end_of_memory_vars(u64 start, u64 size)
764+
static void update_end_of_memory_vars(u64 start, u64 size)
765765
{
766766
unsigned long end_pfn = PFN_UP(start + size);
767767

@@ -772,22 +772,30 @@ static void update_end_of_memory_vars(u64 start, u64 size)
772772
}
773773
}
774774

775-
int arch_add_memory(int nid, u64 start, u64 size, bool want_memblock)
775+
int add_pages(int nid, unsigned long start_pfn,
776+
unsigned long nr_pages, bool want_memblock)
776777
{
777-
unsigned long start_pfn = start >> PAGE_SHIFT;
778-
unsigned long nr_pages = size >> PAGE_SHIFT;
779778
int ret;
780779

781-
init_memory_mapping(start, start + size);
782-
783780
ret = __add_pages(nid, start_pfn, nr_pages, want_memblock);
784781
WARN_ON_ONCE(ret);
785782

786783
/* update max_pfn, max_low_pfn and high_memory */
787-
update_end_of_memory_vars(start, size);
784+
update_end_of_memory_vars(start_pfn << PAGE_SHIFT,
785+
nr_pages << PAGE_SHIFT);
788786

789787
return ret;
790788
}
789+
790+
int arch_add_memory(int nid, u64 start, u64 size, bool want_memblock)
791+
{
792+
unsigned long start_pfn = start >> PAGE_SHIFT;
793+
unsigned long nr_pages = size >> PAGE_SHIFT;
794+
795+
init_memory_mapping(start, start + size);
796+
797+
return add_pages(nid, start_pfn, nr_pages, want_memblock);
798+
}
791799
EXPORT_SYMBOL_GPL(arch_add_memory);
792800

793801
#define PAGE_INUSE 0xFD

include/linux/memory_hotplug.h

+11
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ extern int __remove_pages(struct zone *zone, unsigned long start_pfn,
133133
extern int __add_pages(int nid, unsigned long start_pfn,
134134
unsigned long nr_pages, bool want_memblock);
135135

136+
#ifndef CONFIG_ARCH_HAS_ADD_PAGES
137+
static inline int add_pages(int nid, unsigned long start_pfn,
138+
unsigned long nr_pages, bool want_memblock)
139+
{
140+
return __add_pages(nid, start_pfn, nr_pages, want_memblock);
141+
}
142+
#else /* ARCH_HAS_ADD_PAGES */
143+
int add_pages(int nid, unsigned long start_pfn,
144+
unsigned long nr_pages, bool want_memblock);
145+
#endif /* ARCH_HAS_ADD_PAGES */
146+
136147
#ifdef CONFIG_NUMA
137148
extern int memory_add_physaddr_to_nid(u64 start);
138149
#else

0 commit comments

Comments
 (0)