Skip to content

Commit 940519f

Browse files
Michal Hockotorvalds
authored andcommitted
mm, memory_hotplug: provide a more generic restrictions for memory hotplug
arch_add_memory, __add_pages take a want_memblock which controls whether the newly added memory should get the sysfs memblock user API (e.g. ZONE_DEVICE users do not want/need this interface). Some callers even want to control where do we allocate the memmap from by configuring altmap. Add a more generic hotplug context for arch_add_memory and __add_pages. struct mhp_restrictions contains flags which contains additional features to be enabled by the memory hotplug (MHP_MEMBLOCK_API currently) and altmap for alternative memmap allocator. This patch shouldn't introduce any functional change. [akpm@linux-foundation.org: build fix] Link: http://lkml.kernel.org/r/20190408082633.2864-3-osalvador@suse.de Signed-off-by: Michal Hocko <mhocko@suse.com> Signed-off-by: Oscar Salvador <osalvador@suse.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5557c76 commit 940519f

10 files changed

Lines changed: 63 additions & 37 deletions

File tree

‎arch/arm64/mm/mmu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,8 @@ int p4d_free_pud_page(p4d_t *p4d, unsigned long addr)
10651065
}
10661066

10671067
#ifdef CONFIG_MEMORY_HOTPLUG
1068-
int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
1069-
bool want_memblock)
1068+
int arch_add_memory(int nid, u64 start, u64 size,
1069+
struct mhp_restrictions *restrictions)
10701070
{
10711071
int flags = 0;
10721072

@@ -1077,6 +1077,6 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
10771077
size, PAGE_KERNEL, __pgd_pgtable_alloc, flags);
10781078

10791079
return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT,
1080-
altmap, want_memblock);
1080+
restrictions);
10811081
}
10821082
#endif

‎arch/ia64/mm/init.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,14 +666,14 @@ mem_init (void)
666666
}
667667

668668
#ifdef CONFIG_MEMORY_HOTPLUG
669-
int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
670-
bool want_memblock)
669+
int arch_add_memory(int nid, u64 start, u64 size,
670+
struct mhp_restrictions *restrictions)
671671
{
672672
unsigned long start_pfn = start >> PAGE_SHIFT;
673673
unsigned long nr_pages = size >> PAGE_SHIFT;
674674
int ret;
675675

676-
ret = __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
676+
ret = __add_pages(nid, start_pfn, nr_pages, restrictions);
677677
if (ret)
678678
printk("%s: Problem encountered in __add_pages() as ret=%d\n",
679679
__func__, ret);

‎arch/powerpc/mm/mem.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ int __weak remove_section_mapping(unsigned long start, unsigned long end)
109109
return -ENODEV;
110110
}
111111

112-
int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
113-
bool want_memblock)
112+
int __ref arch_add_memory(int nid, u64 start, u64 size,
113+
struct mhp_restrictions *restrictions)
114114
{
115115
unsigned long start_pfn = start >> PAGE_SHIFT;
116116
unsigned long nr_pages = size >> PAGE_SHIFT;
@@ -127,7 +127,7 @@ int __ref arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altm
127127
}
128128
flush_inval_dcache_range(start, start + size);
129129

130-
return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
130+
return __add_pages(nid, start_pfn, nr_pages, restrictions);
131131
}
132132

133133
#ifdef CONFIG_MEMORY_HOTREMOVE

‎arch/s390/mm/init.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ device_initcall(s390_cma_mem_init);
219219

220220
#endif /* CONFIG_CMA */
221221

222-
int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
223-
bool want_memblock)
222+
int arch_add_memory(int nid, u64 start, u64 size,
223+
struct mhp_restrictions *restrictions)
224224
{
225225
unsigned long start_pfn = PFN_DOWN(start);
226226
unsigned long size_pages = PFN_DOWN(size);
@@ -230,7 +230,7 @@ int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
230230
if (rc)
231231
return rc;
232232

233-
rc = __add_pages(nid, start_pfn, size_pages, altmap, want_memblock);
233+
rc = __add_pages(nid, start_pfn, size_pages, restrictions);
234234
if (rc)
235235
vmem_remove_mapping(start, size);
236236
return rc;

‎arch/sh/mm/init.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,15 @@ void __init mem_init(void)
404404
}
405405

