linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: hugetlb: fix per-node size calculation for hugetlb_cma
@ 2020-03-23 22:14 Roman Gushchin
  2020-03-23 23:34 ` [PATCH v2] " Roman Gushchin
  2020-03-23 23:36 ` [Potential Spoof] [PATCH] " Roman Gushchin
  0 siblings, 2 replies; 3+ messages in thread
From: Roman Gushchin @ 2020-03-23 22:14 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Aslan Barkirov, Michal Hocko, linux-mm, kernel-team,
	linux-kernel, Rik van Riel, Mike Kravetz, Roman Gushchin

Aslan found a bug in the per-node hugetlb_cma area size calculation:
the total remaining size should cap the per-node area size instead
of be the minimal possible allocation.

Without the fix:
[    0.004136] hugetlb_cma: reserve 2048 MiB, up to 1024 MiB per node
[    0.004138] cma: Reserved 2048 MiB at 0x0000000180000000
[    0.004139] hugetlb_cma: reserved 2048 MiB on node 0

With the fix:
[    0.006780] hugetlb_cma: reserve 2048 MiB, up to 1024 MiB per node
[    0.006786] cma: Reserved 1024 MiB at 0x00000001c0000000
[    0.006787] hugetlb_cma: reserved 1024 MiB on node 0
[    0.006788] cma: Reserved 1024 MiB at 0x00000003c0000000
[    0.006789] hugetlb_cma: reserved 1024 MiB on node 1

Reported-by: Aslan Barkirov <aslan@fb.com>
Signed-off-by: Roman Gushchin <guro@fb.com>
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 456f4c010fea..44b47c2b6fab 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5590,7 +5590,7 @@ void __init hugetlb_cma_reserve(int order)
 		min_pfn = min_low_pfn;
 		max_pfn = max_low_pfn;
 #endif
-		size = max(per_node, hugetlb_cma_size - reserved);
+		size = min(per_node, hugetlb_cma_size - reserved);
 		size = round_up(size, PAGE_SIZE << order);
 
 		if (size > ((max_pfn - min_pfn) << PAGE_SHIFT) / 2) {
-- 
2.25.1



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

* [PATCH v2] mm: hugetlb: fix per-node size calculation for hugetlb_cma
  2020-03-23 22:14 [PATCH] mm: hugetlb: fix per-node size calculation for hugetlb_cma Roman Gushchin
@ 2020-03-23 23:34 ` Roman Gushchin
  2020-03-23 23:36 ` [Potential Spoof] [PATCH] " Roman Gushchin
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Gushchin @ 2020-03-23 23:34 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Aslan Bakirov, Michal Hocko, linux-mm, kernel-team, linux-kernel,
	Rik van Riel, Mike Kravetz, Roman Gushchin

Aslan found a bug in the per-node hugetlb_cma area size calculation:
the total remaining size should cap the per-node area size instead
of be the minimal possible allocation.

Without the fix:
[    0.004136] hugetlb_cma: reserve 2048 MiB, up to 1024 MiB per node
[    0.004138] cma: Reserved 2048 MiB at 0x0000000180000000
[    0.004139] hugetlb_cma: reserved 2048 MiB on node 0

With the fix:
[    0.006780] hugetlb_cma: reserve 2048 MiB, up to 1024 MiB per node
[    0.006786] cma: Reserved 1024 MiB at 0x00000001c0000000
[    0.006787] hugetlb_cma: reserved 1024 MiB on node 0
[    0.006788] cma: Reserved 1024 MiB at 0x00000003c0000000
[    0.006789] hugetlb_cma: reserved 1024 MiB on node 1

Reported-by: Aslan Bakirov <aslan@fb.com>
Signed-off-by: Roman Gushchin <guro@fb.com>
---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 456f4c010fea..44b47c2b6fab 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5590,7 +5590,7 @@ void __init hugetlb_cma_reserve(int order)
 		min_pfn = min_low_pfn;
 		max_pfn = max_low_pfn;
 #endif
-		size = max(per_node, hugetlb_cma_size - reserved);
+		size = min(per_node, hugetlb_cma_size - reserved);
 		size = round_up(size, PAGE_SIZE << order);
 
 		if (size > ((max_pfn - min_pfn) << PAGE_SHIFT) / 2) {
-- 
2.25.1



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

* Re: [Potential Spoof] [PATCH] mm: hugetlb: fix per-node size calculation for hugetlb_cma
  2020-03-23 22:14 [PATCH] mm: hugetlb: fix per-node size calculation for hugetlb_cma Roman Gushchin
  2020-03-23 23:34 ` [PATCH v2] " Roman Gushchin
@ 2020-03-23 23:36 ` Roman Gushchin
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Gushchin @ 2020-03-23 23:36 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Aslan Bakirov, Michal Hocko, linux-mm, kernel-team, linux-kernel,
	Rik van Riel, Mike Kravetz

On Mon, Mar 23, 2020 at 03:14:11PM -0700, Roman Gushchin wrote:
> Aslan found a bug in the per-node hugetlb_cma area size calculation:
> the total remaining size should cap the per-node area size instead
> of be the minimal possible allocation.
> 
> Without the fix:
> [    0.004136] hugetlb_cma: reserve 2048 MiB, up to 1024 MiB per node
> [    0.004138] cma: Reserved 2048 MiB at 0x0000000180000000
> [    0.004139] hugetlb_cma: reserved 2048 MiB on node 0
> 
> With the fix:
> [    0.006780] hugetlb_cma: reserve 2048 MiB, up to 1024 MiB per node
> [    0.006786] cma: Reserved 1024 MiB at 0x00000001c0000000
> [    0.006787] hugetlb_cma: reserved 1024 MiB on node 0
> [    0.006788] cma: Reserved 1024 MiB at 0x00000003c0000000
> [    0.006789] hugetlb_cma: reserved 1024 MiB on node 1
> 
> Reported-by: Aslan Barkirov <aslan@fb.com>
> Signed-off-by: Roman Gushchin <guro@fb.com>

I'm deeply sorry, I've made a typo in Aslan's name.

v2 fixes this.

Thanks!


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

end of thread, other threads:[~2020-03-23 23:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 22:14 [PATCH] mm: hugetlb: fix per-node size calculation for hugetlb_cma Roman Gushchin
2020-03-23 23:34 ` [PATCH v2] " Roman Gushchin
2020-03-23 23:36 ` [Potential Spoof] [PATCH] " Roman Gushchin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).