Skip to contentSkip to conversation

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

PATCH In review Aneesh Kumar K.V 2 participants 4 messages May 16, 2017 – May 18, 2017 PowerPC

lore
Share & tools
lore
#0 lore raw

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

We use the kernel command line to do reservation of hugetlb pages. The code duplcation here is mostly to make it simpler. With 64 bit book3s, we need to support either 16G or 1G gigantic hugepage. Whereas the FSL_BOOK3E implementation needs to support multiple gigantic hugepage. We avoid the gpage_npages array and use a gpage_npage count for ppc64. We also cannot use the generic code to do the gigantic page allocation because that will require conditonal to handle the pseries allocation, where the memory is already reserved by the hypervisor.

Inorder to keep it simpler, book3s 64 implements a version that keeps it simpler and working with pseries.

---
 arch/powerpc/include/asm/hugetlb.h |  8 +---
 arch/powerpc/mm/hugetlbpage.c      | 78 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/hugetlb.h +1 -7
index 7f4025a6c69e..03401a17d1da 100644
@@ -218,13 +218,7 @@ 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))
+#ifdef CONFIG_HUGETLB_PAGE
 extern void __init reserve_hugetlb_gpages(void);
 #else
 static inline void reserve_hugetlb_gpages(void)
arch/powerpc/mm/hugetlbpage.c +78 -0

