Skip to content

Commit 1b862ae

Browse files
Michal Hockotorvalds
authored andcommitted
mm, memory_hotplug: get rid of is_zone_device_section
Device memory hotplug hooks into regular memory hotplug only half way. It needs memory sections to track struct pages but there is no need/desire to associate those sections with memory blocks and export them to the userspace via sysfs because they cannot be onlined anyway. This is currently expressed by for_device argument to arch_add_memory which then makes sure to associate the given memory range with ZONE_DEVICE. register_new_memory then relies on is_zone_device_section to distinguish special memory hotplug from the regular one. While this works now, later patches in this series want to move __add_zone outside of arch_add_memory path so we have to come up with something else. Add want_memblock down the __add_pages path and use it to control whether the section->memblock association should be done. arch_add_memory then just trivially want memblock for everything but for_device hotplug. remove_memory_section doesn't need is_zone_device_section either. We can simply skip all the memblock specific cleanup if there is no memblock for the given section. This shouldn't introduce any functional change. Link: http://lkml.kernel.org/r/20170515085827.16474-5-mhocko@kernel.org Signed-off-by: Michal Hocko <mhocko@suse.com> Tested-by: Dan Williams <dan.j.williams@intel.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Balbir Singh <bsingharora@gmail.com> Cc: Daniel Kiper <daniel.kiper@oracle.com> Cc: David Rientjes <rientjes@google.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Igor Mammedov <imammedo@redhat.com> Cc: Jerome Glisse <jglisse@redhat.com> Cc: Joonsoo Kim <js1304@gmail.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Reza Arbab <arbab@linux.vnet.ibm.com> Cc: Tobias Regnery <tobias.regnery@gmail.com> Cc: Toshi Kani <toshi.kani@hpe.com> Cc: Vitaly Kuznetsov <vkuznets@redhat.com> Cc: Xishi Qiu <qiuxishi@huawei.com> Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bfe63d3 commit 1b862ae

9 files changed

Lines changed: 22 additions & 24 deletions

File tree

‎arch/ia64/mm/init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
658658

659659
zone = pgdat->node_zones +
660660
zone_for_memory(nid, start, size, ZONE_NORMAL, for_device);
661-
ret = __add_pages(nid, zone, start_pfn, nr_pages);
661+
ret = __add_pages(nid, zone, start_pfn, nr_pages, !for_device);
662662

663663
if (ret)
664664
printk("%s: Problem encountered in __add_pages() as ret=%d\n",

‎arch/powerpc/mm/mem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
151151
zone = pgdata->node_zones +
152152
zone_for_memory(nid, start, size, 0, for_device);
153153

154-
return __add_pages(nid, zone, start_pfn, nr_pages);
154+
return __add_pages(nid, zone, start_pfn, nr_pages, !for_device);
155155
}
156156

157157
#ifdef CONFIG_MEMORY_HOTREMOVE

‎arch/s390/mm/init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
195195
continue;
196196
nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
197197
zone_end_pfn - start_pfn : size_pages;
198-
rc = __add_pages(nid, zone, start_pfn, nr_pages);
198+
rc = __add_pages(nid, zone, start_pfn, nr_pages, !for_device);
199199
if (rc)
200200
break;
201201
start_pfn += nr_pages;

‎arch/sh/mm/init.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
498498
ret = __add_pages(nid, pgdat->node_zones +
499499
zone_for_memory(nid, start, size, ZONE_NORMAL,
500500
for_device),
501-
start_pfn, nr_pages);
501+
start_pfn, nr_pages, !for_device);
502502
if (unlikely(ret))
503503
printk("%s: Failed, __add_pages() == %d\n", __func__, ret);
504504

‎arch/x86/mm/init_32.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
831831
unsigned long start_pfn = start >> PAGE_SHIFT;
832832
unsigned long nr_pages = size >> PAGE_SHIFT;
833833

834-
return __add_pages(nid, zone, start_pfn, nr_pages);
834+
return __add_pages(nid, zone, start_pfn, nr_pages, !for_device);
835835
}
836836

