diff mbox

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

Message ID 20170727061828.11406-1-aneesh.kumar@linux.vnet.ibm.com (mailing list archive)
State Superseded
Headers show

Commit Message

Aneesh Kumar K.V July 27, 2017, 6:18 a.m. UTC
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.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 include/linux/hugetlb.h | 1 +
 mm/hugetlb.c            | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Michal Hocko July 27, 2017, 1:01 p.m. UTC | #1
On Thu 27-07-17 11:48:26, Aneesh Kumar K.V wrote:
> For ppc64, we want to call this function when we are not running as guest.

What does this mean?

> Also, if we failed to allocate hugepages, let the user know.
> 
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> ---
>  include/linux/hugetlb.h | 1 +
>  mm/hugetlb.c            | 5 ++++-
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 0ed8e41aaf11..8bbbd37ab105 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -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);
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index bc48ee783dd9..a3a7a7e6339e 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -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:
> -- 
> 2.13.3
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
Liam R. Howlett July 27, 2017, 3:25 p.m. UTC | #2
* Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> [170727 02:18]:
> 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.
> 
[...]
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index bc48ee783dd9..a3a7a7e6339e 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -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:

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
Aneesh Kumar K.V July 27, 2017, 4:12 p.m. UTC | #3
On 07/27/2017 08:55 PM, Liam R. Howlett wrote:
> * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> [170727 02:18]:
>> 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.
>>
> [...]
>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
>> index bc48ee783dd9..a3a7a7e6339e 100644
>> --- a/mm/hugetlb.c
>> +++ b/mm/hugetlb.c
>> @@ -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:
> 
> 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
Aneesh Kumar K.V July 27, 2017, 4:20 p.m. UTC | #4
On 07/27/2017 06:31 PM, Michal Hocko wrote:
> On Thu 27-07-17 11:48:26, Aneesh Kumar K.V wrote:
>> 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
Liam R. Howlett July 27, 2017, 5:38 p.m. UTC | #5
* Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> [170727 12:12]:
> 
> 
> On 07/27/2017 08:55 PM, Liam R. Howlett wrote:
> > * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> [170727 02:18]:
> > > 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.
> > > 
> > [...]
> > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > > index bc48ee783dd9..a3a7a7e6339e 100644
> > > --- a/mm/hugetlb.c
> > > +++ b/mm/hugetlb.c
> > > @@ -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:
> > 
> > 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.

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

Cheers,
Liam
Michal Hocko July 28, 2017, 7:06 a.m. UTC | #6
On Thu 27-07-17 21:50:35, Aneesh Kumar K.V wrote:
> 
> 
> On 07/27/2017 06:31 PM, Michal Hocko wrote:
> >On Thu 27-07-17 11:48:26, Aneesh Kumar K.V wrote:
> >>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 ?

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

Patch

diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 0ed8e41aaf11..8bbbd37ab105 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -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);
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bc48ee783dd9..a3a7a7e6339e 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -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: