Skip to contentSkip to conversation

mm/hugetlb: align cma on allocation order, not demotion order

PATCH Applied Frank van der Linden 4 participants 6 messages Apr 30, 2024 – May 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/hugetlb: align cma on allocation order, not demotion order

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.

Cc Roman Gushchin <[email protected]>
Fixes a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +1 -1
index 5dc3f5ea3a2e..cfe7b025c576 100644
@@ -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) {
Signature · 1 line
2.45.0.rc0.197.gbae5840b3b-goog
#1 lore raw

Note that this applies on top of:

https://lore.kernel.org/lkml/[email protected]/

..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.

Quoted 29 lines · Frank van der Linden

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.

Cc Roman Gushchin <[email protected]>
Fixes a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +1 -2
index 5dc3f5ea3a2e..cfe7b025c576 100644
@@ -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

Reviewed-by on v1 1/1
#2 lore raw
In reply to Frank van der Linden
Quoted 17 lines · Frank van der Linden

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.

Cc Roman Gushchin <[email protected]>
Fixes a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
---
  mm/hugetlb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +0 -0
index 5dc3f5ea3a2e..cfe7b025c576 100644

mm/hugetlb.c void __init hugetlb_cma_reserve(int order) · line 7800

Quoted 8 lines
mm/hugetlb.c +1 -1
@@ -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.

Signature · 3 lines
Cheers,

David / dhildenb
#3 lore raw
Quoted 23 lines · David Hildenbrand
Quoted 21 lines · Frank van der Linden

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.

Cc Roman Gushchin <[email protected]>
Fixes a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
---
  mm/hugetlb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +0 -1
index 5dc3f5ea3a2e..cfe7b025c576 100644
@@ -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,
Quoted 8 lines

mm/hugetlb.c void __init hugetlb_cma_reserve(int order) · line 7800

Quoted 4 lines
mm/hugetlb.c +1 -0
+                                     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.

Quoted 4 lines

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

Thanks!

Reviewed-by on v1 1/1
#4 lore raw
In reply to Frank van der Linden
Quoted 8 lines · Frank van der Linden

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.

Cc Roman Gushchin <[email protected]>
Fixes a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")

Thanks!

maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Frank van der Linden
Quoted 8 lines · Frank van der Linden

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.

Cc Roman Gushchin <[email protected]>
Fixes a01f43901cfb ("hugetlb: be sure to free demoted CMA pages to CMA")
Signature · 2 lines
Oscar Salvador
SUSE Labs