837837
#ifdef CONFIG_MEMORY_HOTREMOVE

‎arch/x86/mm/init_64.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
787787

788788
init_memory_mapping(start, start + size);
789789

790-
ret = __add_pages(nid, zone, start_pfn, nr_pages);
790+
ret = __add_pages(nid, zone, start_pfn, nr_pages, !for_device);
791791
WARN_ON_ONCE(ret);
792792

793793
/* update max_pfn, max_low_pfn and high_memory */

‎drivers/base/memory.c‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,6 @@ static int add_memory_block(int base_section_nr)
685685
return 0;
686686
}
687687

688-
static bool is_zone_device_section(struct mem_section *ms)
689-
{
690-
struct page *page;
691-
692-
page = sparse_decode_mem_map(ms->section_mem_map, __section_nr(ms));
693-
return is_zone_device_page(page);
694-
}
695-
696688
/*
697689
* need an interface for the VM to add new memory regions,
698690
* but without onlining it.
@@ -702,9 +694,6 @@ int register_new_memory(int nid, struct mem_section *section)
702694
int ret = 0;
703695
struct memory_block *mem;
704696

705-
if (is_zone_device_section(section))
706-
return 0;
707-
708697
mutex_lock(&mem_sysfs_mutex);
709698

710699
mem = find_memory_block(section);
@@ -741,11 +730,16 @@ static int remove_memory_section(unsigned long node_id,
741730
{
742731
struct memory_block *mem;
743732

744-
if (is_zone_device_section(section))
745-
return 0;
746-
747733
mutex_lock(&mem_sysfs_mutex);
734+
735+
/*
736+
* Some users of the memory hotplug do not want/need memblock to
737+
* track all sections. Skip over those.
738+
*/
748739
mem = find_memory_block(section);
740+
if (!mem)
741+
goto out_unlock;
742+
749743
unregister_mem_sect_under_nodes(mem, __section_nr(section));
750744

751745
mem->section_count--;
@@ -754,6 +748,7 @@ static int remove_memory_section(unsigned long node_id,
754748
else
755749
put_device(&mem->dev);
756750

751+
out_unlock:
757752
mutex_unlock(&mem_sysfs_mutex);
758753
return 0;
759754
}

‎include/linux/memory_hotplug.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ extern int __remove_pages(struct zone *zone, unsigned long start_pfn,
111111

112112
/* reasonably generic interface to expand the physical pages in a zone */
113113
extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn,
114-
unsigned long nr_pages);
114+
unsigned long nr_pages, bool want_memblock);
115115

116116
#ifdef CONFIG_NUMA
117117
extern int memory_add_physaddr_to_nid(u64 start);

‎mm/memory_hotplug.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
494494
}
495495

496496
static int __meminit __add_section(int nid, struct zone *zone,
497-
unsigned long phys_start_pfn)
497+
unsigned long phys_start_pfn, bool want_memblock)
498498
{
499499
int ret;
500500

@@ -511,6 +511,9 @@ static int __meminit __add_section(int nid, struct zone *zone,
511511
if (ret < 0)
512512
return ret;
513513

514+
if (!want_memblock)
515+
return 0;
516+
514517
return register_new_memory(nid, __pfn_to_section(phys_start_pfn));
515518
}
516519

@@ -521,7 +524,7 @@ static int __meminit __add_section(int nid, struct zone *zone,
521524
* add the new pages.
522525
*/
523526
int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn,
524-
unsigned long nr_pages)
527+
unsigned long nr_pages, bool want_memblock)
525528
{
526529
unsigned long i;
527530
int err = 0;
@@ -549,7 +552,7 @@ int __ref __add_pages(int nid, struct zone *zone, unsigned long phys_start_pfn,
549552
}
550553

551554
for (i = start_sec; i <= end_sec; i++) {
552-
err = __add_section(nid, zone, section_nr_to_pfn(i));
555+
err = __add_section(nid, zone, section_nr_to_pfn(i), want_memblock);
553556

554557
/*
555558
* EEXIST is finally dealt with by ioresource collision

0 commit comments

Comments
 (0)