406406
#ifdef CONFIG_MEMORY_HOTPLUG
407-
int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
408-
bool want_memblock)
407+
int arch_add_memory(int nid, u64 start, u64 size,
408+
struct mhp_restrictions *restrictions)
409409
{
410410
unsigned long start_pfn = PFN_DOWN(start);
411411
unsigned long nr_pages = size >> PAGE_SHIFT;
412412
int ret;
413413

414414
/* We only have ZONE_NORMAL, so this is easy.. */
415-
ret = __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
415+
ret = __add_pages(nid, start_pfn, nr_pages, restrictions);
416416
if (unlikely(ret))
417417
printk("%s: Failed, __add_pages() == %d\n", __func__, ret);
418418

‎arch/x86/mm/init_32.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,13 @@ void __init mem_init(void)
850850
}
851851

852852
#ifdef CONFIG_MEMORY_HOTPLUG
853-
int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
854-
bool want_memblock)
853+
int arch_add_memory(int nid, u64 start, u64 size,
854+
struct mhp_restrictions *restrictions)
855855
{
856856
unsigned long start_pfn = start >> PAGE_SHIFT;
857857
unsigned long nr_pages = size >> PAGE_SHIFT;
858858

859-
return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
859+
return __add_pages(nid, start_pfn, nr_pages, restrictions);
860860
}
861861

862862
#ifdef CONFIG_MEMORY_HOTREMOVE

‎arch/x86/mm/init_64.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,11 @@ static void update_end_of_memory_vars(u64 start, u64 size)
777777
}
778778

779779
int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
780-
struct vmem_altmap *altmap, bool want_memblock)
780+
struct mhp_restrictions *restrictions)
781781
{
782782
int ret;
783783

784-
ret = __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
784+
ret = __add_pages(nid, start_pfn, nr_pages, restrictions);
785785
WARN_ON_ONCE(ret);
786786

787787
/* update max_pfn, max_low_pfn and high_memory */
@@ -791,15 +791,15 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
791791
return ret;
792792
}
793793

794-
int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
795-
bool want_memblock)
794+
int arch_add_memory(int nid, u64 start, u64 size,
795+
struct mhp_restrictions *restrictions)
796796
{
797797
unsigned long start_pfn = start >> PAGE_SHIFT;
798798
unsigned long nr_pages = size >> PAGE_SHIFT;
799799

800800
init_memory_mapping(start, start + size);
801801

802-
return add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
802+
return add_pages(nid, start_pfn, nr_pages, restrictions);
803803
}
804804

805805
#define PAGE_INUSE 0xFD

‎include/linux/memory_hotplug.h‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ enum {
5353
MMOP_ONLINE_MOVABLE,
5454
};
5555

56+
/*
57+
* Restrictions for the memory hotplug:
58+
* flags: MHP_ flags
59+
* altmap: alternative allocator for memmap array
60+
*/
61+
struct mhp_restrictions {
62+
unsigned long flags;
63+
struct vmem_altmap *altmap;
64+
};
65+
5666
/*
5767
* Zone resizing functions
5868
*
@@ -101,6 +111,8 @@ extern void __online_page_free(struct page *page);
101111

102112
extern int try_online_node(int nid);
103113

114+
extern int arch_add_memory(int nid, u64 start, u64 size,
115+
struct mhp_restrictions *restrictions);
104116
extern u64 max_mem_size;
105117

106118
extern bool memhp_auto_online;
@@ -118,20 +130,27 @@ extern int __remove_pages(struct zone *zone, unsigned long start_pfn,
118130
unsigned long nr_pages, struct vmem_altmap *altmap);
119131
#endif /* CONFIG_MEMORY_HOTREMOVE */
120132

133+
/*
134+
* Do we want sysfs memblock files created. This will allow userspace to online
135+
* and offline memory explicitly. Lack of this bit means that the caller has to
136+
* call move_pfn_range_to_zone to finish the initialization.
137+
*/
138+
139+
#define MHP_MEMBLOCK_API (1<<0)
140+
121141
/* reasonably generic interface to expand the physical pages */
122142
extern int __add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
123-
struct vmem_altmap *altmap, bool want_memblock);
143+
struct mhp_restrictions *restrictions);
124144

125145
#ifndef CONFIG_ARCH_HAS_ADD_PAGES
126146
static inline int add_pages(int nid, unsigned long start_pfn,
127-
unsigned long nr_pages, struct vmem_altmap *altmap,
128-
bool want_memblock)
147+
unsigned long nr_pages, struct mhp_restrictions *restrictions)
129148
{
130-
return __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
149+
return __add_pages(nid, start_pfn, nr_pages, restrictions);
131150
}
132151
#else /* ARCH_HAS_ADD_PAGES */
133152
int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
134-
struct vmem_altmap *altmap, bool want_memblock);
153+
struct mhp_restrictions *restrictions);
135154
#endif /* ARCH_HAS_ADD_PAGES */
136155

137156
#ifdef CONFIG_NUMA
@@ -332,8 +351,6 @@ extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
332351
extern int __add_memory(int nid, u64 start, u64 size);
333352
extern int add_memory(int nid, u64 start, u64 size);
334353
extern int add_memory_resource(int nid, struct resource *resource);
335-
extern int arch_add_memory(int nid, u64 start, u64 size,
336-
struct vmem_altmap *altmap, bool want_memblock);
337354
extern void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,
338355
unsigned long nr_pages, struct vmem_altmap *altmap);
339356
extern bool is_memblock_offlined(struct memory_block *mem);

‎kernel/memremap.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
148148
&pgmap->altmap : NULL;
149149
struct resource *res = &pgmap->res;
150150
struct dev_pagemap *conflict_pgmap;
151+
struct mhp_restrictions restrictions = {
152+
/*
153+
* We do not want any optional features only our own memmap
154+
*/
155+
.altmap = altmap,
156+
};
151157
pgprot_t pgprot = PAGE_KERNEL;
152158
int error, nid, is_ram;
153159

@@ -214,16 +220,16 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
214220
*/
215221
if (pgmap->type == MEMORY_DEVICE_PRIVATE) {
216222
error = add_pages(nid, align_start >> PAGE_SHIFT,
217-
align_size >> PAGE_SHIFT, NULL, false);
223+
align_size >> PAGE_SHIFT, &restrictions);
218224
} else {
219225
error = kasan_add_zero_shadow(__va(align_start), align_size);
220226
if (error) {
221227
mem_hotplug_done();
222228
goto err_kasan;
223229
}
224230

225-
error = arch_add_memory(nid, align_start, align_size, altmap,
226-
false);
231+
error = arch_add_memory(nid, align_start, align_size,
232+
&restrictions);
227233
}
228234

229235
if (!error) {

‎mm/memory_hotplug.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@ static int __meminit __add_section(int nid, unsigned long phys_start_pfn,
273273
* add the new pages.
274274
*/
275275
int __ref __add_pages(int nid, unsigned long phys_start_pfn,
276-
unsigned long nr_pages, struct vmem_altmap *altmap,
277-
bool want_memblock)
276+
unsigned long nr_pages, struct mhp_restrictions *restrictions)
278277
{
279278
unsigned long i;
280279
int err = 0;
281280
int start_sec, end_sec;
281+
struct vmem_altmap *altmap = restrictions->altmap;
282282

283283
/* during initialize mem_map, align hot-added range to section */
284284
start_sec = pfn_to_section_nr(phys_start_pfn);
@@ -299,7 +299,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,
299299

300300
for (i = start_sec; i <= end_sec; i++) {
301301
err = __add_section(nid, section_nr_to_pfn(i), altmap,
302-
want_memblock);
302+
restrictions->flags & MHP_MEMBLOCK_API);
303303

304304
/*
305305
* EEXIST is finally dealt with by ioresource collision
@@ -1097,6 +1097,9 @@ static int online_memory_block(struct memory_block *mem, void *arg)
10971097
*/
10981098
int __ref add_memory_resource(int nid, struct resource *res)
10991099
{
1100+
struct mhp_restrictions restrictions = {
1101+
.flags = MHP_MEMBLOCK_API,
1102+
};
11001103
u64 start, size;
11011104
bool new_node = false;
11021105
int ret;
@@ -1124,7 +1127,7 @@ int __ref add_memory_resource(int nid, struct resource *res)
11241127
new_node = ret;
11251128

11261129
/* call arch's memory hotadd */
1127-
ret = arch_add_memory(nid, start, size, NULL, true);
1130+
ret = arch_add_memory(nid, start, size, &restrictions);
11281131
if (ret < 0)
11291132
goto error;
11301133

0 commit comments

Comments
 (0)