90 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw
Quoted 15 lines · Aneesh Kumar K.V
arch/powerpc/mm/hugetlbpage.c +15 -0
+void __init reserve_hugetlb_gpages(void)
+{
+	char buf[10];
+	phys_addr_t base;
+	unsigned long gpage_size = 1UL << 34;
+	static __initdata char cmdline[COMMAND_LINE_SIZE];
+
+	if (radix_enabled())
+		gpage_size = 1UL << 30;
+
+	strlcpy(cmdline, boot_command_line, COMMAND_LINE_SIZE);
+	parse_args("hugetlb gpages", cmdline, NULL, 0, 0, 0,
+		   NULL, &do_gpage_early_setup);
+
+	if (!gpage_npages)

arch/powerpc/mm/hugetlbpage.c int alloc_bootmem_huge_page(struct hstate *hstate) · line 449

Quoted 10 lines
arch/powerpc/mm/hugetlbpage.c +10 -0
+		return;
+
+	string_get_size(gpage_size, 1, STRING_UNITS_2, buf, sizeof(buf));
+	pr_info("Trying to reserve %ld %s pages\n", gpage_npages, buf);
+
+	/* Allocate one page at a time */
+	while(gpage_npages) {
+		base = memblock_alloc_base(gpage_size, gpage_size,
+					   MEMBLOCK_ALLOC_ANYWHERE);
+		add_gpage(base, gpage_size, 1);

For 16GB pages (1UL << 34) on POWER8, we already do these functions inside htab_dt_scan_hugepage_blocks(). IIUC this happens just by scanning DT without even specifying any gpages in kernel command line.

memblock_reserve()
add_gpage()

Then attempting to allocate from memblock and adding it again into gigantic pages list wont collide ? More over its trying to allocate across the RAM not specifically on the gpages mentioned in device tree by the platform. Are we trying to support 16GB pages just from any memory without platform notification through DT ?

#2 lore raw
Quoted 32 lines · Anshuman Khandual
Quoted 15 lines · Aneesh Kumar K.V
arch/powerpc/mm/hugetlbpage.c +15 -0
+void __init reserve_hugetlb_gpages(void)
+{
+	char buf[10];
+	phys_addr_t base;
+	unsigned long gpage_size = 1UL << 34;
+	static __initdata char cmdline[COMMAND_LINE_SIZE];
+
+	if (radix_enabled())
+		gpage_size = 1UL << 30;
+
+	strlcpy(cmdline, boot_command_line, COMMAND_LINE_SIZE);
+	parse_args("hugetlb gpages", cmdline, NULL, 0, 0, 0,
+		   NULL, &do_gpage_early_setup);
+
+	if (!gpage_npages)

arch/powerpc/mm/hugetlbpage.c int alloc_bootmem_huge_page(struct hstate *hstate) · line 449

Quoted 10 lines
arch/powerpc/mm/hugetlbpage.c +10 -0
+		return;
+
+	string_get_size(gpage_size, 1, STRING_UNITS_2, buf, sizeof(buf));
+	pr_info("Trying to reserve %ld %s pages\n", gpage_npages, buf);
+
+	/* Allocate one page at a time */
+	while(gpage_npages) {
+		base = memblock_alloc_base(gpage_size, gpage_size,
+					   MEMBLOCK_ALLOC_ANYWHERE);
+		add_gpage(base, gpage_size, 1);

For 16GB pages (1UL << 34) on POWER8, we already do these functions inside htab_dt_scan_hugepage_blocks(). IIUC this happens just by scanning DT without even specifying any gpages in kernel command line.

Quoted 5 lines

memblock_reserve()
add_gpage()

Then attempting to allocate from memblock and adding it again into gigantic pages list wont collide ?

That is for pseries.ie, pSeries will get the hugpages reserved by phyp and the details of those pages are passed via device tree. Not sure what is the conflict here. If we use the above kernel parameter, we will try to allocate another 'x' number of hugepages.

Quoted 5 lines

More over its trying to allocate
across the RAM not specifically on the gpages mentioned in device tree by the platform. Are we trying to support 16GB pages just from any memory without platform notification through DT ?

There are two ways to specify gpages, one via device tree which is used only in case of pseries and other hugepagesz=size hugepags=no-of-hugepages.

-aneesh

#3 lore raw
Quoted 46 lines · Aneesh Kumar K.V
Quoted 32 lines · Anshuman Khandual
Quoted 15 lines · Aneesh Kumar K.V
arch/powerpc/mm/hugetlbpage.c +15 -0
+void __init reserve_hugetlb_gpages(void)
+{
+    char buf[10];
+    phys_addr_t base;
+    unsigned long gpage_size = 1UL << 34;
+    static __initdata char cmdline[COMMAND_LINE_SIZE];
+
+    if (radix_enabled())
+        gpage_size = 1UL << 30;
+
+    strlcpy(cmdline, boot_command_line, COMMAND_LINE_SIZE);
+    parse_args("hugetlb gpages", cmdline, NULL, 0, 0, 0,
+           NULL, &do_gpage_early_setup);
+
+    if (!gpage_npages)

arch/powerpc/mm/hugetlbpage.c int alloc_bootmem_huge_page(struct hstate *hstate) · line 449

Quoted 10 lines
arch/powerpc/mm/hugetlbpage.c +10 -0
+        return;
+
+    string_get_size(gpage_size, 1, STRING_UNITS_2, buf, sizeof(buf));
+    pr_info("Trying to reserve %ld %s pages\n", gpage_npages, buf);
+
+    /* Allocate one page at a time */
+    while(gpage_npages) {
+        base = memblock_alloc_base(gpage_size, gpage_size,
+                       MEMBLOCK_ALLOC_ANYWHERE);
+        add_gpage(base, gpage_size, 1);

For 16GB pages (1UL << 34) on POWER8, we already do these functions inside htab_dt_scan_hugepage_blocks(). IIUC this happens just by scanning DT without even specifying any gpages in kernel command line.

Quoted 5 lines

memblock_reserve()
add_gpage()

Then attempting to allocate from memblock and adding it again into gigantic pages list wont collide ?

That is for pseries.ie, pSeries will get the hugpages reserved by phyp and the details of those pages are passed via device tree. Not sure what is the conflict here. If we use the above kernel parameter, we will try to allocate another 'x' number of hugepages.

Quoted 8 lines
Quoted 5 lines

More over its trying to allocate
across the RAM not specifically on the gpages mentioned in device tree by the platform. Are we trying to support 16GB pages just from any memory without platform notification through DT ?

There are two ways to specify gpages, one via device tree which is used only in case of pseries and other hugepagesz=size hugepags=no-of-hugepages.

New way (Added with this patch)
-------------------------------
setup_arch()
reserve_hugetlb_page() (Now defined for PPC64 BOOK3S)

reserve_hugetlb_page() allocate 1GB (radix) / 16GB (hash) from the memblock during boot (with memblock_alloc_base()) looking into the kernel command line parameters for HugeTLB gigantic pages. It then calls add_gpage() which populates gpage_freearray[] which remains local to powerpc arch.

Existing DT (pseries on PHYP)
-----------------------------
early_setup()
early_init_devtree()
mmu_early_init_devtree()
hash__early_init_devtree()
htab_scan_page_sizes()
htab_dt_scan_hugepage_blocks()

htab_dt_scan_hugepage_blocks() scans and adds individual PHYP reserved 16GB pages huge pages into gpage_freearray[] through add_gpage() call.

The same kernel command line parameters then create the hstate structure for the gigantic pages in generic HugeTLB and which then calls alloc_ bootmem_huge_page() transferring the local gpages details stored in gpage_freearray[] to generic huge_boot_pages. I hope my understanding here is correct, please do correct me otherwise.

DT scanned gpages are first reserved with memblock_reserve() hence then wont be used during memblock_alloc_base() called from the other method. Hence no race during add_gpage() on system using both methods simultaneously. I dont see anything preventing reserve_hugetlb_page() being called on pseries systems though in which case may allocate gigantic pages more than required if there are some already available through DT path. Will look into this further.