Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* Re: [PATCH v7] hugetlbfs: Extend the definition of hugepages parameter to support node allocation
       [not found] <20210927104149.46884-1-yaozhenguo1@gmail.com>
@ 2021-09-29 19:24 ` Nathan Chancellor
  2021-09-29 22:27   ` Mike Rapoport
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2021-09-29 19:24 UTC (permalink / raw)
  To: Zhenguo Yao
  Cc: mike.kravetz, mpe, benh, paulus, corbet, rppt, akpm, yaozhenguo,
	willy, linux-kernel, linux-doc, linux-mm, llvm

On Mon, Sep 27, 2021 at 06:41:49PM +0800, Zhenguo Yao wrote:
> We can specify the number of hugepages to allocate at boot. But the
> hugepages is balanced in all nodes at present. In some scenarios,
> we only need hugepages in one node. For example: DPDK needs hugepages
> which are in the same node as NIC. if DPDK needs four hugepages of 1G
> size in node1 and system has 16 numa nodes. We must reserve 64 hugepages
> in kernel cmdline. But, only four hugepages are used. The others should
> be free after boot. If the system memory is low(for example: 64G), it will
> be an impossible task. So, Extending hugepages parameter to support
> specifying hugepages at a specific node.
> For example add following parameter:
> 
> hugepagesz=1G hugepages=0:1,1:3
> 
> It will allocate 1 hugepage in node0 and 3 hugepages in node1.
> 
> Signed-off-by: Zhenguo Yao <yaozhenguo1@gmail.com>

<snip>

> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 95dc7b83381f..ca00676a1bdd 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -66,6 +66,7 @@ static struct hstate * __initdata parsed_hstate;
>  static unsigned long __initdata default_hstate_max_huge_pages;
>  static bool __initdata parsed_valid_hugepagesz = true;
>  static bool __initdata parsed_default_hugepagesz;
> +static unsigned int default_hugepages_in_node[MAX_NUMNODES] __initdata;
>  
>  /*
>   * Protects updates to hugepage_freelists, hugepage_activelist, nr_huge_pages,
> @@ -2868,33 +2869,41 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
>  	return ERR_PTR(-ENOSPC);
>  }
>  
> -int alloc_bootmem_huge_page(struct hstate *h)
> +int alloc_bootmem_huge_page(struct hstate *h, int nid)
>  	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
> -int __alloc_bootmem_huge_page(struct hstate *h)
> +int __alloc_bootmem_huge_page(struct hstate *h, int nid)
>  {
>  	struct huge_bootmem_page *m;
>  	int nr_nodes, node;
>  
> +	if (nid >= nr_online_nodes)
> +		return 0;
> +	/* do node specific alloc */
> +	if (nid != NUMA_NO_NODE) {
> +		m = memblock_alloc_try_nid_raw(huge_page_size(h), huge_page_size(h),
> +				0, MEMBLOCK_ALLOC_ACCESSIBLE, nid);
> +		if (m)
> +			goto found;
> +		else
> +			return 0;
> +	}
> +	/* do all node balanced alloc */
>  	for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
> -		void *addr;
> -
> -		addr = memblock_alloc_try_nid_raw(
> +		m = memblock_alloc_try_nid_raw(
>  				huge_page_size(h), huge_page_size(h),
>  				0, MEMBLOCK_ALLOC_ACCESSIBLE, node);
> -		if (addr) {
> -			/*
> -			 * Use the beginning of the huge page to store the
> -			 * huge_bootmem_page struct (until gather_bootmem
> -			 * puts them into the mem_map).
> -			 */
> -			m = addr;
> +		/*
> +		 * Use the beginning of the huge page to store the
> +		 * huge_bootmem_page struct (until gather_bootmem
> +		 * puts them into the mem_map).
> +		 */
> +		if (m)
>  			goto found;
> -		}
> +		else
> +			return 0;
>  	}
> -	return 0;
>  
>  found:
> -	BUG_ON(!IS_ALIGNED(virt_to_phys(m), huge_page_size(h)));
>  	/* Put them into a private list first because mem_map is not up yet */
>  	INIT_LIST_HEAD(&m->list);
>  	list_add(&m->list, &huge_boot_pages);

This hunk causes a clang warning now:

mm/hugetlb.c:2957:33: error: variable 'm' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
        for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/hugetlb.c:1254:3: note: expanded from macro 'for_each_node_mask_to_alloc'
                nr_nodes > 0 &&                                         \
                ^~~~~~~~~~~~
mm/hugetlb.c:2974:18: note: uninitialized use occurs here
        INIT_LIST_HEAD(&m->list);
                        ^
mm/hugetlb.c:2957:33: note: remove the '&&' if its condition is always true
        for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
                                       ^
mm/hugetlb.c:2942:29: note: initialize the variable 'm' to silence this warning
        struct huge_bootmem_page *m;
                                   ^
                                    = NULL
1 error generated.

I am not sure if it is possible for nr_nodes to be 0 right out of the
gate so might be a false positive?

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v7] hugetlbfs: Extend the definition of hugepages parameter to support node allocation
  2021-09-29 19:24 ` [PATCH v7] hugetlbfs: Extend the definition of hugepages parameter to support node allocation Nathan Chancellor
@ 2021-09-29 22:27   ` Mike Rapoport
  2021-09-29 23:25     ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Rapoport @ 2021-09-29 22:27 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Zhenguo Yao, mike.kravetz, mpe, benh, paulus, corbet, akpm,
	yaozhenguo, willy, linux-kernel, linux-doc, linux-mm, llvm

On Wed, Sep 29, 2021 at 12:24:06PM -0700, Nathan Chancellor wrote:
> On Mon, Sep 27, 2021 at 06:41:49PM +0800, Zhenguo Yao wrote:
> > We can specify the number of hugepages to allocate at boot. But the
> > hugepages is balanced in all nodes at present. In some scenarios,
> > we only need hugepages in one node. For example: DPDK needs hugepages
> > which are in the same node as NIC. if DPDK needs four hugepages of 1G
> > size in node1 and system has 16 numa nodes. We must reserve 64 hugepages
> > in kernel cmdline. But, only four hugepages are used. The others should
> > be free after boot. If the system memory is low(for example: 64G), it will
> > be an impossible task. So, Extending hugepages parameter to support
> > specifying hugepages at a specific node.
> > For example add following parameter:
> > 
> > hugepagesz=1G hugepages=0:1,1:3
> > 
> > It will allocate 1 hugepage in node0 and 3 hugepages in node1.
> > 
> > Signed-off-by: Zhenguo Yao <yaozhenguo1@gmail.com>
> 
> <snip>
> 
> > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > index 95dc7b83381f..ca00676a1bdd 100644
> > --- a/mm/hugetlb.c
> > +++ b/mm/hugetlb.c
> > @@ -66,6 +66,7 @@ static struct hstate * __initdata parsed_hstate;
> >  static unsigned long __initdata default_hstate_max_huge_pages;
> >  static bool __initdata parsed_valid_hugepagesz = true;
> >  static bool __initdata parsed_default_hugepagesz;
> > +static unsigned int default_hugepages_in_node[MAX_NUMNODES] __initdata;
> >  
> >  /*
> >   * Protects updates to hugepage_freelists, hugepage_activelist, nr_huge_pages,
> > @@ -2868,33 +2869,41 @@ struct page *alloc_huge_page(struct vm_area_struct *vma,
> >  	return ERR_PTR(-ENOSPC);
> >  }
> >  
> > -int alloc_bootmem_huge_page(struct hstate *h)
> > +int alloc_bootmem_huge_page(struct hstate *h, int nid)
> >  	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
> > -int __alloc_bootmem_huge_page(struct hstate *h)
> > +int __alloc_bootmem_huge_page(struct hstate *h, int nid)
> >  {
> >  	struct huge_bootmem_page *m;
> >  	int nr_nodes, node;
> >  
> > +	if (nid >= nr_online_nodes)
> > +		return 0;
> > +	/* do node specific alloc */
> > +	if (nid != NUMA_NO_NODE) {
> > +		m = memblock_alloc_try_nid_raw(huge_page_size(h), huge_page_size(h),
> > +				0, MEMBLOCK_ALLOC_ACCESSIBLE, nid);
> > +		if (m)
> > +			goto found;
> > +		else
> > +			return 0;
> > +	}
> > +	/* do all node balanced alloc */
> >  	for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
> > -		void *addr;
> > -
> > -		addr = memblock_alloc_try_nid_raw(
> > +		m = memblock_alloc_try_nid_raw(
> >  				huge_page_size(h), huge_page_size(h),
> >  				0, MEMBLOCK_ALLOC_ACCESSIBLE, node);
> > -		if (addr) {
> > -			/*
> > -			 * Use the beginning of the huge page to store the
> > -			 * huge_bootmem_page struct (until gather_bootmem
> > -			 * puts them into the mem_map).
> > -			 */
> > -			m = addr;
> > +		/*
> > +		 * Use the beginning of the huge page to store the
> > +		 * huge_bootmem_page struct (until gather_bootmem
> > +		 * puts them into the mem_map).
> > +		 */
> > +		if (m)
> >  			goto found;
> > -		}
> > +		else
> > +			return 0;
> >  	}
> > -	return 0;
> >  
> >  found:
> > -	BUG_ON(!IS_ALIGNED(virt_to_phys(m), huge_page_size(h)));
> >  	/* Put them into a private list first because mem_map is not up yet */
> >  	INIT_LIST_HEAD(&m->list);
> >  	list_add(&m->list, &huge_boot_pages);
> 
> This hunk causes a clang warning now:
> 
> mm/hugetlb.c:2957:33: error: variable 'm' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
>         for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
>         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> mm/hugetlb.c:1254:3: note: expanded from macro 'for_each_node_mask_to_alloc'
>                 nr_nodes > 0 &&                                         \
>                 ^~~~~~~~~~~~
> mm/hugetlb.c:2974:18: note: uninitialized use occurs here
>         INIT_LIST_HEAD(&m->list);
>                         ^
> mm/hugetlb.c:2957:33: note: remove the '&&' if its condition is always true
>         for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
>                                        ^
> mm/hugetlb.c:2942:29: note: initialize the variable 'm' to silence this warning
>         struct huge_bootmem_page *m;
>                                    ^
>                                     = NULL
> 1 error generated.
> 
> I am not sure if it is possible for nr_nodes to be 0 right out of the
> gate so might be a false positive?

With nr_nodes == 0 there will be no memory in the system :)

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v7] hugetlbfs: Extend the definition of hugepages parameter to support node allocation
  2021-09-29 22:27   ` Mike Rapoport
@ 2021-09-29 23:25     ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2021-09-29 23:25 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Nathan Chancellor, Zhenguo Yao, mike.kravetz, mpe, benh, paulus,
	corbet, yaozhenguo, willy, linux-kernel, linux-doc, linux-mm,
	llvm

On Wed, 29 Sep 2021 15:27:18 -0700 Mike Rapoport <rppt@kernel.org> wrote:

> > mm/hugetlb.c:2957:33: error: variable 'm' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized]
> >         for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
> >         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > mm/hugetlb.c:1254:3: note: expanded from macro 'for_each_node_mask_to_alloc'
> >                 nr_nodes > 0 &&                                         \
> >                 ^~~~~~~~~~~~
> > mm/hugetlb.c:2974:18: note: uninitialized use occurs here
> >         INIT_LIST_HEAD(&m->list);
> >                         ^
> > mm/hugetlb.c:2957:33: note: remove the '&&' if its condition is always true
> >         for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) {
> >                                        ^
> > mm/hugetlb.c:2942:29: note: initialize the variable 'm' to silence this warning
> >         struct huge_bootmem_page *m;
> >                                    ^
> >                                     = NULL
> > 1 error generated.
> > 
> > I am not sure if it is possible for nr_nodes to be 0 right out of the
> > gate so might be a false positive?
> 
> With nr_nodes == 0 there will be no memory in the system :)

Let's keep clang happy?

--- a/mm/hugetlb.c~hugetlbfs-extend-the-definition-of-hugepages-parameter-to-support-node-allocation-fix
+++ a/mm/hugetlb.c
@@ -2939,7 +2939,7 @@ int alloc_bootmem_huge_page(struct hstat
 	__attribute__ ((weak, alias("__alloc_bootmem_huge_page")));
 int __alloc_bootmem_huge_page(struct hstate *h, int nid)
 {
-	struct huge_bootmem_page *m;
+	struct huge_bootmem_page *m = NULL;	/* initialize for clang */
 	int nr_nodes, node;
 
 	if (nid >= nr_online_nodes)
_


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-29 23:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20210927104149.46884-1-yaozhenguo1@gmail.com>
2021-09-29 19:24 ` [PATCH v7] hugetlbfs: Extend the definition of hugepages parameter to support node allocation Nathan Chancellor
2021-09-29 22:27   ` Mike Rapoport
2021-09-29 23:25     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox