summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2019-07-18 18:58:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-18 20:08:07 -0400
commite9c0a3f05477e18d2dae816cb61b62be1b7e90d3 (patch)
tree2749369b31e1c646b076592ea63af34a7cc9079f
parent49ba3c6b37b38b58251c27864f551908c583e99d (diff)
mm/sparsemem: convert kmalloc_section_memmap() to populate_section_memmap()
Allow sub-section sized ranges to be added to the memmap. populate_section_memmap() takes an explict pfn range rather than assuming a full section, and those parameters are plumbed all the way through to vmmemap_populate(). There should be no sub-section usage in current deployments. New warnings are added to clarify which memmap allocation paths are sub-section capable. Link: http://lkml.kernel.org/r/156092352058.979959.6551283472062305149.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Pavel Tatashin <pasha.tatashin@soleen.com> Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> [ppc64] Reviewed-by: Oscar Salvador <osalvador@suse.de> Cc: Michal Hocko <mhocko@suse.com> Cc: David Hildenbrand <david@redhat.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Jane Chu <jane.chu@oracle.com> Cc: Jeff Moyer <jmoyer@redhat.com> Cc: Jérôme Glisse <jglisse@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Toshi Kani <toshi.kani@hpe.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Wei Yang <richardw.yang@linux.intel.com> Cc: Jason Gunthorpe <jgg@mellanox.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/x86/mm/init_64.c4
-rw-r--r--include/linux/mm.h4
-rw-r--r--mm/sparse-vmemmap.c21
-rw-r--r--mm/sparse.c50
4 files changed, 46 insertions, 33 deletions
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 5a289a2ab108..a6b5c653727b 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1518,7 +1518,9 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
1518{ 1518{
1519 int err; 1519 int err;
1520 1520
1521 if (boot_cpu_has(X86_FEATURE_PSE)) 1521 if (end - start < PAGES_PER_SECTION * sizeof(struct page))
1522 err = vmemmap_populate_basepages(start, end, node);
1523 else if (boot_cpu_has(X86_FEATURE_PSE))
1522 err = vmemmap_populate_hugepages(start, end, node, altmap); 1524 err = vmemmap_populate_hugepages(start, end, node, altmap);
1523 else if (altmap) { 1525 else if (altmap) {
1524 pr_err_once("%s: no cpu support for altmap allocations\n", 1526 pr_err_once("%s: no cpu support for altmap allocations\n",
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 48ab7b982d82..0334ca97c584 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2767,8 +2767,8 @@ static inline void print_vma_addr(char *prefix, unsigned long rip)
2767#endif 2767#endif
2768 2768
2769void *sparse_buffer_alloc(unsigned long size); 2769void *sparse_buffer_alloc(unsigned long size);
2770struct page *sparse_mem_map_populate(unsigned long pnum, int nid, 2770struct page * __populate_section_memmap(unsigned long pfn,
2771 struct vmem_altmap *altmap); 2771 unsigned long nr_pages, int nid, struct vmem_altmap *altmap);
2772pgd_t *vmemmap_pgd_populate(unsigned long addr, int node); 2772pgd_t *vmemmap_pgd_populate(unsigned long addr, int node);
2773p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node); 2773p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node);
2774pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node); 2774pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node);
diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 7fec05796796..200aef686722 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -245,19 +245,26 @@ int __meminit vmemmap_populate_basepages(unsigned long start,
245 return 0; 245 return 0;
246} 246}
247 247
248struct page * __meminit sparse_mem_map_populate(unsigned long pnum, int nid, 248struct page * __meminit __populate_section_memmap(unsigned long pfn,
249 struct vmem_altmap *altmap) 249 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
250{ 250{
251 unsigned long start; 251 unsigned long start;
252 unsigned long end; 252 unsigned long end;
253 struct page *map;
254 253
255 map = pfn_to_page(pnum * PAGES_PER_SECTION); 254 /*
256 start = (unsigned long)map; 255 * The minimum granularity of memmap extensions is
257 end = (unsigned long)(map + PAGES_PER_SECTION); 256 * PAGES_PER_SUBSECTION as allocations are tracked in the
257 * 'subsection_map' bitmap of the section.
258 */
259 end = ALIGN(pfn + nr_pages, PAGES_PER_SUBSECTION);
260 pfn &= PAGE_SUBSECTION_MASK;
261 nr_pages = end - pfn;
262
263 start = (unsigned long) pfn_to_page(pfn);
264 end = start + nr_pages * sizeof(struct page);
258 265
259 if (vmemmap_populate(start, end, nid, altmap)) 266 if (vmemmap_populate(start, end, nid, altmap))
260 return NULL; 267 return NULL;
261 268
262 return map; 269 return pfn_to_page(pfn);
263} 270}
diff --git a/mm/sparse.c b/mm/sparse.c
index 26b48ee1a262..6b01022e23a9 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -439,8 +439,8 @@ static unsigned long __init section_map_size(void)
439 return PAGE_ALIGN(sizeof(struct page) * PAGES_PER_SECTION); 439 return PAGE_ALIGN(sizeof(struct page) * PAGES_PER_SECTION);
440} 440}
441 441
442struct page __init *sparse_mem_map_populate(unsigned long pnum, int nid, 442struct page __init *__populate_section_memmap(unsigned long pfn,
443 struct vmem_altmap *altmap) 443 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
444{ 444{
445 unsigned long size = section_map_size(); 445 unsigned long size = section_map_size();
446 struct page *map = sparse_buffer_alloc(size); 446 struct page *map = sparse_buffer_alloc(size);
@@ -521,10 +521,13 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin,
521 } 521 }
522 sparse_buffer_init(map_count * section_map_size(), nid); 522 sparse_buffer_init(map_count * section_map_size(), nid);
523 for_each_present_section_nr(pnum_begin, pnum) { 523 for_each_present_section_nr(pnum_begin, pnum) {
524 unsigned long pfn = section_nr_to_pfn(pnum);
525
524 if (pnum >= pnum_end) 526 if (pnum >= pnum_end)
525 break; 527 break;
526 528
527 map = sparse_mem_map_populate(pnum, nid, NULL); 529 map = __populate_section_memmap(pfn, PAGES_PER_SECTION,
530 nid, NULL);
528 if (!map) { 531 if (!map) {
529 pr_err("%s: node[%d] memory map backing failed. Some memory will not be available.", 532 pr_err("%s: node[%d] memory map backing failed. Some memory will not be available.",
530 __func__, nid); 533 __func__, nid);
@@ -625,17 +628,17 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
625#endif 628#endif
626 629
627#ifdef CONFIG_SPARSEMEM_VMEMMAP 630#ifdef CONFIG_SPARSEMEM_VMEMMAP
628static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, 631static struct page *populate_section_memmap(unsigned long pfn,
629 struct vmem_altmap *altmap) 632 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
630{ 633{
631 /* This will make the necessary allocations eventually. */ 634 return __populate_section_memmap(pfn, nr_pages, nid, altmap);
632 return sparse_mem_map_populate(pnum, nid, altmap);
633} 635}
634static void __kfree_section_memmap(struct page *memmap, 636
637static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,
635 struct vmem_altmap *altmap) 638 struct vmem_altmap *altmap)
636{ 639{
637 unsigned long start = (unsigned long)memmap; 640 unsigned long start = (unsigned long) pfn_to_page(pfn);
638 unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION); 641 unsigned long end = start + nr_pages * sizeof(struct page);
639 642
640 vmemmap_free(start, end, altmap); 643 vmemmap_free(start, end, altmap);
641} 644}
@@ -647,7 +650,8 @@ static void free_map_bootmem(struct page *memmap)
647 vmemmap_free(start, end, NULL); 650 vmemmap_free(start, end, NULL);
648} 651}
649#else 652#else
650static struct page *__kmalloc_section_memmap(void) 653struct page *populate_section_memmap(unsigned long pfn,
654 unsigned long nr_pages, int nid, struct vmem_altmap *altmap)
651{ 655{
652 struct page *page, *ret; 656 struct page *page, *ret;
653 unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION; 657 unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION;
@@ -668,15 +672,11 @@ got_map_ptr:
668 return ret; 672 return ret;
669} 673}
670 674
671static inline struct page *kmalloc_section_memmap(unsigned long pnum, int nid, 675static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,
672 struct vmem_altmap *altmap) 676 struct vmem_altmap *altmap)
673{ 677{
674 return __kmalloc_section_memmap(); 678 struct page *memmap = pfn_to_page(pfn);
675}
676 679
677static void __kfree_section_memmap(struct page *memmap,
678 struct vmem_altmap *altmap)
679{
680 if (is_vmalloc_addr(memmap)) 680 if (is_vmalloc_addr(memmap))
681 vfree(memmap); 681 vfree(memmap);
682 else 682 else
@@ -745,12 +745,13 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn,
745 if (ret < 0 && ret != -EEXIST) 745 if (ret < 0 && ret != -EEXIST)
746 return ret; 746 return ret;
747 ret = 0; 747 ret = 0;
748 memmap = kmalloc_section_memmap(section_nr, nid, altmap); 748 memmap = populate_section_memmap(start_pfn, PAGES_PER_SECTION, nid,
749 altmap);
749 if (!memmap) 750 if (!memmap)
750 return -ENOMEM; 751 return -ENOMEM;
751 usage = kzalloc(mem_section_usage_size(), GFP_KERNEL); 752 usage = kzalloc(mem_section_usage_size(), GFP_KERNEL);
752 if (!usage) { 753 if (!usage) {
753 __kfree_section_memmap(memmap, altmap); 754 depopulate_section_memmap(start_pfn, PAGES_PER_SECTION, altmap);
754 return -ENOMEM; 755 return -ENOMEM;
755 } 756 }
756 757
@@ -773,7 +774,7 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn,
773out: 774out:
774 if (ret < 0) { 775 if (ret < 0) {
775 kfree(usage); 776 kfree(usage);
776 __kfree_section_memmap(memmap, altmap); 777 depopulate_section_memmap(start_pfn, PAGES_PER_SECTION, altmap);
777 } 778 }
778 return ret; 779 return ret;
779} 780}
@@ -809,7 +810,8 @@ static inline void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
809#endif 810#endif
810 811
811static void free_section_usage(struct mem_section *ms, struct page *memmap, 812static void free_section_usage(struct mem_section *ms, struct page *memmap,
812 struct mem_section_usage *usage, struct vmem_altmap *altmap) 813 struct mem_section_usage *usage, unsigned long pfn,
814 unsigned long nr_pages, struct vmem_altmap *altmap)
813{ 815{
814 if (!usage) 816 if (!usage)
815 return; 817 return;
@@ -820,7 +822,7 @@ static void free_section_usage(struct mem_section *ms, struct page *memmap,
820 if (!early_section(ms)) { 822 if (!early_section(ms)) {
821 kfree(usage); 823 kfree(usage);
822 if (memmap) 824 if (memmap)
823 __kfree_section_memmap(memmap, altmap); 825 depopulate_section_memmap(pfn, nr_pages, altmap);
824 return; 826 return;
825 } 827 }
826 828
@@ -849,6 +851,8 @@ void sparse_remove_one_section(struct mem_section *ms, unsigned long map_offset,
849 851
850 clear_hwpoisoned_pages(memmap + map_offset, 852 clear_hwpoisoned_pages(memmap + map_offset,
851 PAGES_PER_SECTION - map_offset); 853 PAGES_PER_SECTION - map_offset);
852 free_section_usage(ms, memmap, usage, altmap); 854 free_section_usage(ms, memmap, usage,
855 section_nr_to_pfn(__section_nr(ms)),
856 PAGES_PER_SECTION, altmap);
853} 857}
854#endif /* CONFIG_MEMORY_HOTPLUG */ 858#endif /* CONFIG_MEMORY_HOTPLUG */