linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/hugetlb: align cma on allocation order, not demotion order
@ 2024-04-30 16:14 Frank van der Linden
  2024-04-30 16:20 ` Frank van der Linden
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Frank van der Linden @ 2024-04-30 16:14 UTC (permalink / raw)
  To: linux-mm, muchun.song, akpm
  Cc: linux-kernel, Frank van der Linden, Roman Gushchin

Align the CMA area for hugetlb gigantic pages to their size, not the
size that they can be demoted to. Otherwise there might be misaligned
sections at the start and end of the CMA area that will never be used
for hugetlb page allocations.

Signed-off-by: Frank van der Linden <fvdl@google.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Fixes: a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 5dc3f5ea3a2e..cfe7b025c576 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -7794,7 +7794,7 @@ void __init hugetlb_cma_reserve(int order)
 		 * huge page demotion.
 		 */
 		res = cma_declare_contiguous_nid(0, size, 0,
-					PAGE_SIZE << HUGETLB_PAGE_ORDER,
+					PAGE_SIZE << order,
 					HUGETLB_PAGE_ORDER, false, name,
 					&hugetlb_cma[nid], nid);
 		if (res) {
-- 
2.45.0.rc0.197.gbae5840b3b-goog



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

* Re: [PATCH] mm/hugetlb: align cma on allocation order, not demotion order
  2024-04-30 16:14 [PATCH] mm/hugetlb: align cma on allocation order, not demotion order Frank van der Linden
@ 2024-04-30 16:20 ` Frank van der Linden
  2024-05-02 13:15 ` David Hildenbrand
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Frank van der Linden @ 2024-04-30 16:20 UTC (permalink / raw)
  To: linux-mm, muchun.song, akpm; +Cc: linux-kernel, Roman Gushchin

Note that this applies on top of:

https://lore.kernel.org/lkml/20240404162515.527802-2-fvdl@google.com/

..which is in mm-stable right now. It's not a fixup of that patch,
though, it's a separate issue. Although they could be combined in to a
"fix arguments to cma_declare_contiguous_nid" commit.

On Tue, Apr 30, 2024 at 9:14 AM Frank van der Linden <fvdl@google.com> wrote:
>
> Align the CMA area for hugetlb gigantic pages to their size, not the
> size that they can be demoted to. Otherwise there might be misaligned
> sections at the start and end of the CMA area that will never be used
> for hugetlb page allocations.
>
> Signed-off-by: Frank van der Linden <fvdl@google.com>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Fixes: a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
> ---
>  mm/hugetlb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 5dc3f5ea3a2e..cfe7b025c576 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -7794,7 +7794,7 @@ void __init hugetlb_cma_reserve(int order)
>                  * huge page demotion.
>                  */
>                 res = cma_declare_contiguous_nid(0, size, 0,
> -                                       PAGE_SIZE << HUGETLB_PAGE_ORDER,
> +                                       PAGE_SIZE << order,
>                                         HUGETLB_PAGE_ORDER, false, name,
>                                         &hugetlb_cma[nid], nid);
>                 if (res) {
> --
> 2.45.0.rc0.197.gbae5840b3b-goog
>


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

* Re: [PATCH] mm/hugetlb: align cma on allocation order, not demotion order
  2024-04-30 16:14 [PATCH] mm/hugetlb: align cma on allocation order, not demotion order Frank van der Linden
  2024-04-30 16:20 ` Frank van der Linden
@ 2024-05-02 13:15 ` David Hildenbrand
  2024-05-02 17:27   ` Frank van der Linden
  2024-05-02 16:45 ` Roman Gushchin
  2024-05-08 10:13 ` Oscar Salvador
  3 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand @ 2024-05-02 13:15 UTC (permalink / raw)
  To: Frank van der Linden, linux-mm, muchun.song, akpm
  Cc: linux-kernel, Roman Gushchin

