Skip to contentSkip to conversation

mm/hugetlb: Allow arch to override and call the weak function

PATCH Superseded Aneesh Kumar K.V 3 participants 9 messages Jul 27, 2017 – Jul 28, 2017

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 mm/hugetlb: Allow arch to override and call the weak function

For ppc64, we want to call this function when we are not running as guest. Also, if we failed to allocate hugepages, let the user know.

---
 include/linux/hugetlb.h | 1 +
 mm/hugetlb.c            | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
include/linux/hugetlb.h +1 -0
index 0ed8e41aaf11..8bbbd37ab105 100644
@@ -358,6 +358,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 			pgoff_t idx);
 
 /* arch callback */
+int __init __alloc_bootmem_huge_page(struct hstate *h);
 int __init alloc_bootmem_huge_page(struct hstate *h);
 
 void __init hugetlb_bad_size(void);
mm/hugetlb.c +4 -1
index bc48ee783dd9..a3a7a7e6339e 100644
@@ -2083,7 +2083,9 @@ struct page *alloc_huge_page_noerr(struct vm_area_struct *vma,
 	return page;
 }
 
-int __weak alloc_bootmem_huge_page(struct hstate *h)
+int alloc_bootmem_huge_page(struct hstate *h)
+	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
+int __alloc_bootmem_huge_page(struct hstate *h)
 {
 	struct huge_bootmem_page *m;
 	int nr_nodes, node;
@@ -2104,6 +2106,7 @@ int __weak alloc_bootmem_huge_page(struct hstate *h)
 			goto found;
 		}
 	}
+	pr_info("Failed to allocate hugepage of size %ld\n", huge_page_size(h));
 	return 0;
 
 found:
Signature · 7 lines
2.13.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH v3 2/3 powerpc/mm/hugetlb: Add support for reserving gigantic huge pages via kernel command line

With commit aa888a74977a8 ("hugetlb: support larger than MAX_ORDER") we added support for allocating gigantic hugepages via kernel command line. Switch ppc64 arch specific code to use that.

W.r.t FSL support, we now limit our allocation range using BOOTMEM_ALLOC_ACCESSIBLE.

We use the kernel command line to do reservation of hugetlb pages on powernv platforms. On pseries hash mmu mode the supported gigantic huge page size is 16GB and that can only be allocated with hypervisor assist. For pseries the command line option doesn't do the allocation. Instead pseries does gigantic hugepage allocation based on hypervisor hint that is specified via "ibm,expected#pages" property of the memory node.

Cc Scott Wood <[email protected]>
Cc Christophe Leroy <[email protected]>
---
 arch/powerpc/include/asm/book3s/64/mmu-hash.h |   2 +-
 arch/powerpc/include/asm/hugetlb.h            |  14 --
 arch/powerpc/kernel/setup-common.c            |   7 -
 arch/powerpc/mm/hash_utils_64.c               |   2 +-
 arch/powerpc/mm/hugetlbpage.c                 | 177 +++-----------------------
 arch/powerpc/mm/init_32.c                     |   2 -
 6 files changed, 22 insertions(+), 182 deletions(-)
arch/powerpc/include/asm/book3s/64/mmu-hash.h +1 -1
index 6981a52b3887..f28d21c69f79 100644
@@ -468,7 +468,7 @@ extern int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
 			     int psize, int ssize);
 int htab_remove_mapping(unsigned long vstart, unsigned long vend,
 			int psize, int ssize);
-extern void add_gpage(u64 addr, u64 page_size, unsigned long number_of_pages);
+extern void pseries_add_gpage(u64 addr, u64 page_size, unsigned long number_of_pages);
 extern void demote_segment_4k(struct mm_struct *mm, unsigned long addr);
 
 #ifdef CONFIG_PPC_PSERIES
arch/powerpc/include/asm/hugetlb.h +0 -14
index 7f4025a6c69e..b8a0fb442c64 100644
@@ -218,18 +218,4 @@ static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
 }
 #endif /* CONFIG_HUGETLB_PAGE */
 
-/*
- * FSL Book3E platforms require special gpage handling - the gpages
- * are reserved early in the boot process by memblock instead of via
- * the .dts as on IBM platforms.
- */
-#if defined(CONFIG_HUGETLB_PAGE) && (defined(CONFIG_PPC_FSL_BOOK3E) || \
-    defined(CONFIG_PPC_8xx))
-extern void __init reserve_hugetlb_gpages(void);
-#else
-static inline void reserve_hugetlb_gpages(void)
-{
-}
-#endif
-
 #endif /* _ASM_POWERPC_HUGETLB_H */
arch/powerpc/kernel/setup-common.c +0 -7
index 94a948207cd2..0f896f17d5ab 100644
@@ -916,13 +916,6 @@ void __init setup_arch(char **cmdline_p)
 	/* Reserve large chunks of memory for use by CMA for KVM. */
 	kvm_cma_reserve();
 
-	/*
-	 * Reserve any gigantic pages requested on the command line.
-	 * memblock needs to have been initialized by the time this is
-	 * called since this will reserve memory.
-	 */
-	reserve_hugetlb_gpages();
-
 	klp_init_thread_info(&init_thread_info);
 
 	init_mm.start_code = (unsigned long)_stext;
arch/powerpc/mm/hash_utils_64.c +1 -1
index 7a20669c19e7..2f1f6bc04012 100644
@@ -509,7 +509,7 @@ static int __init htab_dt_scan_hugepage_blocks(unsigned long node,
 			phys_addr, block_size, expected_pages);
 	if (phys_addr + (16 * GB) <= memblock_end_of_DRAM()) {
 		memblock_reserve(phys_addr, block_size * expected_pages);
-		add_gpage(phys_addr, block_size, expected_pages);
+		pseries_add_gpage(phys_addr, block_size, expected_pages);
 	}
 	return 0;
 }
arch/powerpc/mm/hugetlbpage.c +20 -157

207 lines not on this page · raw message

arch/powerpc/mm/init_32.c +0 -2
index 8a7c38b8d335..436d9721ab63 100644
@@ -132,8 +132,6 @@ void __init MMU_init(void)
 	 * Reserve gigantic pages for hugetlb.  This MUST occur before
 	 * lowmem_end_addr is initialized below.
 	 */
-	reserve_hugetlb_gpages();
-
 	if (memblock.memory.cnt > 1) {
 #ifndef CONFIG_WII
 		memblock_enforce_memory_limit(memblock.memory.regions[0].size);
Signature · 7 lines
2.13.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH v3 3/3 powerpc/mm/hugetlb: Allow runtime allocation of 16G.

In reply to Aneesh Kumar K.V

We now have GIGANTIC_PAGE on powerpc. Currently this is enabled only on radix with 1G as gigantic hugepage size. Enable this with hash translation mode too (ie, with 16G hugepage size). Depending on the total system memory we may be able to allocate 16G hugepage size. This bring parity between radix and hash translation mode. Also reduce the confusion of the user with respect to hugetlbfs usage.

---
 arch/powerpc/include/asm/book3s/64/hugetlb.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/powerpc/include/asm/book3s/64/hugetlb.h +1 -3
index 5c28bd6f2ae1..2d1ca488ca44 100644
@@ -54,9 +54,7 @@ static inline pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
 #ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
 static inline bool gigantic_page_supported(void)
 {
-	if (radix_enabled())
-		return true;
-	return false;
+	return true;
 }
 #endif
 
Signature · 7 lines
2.13.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
In reply to Aneesh Kumar K.V
Quoted 1 line · Aneesh Kumar K.V

For ppc64, we want to call this function when we are not running as guest.

What does this mean?

Quoted 51 lines

Also, if we failed to allocate hugepages, let the user know.

---
 include/linux/hugetlb.h | 1 +
 mm/hugetlb.c            | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
include/linux/hugetlb.h +1 -0
index 0ed8e41aaf11..8bbbd37ab105 100644
@@ -358,6 +358,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 			pgoff_t idx);
 
 /* arch callback */
+int __init __alloc_bootmem_huge_page(struct hstate *h);
 int __init alloc_bootmem_huge_page(struct hstate *h);
 
 void __init hugetlb_bad_size(void);
mm/hugetlb.c +4 -1
index bc48ee783dd9..a3a7a7e6339e 100644
@@ -2083,7 +2083,9 @@ struct page *alloc_huge_page_noerr(struct vm_area_struct *vma,
 	return page;
 }
 
-int __weak alloc_bootmem_huge_page(struct hstate *h)
+int alloc_bootmem_huge_page(struct hstate *h)
+	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
+int __alloc_bootmem_huge_page(struct hstate *h)
 {
 	struct huge_bootmem_page *m;
 	int nr_nodes, node;
@@ -2104,6 +2106,7 @@ int __weak alloc_bootmem_huge_page(struct hstate *h)
 			goto found;
 		}
 	}
+	pr_info("Failed to allocate hugepage of size %ld\n", huge_page_size(h));
 	return 0;
 
 found:
Signature · 7 lines
2.13.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw
In reply to Aneesh Kumar K.V
Quoted 3 lines · Aneesh Kumar K.V

For ppc64, we want to call this function when we are not running as guest. Also, if we failed to allocate hugepages, let the user know.

[...]

Quoted 16 lines
mm/hugetlb.c +3 -1
index bc48ee783dd9..a3a7a7e6339e 100644
@@ -2083,7 +2083,9 @@ struct page *alloc_huge_page_noerr(struct vm_area_struct *vma,
 	return page;
 }
 
-int __weak alloc_bootmem_huge_page(struct hstate *h)
+int alloc_bootmem_huge_page(struct hstate *h)
+	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
+int __alloc_bootmem_huge_page(struct hstate *h)
 {
 	struct huge_bootmem_page *m;
 	int nr_nodes, node;

mm/hugetlb.c int __weak alloc_bootmem_huge_page(struct hstate *h) · line 2112

Quoted 7 lines
mm/hugetlb.c +1 -0
@@ -2104,6 +2106,7 @@ int __weak alloc_bootmem_huge_page(struct hstate *h)
 			goto found;
 		}
 	}
+	pr_info("Failed to allocate hugepage of size %ld\n", huge_page_size(h));
 	return 0;
 
 found:

There is already a call to warn the user in the hugetlb_hstate_alloc_pages function. If you look there, you will see that the huge_page_size was translated into a more user friendly format and the count prior to the failure is included. What call path are you trying to cover? Also, you may want your print to be a pr_warn since it is a failure?

Thanks,
Liam

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 27 lines · Liam R. Howlett
Quoted 3 lines · Aneesh Kumar K.V

For ppc64, we want to call this function when we are not running as guest. Also, if we failed to allocate hugepages, let the user know.

[...]

Quoted 22 lines
mm/hugetlb.c +4 -1
index bc48ee783dd9..a3a7a7e6339e 100644
@@ -2083,7 +2083,9 @@ struct page *alloc_huge_page_noerr(struct vm_area_struct *vma,
  	return page;
  }
 
-int __weak alloc_bootmem_huge_page(struct hstate *h)
+int alloc_bootmem_huge_page(struct hstate *h)
+	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
+int __alloc_bootmem_huge_page(struct hstate *h)
  {
  	struct huge_bootmem_page *m;
  	int nr_nodes, node;
@@ -2104,6 +2106,7 @@ int __weak alloc_bootmem_huge_page(struct hstate *h)
  			goto found;
  		}
  	}
+	pr_info("Failed to allocate hugepage of size %ld\n", huge_page_size(h));
  	return 0;
 
Quoted 9 lines

mm/hugetlb.c int __weak alloc_bootmem_huge_page(struct hstate *h) · line 2112

Quoted 1 line
mm/hugetlb.c +0 -0
  found:

There is already a call to warn the user in the hugetlb_hstate_alloc_pages function. If you look there, you will see that the huge_page_size was translated into a more user friendly format and the count prior to the failure is included. What call path are you trying to cover? Also, you may want your print to be a pr_warn since it is a failure?

Sorry I missed that in the recent kernel. I wrote the above before the mentioned changes was done. I will drop the pr_info from the patch.

Thanks
-aneesh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
In reply to Michal Hocko
Quoted 5 lines · Michal Hocko
Quoted 1 line · Aneesh Kumar K.V

For ppc64, we want to call this function when we are not running as guest.

What does this mean?

ppc64 guest (aka LPAR) support a different mechanism for hugetlb allocation/reservation. The LPAR management application called HMC can be used to reserve a set of hugepages and we pass the details of reserved pages via device tree to the guest. You can find the details in htab_dt_scan_hugepage_blocks() . We do the memblock_reserve of the range and later in the boot sequence, we just add the reserved range to
huge_boot_pages.

For baremetal config (when we are not running as guest) we want to follow what other architecture does, that is look at the command line and do memblock allocation. Hence the need to call generic function __alloc_bootmem_huge_page() in that case.

I can add all these details in to the commit message if that makes it easy ?

-aneesh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
In reply to Aneesh Kumar K.V
Quoted 38 lines · Aneesh Kumar K.V
Quoted 25 lines · Liam R. Howlett
Quoted 3 lines · Aneesh Kumar K.V

For ppc64, we want to call this function when we are not running as guest. Also, if we failed to allocate hugepages, let the user know.

[...]

Quoted 20 lines
mm/hugetlb.c +4 -1
index bc48ee783dd9..a3a7a7e6339e 100644
@@ -2083,7 +2083,9 @@ struct page *alloc_huge_page_noerr(struct vm_area_struct *vma,
  	return page;
  }
-int __weak alloc_bootmem_huge_page(struct hstate *h)
+int alloc_bootmem_huge_page(struct hstate *h)
+	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
+int __alloc_bootmem_huge_page(struct hstate *h)
  {
  	struct huge_bootmem_page *m;
  	int nr_nodes, node;
@@ -2104,6 +2106,7 @@ int __weak alloc_bootmem_huge_page(struct hstate *h)
  			goto found;
  		}
  	}
+	pr_info("Failed to allocate hugepage of size %ld\n", huge_page_size(h));
  	return 0;
Quoted 9 lines

mm/hugetlb.c int __weak alloc_bootmem_huge_page(struct hstate *h) · line 2111

Quoted 1 line
mm/hugetlb.c +0 -0
  found:

There is already a call to warn the user in the hugetlb_hstate_alloc_pages function. If you look there, you will see that the huge_page_size was translated into a more user friendly format and the count prior to the failure is included. What call path are you trying to cover? Also, you may want your print to be a pr_warn since it is a failure?

Quoted 2 lines

Sorry I missed that in the recent kernel. I wrote the above before the mentioned changes was done. I will drop the pr_info from the patch.

Okay, thanks. I didn't think there was a code path that was missed on boot.

Cheers,
Liam

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
In reply to Aneesh Kumar K.V
Quoted 17 lines · Aneesh Kumar K.V
Quoted 5 lines · Michal Hocko
Quoted 1 line · Aneesh Kumar K.V

For ppc64, we want to call this function when we are not running as guest.

What does this mean?

ppc64 guest (aka LPAR) support a different mechanism for hugetlb allocation/reservation. The LPAR management application called HMC can be used to reserve a set of hugepages and we pass the details of reserved pages via device tree to the guest. You can find the details in htab_dt_scan_hugepage_blocks() . We do the memblock_reserve of the range and later in the boot sequence, we just add the reserved range to huge_boot_pages.

Quoted 6 lines

For baremetal config (when we are not running as guest) we want to follow what other architecture does, that is look at the command line and do memblock allocation. Hence the need to call generic function __alloc_bootmem_huge_page() in that case.

I can add all these details in to the commit message if that makes it easy ?

It certainly helped me to understand the context much better. Thanks! As you are patching a generic code this would be appropriate IMHO.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>