On 30.04.24 18:14, Frank van der Linden wrote:
> Align the CMA area for hugetlb gigantic pages to their size, not the
> size that they can be demoted to. Otherwise there might be misaligned
> sections at the start and end of the CMA area that will never be used
> for hugetlb page allocations.
> 
> Signed-off-by: Frank van der Linden <fvdl@google.com>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Fixes: a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
> ---
>   mm/hugetlb.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 5dc3f5ea3a2e..cfe7b025c576 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -7794,7 +7794,7 @@ void __init hugetlb_cma_reserve(int order)
>   		 * huge page demotion.
>   		 */
>   		res = cma_declare_contiguous_nid(0, size, 0,
> -					PAGE_SIZE << HUGETLB_PAGE_ORDER,
> +					PAGE_SIZE << order,
>   					HUGETLB_PAGE_ORDER, false, name,
>   					&hugetlb_cma[nid], nid);
>   		if (res) {

I was wondering how that worked when reviewing your other patch. 
Wondering why we never got a BUG report, maybe we were always lucky 
about the alignment we actually got?

We round up size to PAGE_SIZE << order, so that's the alignment we need.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



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

* Re: [PATCH] mm/hugetlb: align cma on allocation order, not demotion order
  2024-04-30 16:14 [PATCH] mm/hugetlb: align cma on allocation order, not demotion order Frank van der Linden
  2024-04-30 16:20 ` Frank van der Linden
  2024-05-02 13:15 ` David Hildenbrand
@ 2024-05-02 16:45 ` Roman Gushchin
  2024-05-08 10:13 ` Oscar Salvador
  3 siblings, 0 replies; 6+ messages in thread
From: Roman Gushchin @ 2024-05-02 16:45 UTC (permalink / raw)
  To: Frank van der Linden; +Cc: linux-mm, muchun.song, akpm, linux-kernel

On Tue, Apr 30, 2024 at 04:14:37PM +0000, Frank van der Linden wrote:
> Align the CMA area for hugetlb gigantic pages to their size, not the
> size that they can be demoted to. Otherwise there might be misaligned
> sections at the start and end of the CMA area that will never be used
> for hugetlb page allocations.
> 
> Signed-off-by: Frank van der Linden <fvdl@google.com>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Fixes: a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")

Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev>

Thanks!


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

* Re: [PATCH] mm/hugetlb: align cma on allocation order, not demotion order
  2024-05-02 13:15 ` David Hildenbrand
@ 2024-05-02 17:27   ` Frank van der Linden
  0 siblings, 0 replies; 6+ messages in thread
From: Frank van der Linden @ 2024-05-02 17:27 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-mm, muchun.song, akpm, linux-kernel, Roman Gushchin

On Thu, May 2, 2024 at 6:15 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 30.04.24 18:14, Frank van der Linden wrote:
> > Align the CMA area for hugetlb gigantic pages to their size, not the
> > size that they can be demoted to. Otherwise there might be misaligned
> > sections at the start and end of the CMA area that will never be used
> > for hugetlb page allocations.
> >
> > Signed-off-by: Frank van der Linden <fvdl@google.com>
> > Cc: Roman Gushchin <roman.gushchin@linux.dev>
> > Fixes: a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
> > ---
> >   mm/hugetlb.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > index 5dc3f5ea3a2e..cfe7b025c576 100644
> > --- a/mm/hugetlb.c
> > +++ b/mm/hugetlb.c
> > @@ -7794,7 +7794,7 @@ void __init hugetlb_cma_reserve(int order)
> >                * huge page demotion.
> >                */
> >               res = cma_declare_contiguous_nid(0, size, 0,
> > -                                     PAGE_SIZE << HUGETLB_PAGE_ORDER,
> > +                                     PAGE_SIZE << order,
> >                                       HUGETLB_PAGE_ORDER, false, name,
> >                                       &hugetlb_cma[nid], nid);
> >               if (res) {
>
> I was wondering how that worked when reviewing your other patch.
> Wondering why we never got a BUG report, maybe we were always lucky
> about the alignment we actually got?

I think this issue was probably masked by the hugetlb allocator
falling back to direct alloc_contig_pages allocation if cma_alloc
fails. So if you're not under memory pressure, the failure to allocate
from the misaligned areas might not have been noticed.

I noticed it, because I was working with change I made: a flag that
prevents the fallback to straight alloc_contig_pages, as that behavior
may not be desired - you don't want to potentially eat in to
non-movable space that the kernel needs, it might be better to fail if
there's no CMA available.
>
> We round up size to PAGE_SIZE << order, so that's the alignment we need.
>
> Reviewed-by: David Hildenbrand <david@redhat.com>

Thanks!


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

* Re: [PATCH] mm/hugetlb: align cma on allocation order, not demotion order
  2024-04-30 16:14 [PATCH] mm/hugetlb: align cma on allocation order, not demotion order Frank van der Linden
                   ` (2 preceding siblings ...)
  2024-05-02 16:45 ` Roman Gushchin
@ 2024-05-08 10:13 ` Oscar Salvador
  3 siblings, 0 replies; 6+ messages in thread
From: Oscar Salvador @ 2024-05-08 10:13 UTC (permalink / raw)
  To: Frank van der Linden
  Cc: linux-mm, muchun.song, akpm, linux-kernel, Roman Gushchin

On Tue, Apr 30, 2024 at 04:14:37PM +0000, Frank van der Linden wrote:
> Align the CMA area for hugetlb gigantic pages to their size, not the
> size that they can be demoted to. Otherwise there might be misaligned
> sections at the start and end of the CMA area that will never be used
> for hugetlb page allocations.
> 
> Signed-off-by: Frank van der Linden <fvdl@google.com>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Fixes: a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")

Reviewed-by: Oscar Salvador <osalvador@suse.de>


-- 
Oscar Salvador
SUSE Labs


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

end of thread, other threads:[~2024-05-08 10:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30 16:14 [PATCH] mm/hugetlb: align cma on allocation order, not demotion order Frank van der Linden
2024-04-30 16:20 ` Frank van der Linden
2024-05-02 13:15 ` David Hildenbrand
2024-05-02 17:27   ` Frank van der Linden
2024-05-02 16:45 ` Roman Gushchin
2024-05-08 10:13 ` Oscar Salvador

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