Skip to contentSkip to conversation

Cleanups and fixup for page_alloc

PATCH Superseded Miaohe Lin 7 participants 36 messages Aug 30, 2021 – Sep 2, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

cover Cleanups and fixup for page_alloc

Hi all,
This series contains cleanups to remove meaningless VM_BUG_ON(), use helpers to simplify the code and remove obsolete comment. Also we fix the potential accessing to uninitialized pcp page migratetype and so on. More details can be found in the respective changelogs. Thanks!

Miaohe Lin (6):
mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order() mm/page_alloc.c: simplify the code by using macro K() mm/page_alloc.c: remove obsolete comment in free_pcppages_bulk() mm/page_alloc.c: use helper function zone_spans_pfn() mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype mm/page_alloc.c: avoid allocating highmem pages via
alloc_pages_exact_nid()

 mm/page_alloc.c | 35 +++++++++++------------------------
 1 file changed, 11 insertions(+), 24 deletions(-)
Signature · 1 line
2.23.0
author
#1 lore raw

PATCH 1/6 mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order()

It's meaningless to VM_BUG_ON() order != pageblock_order just after setting order to pageblock_order. Remove it.

---
 mm/page_alloc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
mm/page_alloc.c +1 -3
index 91edb930b8ab..dbb3338d9287 100644
@@ -677,10 +677,8 @@ static inline int pindex_to_order(unsigned int pindex)
 	int order = pindex / MIGRATE_PCPTYPES;
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-	if (order > PAGE_ALLOC_COSTLY_ORDER) {
+	if (order > PAGE_ALLOC_COSTLY_ORDER)
 		order = pageblock_order;
-		VM_BUG_ON(order != pageblock_order);
-	}
 #else
 	VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER);
 #endif
Signature · 1 line
2.23.0
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order()

Quoted 4 lines · Miaohe Lin

It's meaningless to VM_BUG_ON() order != pageblock_order just after setting order to pageblock_order. Remove it.

Signature · 2 lines
Mel Gorman
SUSE Labs
Reviewed-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] mm/page_alloc.c: remove meaningless VM_BUG_ON() in pindex_to_order()

In reply to Miaohe Lin
Quoted 15 lines · Miaohe Lin

It's meaningless to VM_BUG_ON() order != pageblock_order just after setting order to pageblock_order. Remove it.

---
  mm/page_alloc.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
mm/page_alloc.c +0 -0
index 91edb930b8ab..dbb3338d9287 100644
@@ -677,10 +677,8 @@ static inline int pindex_to_order(unsigned int pindex)
  	int order = pindex / MIGRATE_PCPTYPES;

mm/page_alloc.c static inline int pindex_to_order(unsigned int pindex) · line 684

Quoted 10 lines
mm/page_alloc.c +1 -3
 
  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-	if (order > PAGE_ALLOC_COSTLY_ORDER) {
+	if (order > PAGE_ALLOC_COSTLY_ORDER)
  		order = pageblock_order;
-		VM_BUG_ON(order != pageblock_order);
-	}
  #else
  	VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER);
  #endif
Signature · 3 lines
Thanks,

David / dhildenb
author
#4 lore raw

PATCH 2/6 mm/page_alloc.c: simplify the code by using macro K()

In reply to Miaohe Lin

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---
 mm/page_alloc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +5 -7
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 	}
 
 	if (pages && s)
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
 	return pages;
 }
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
 		", %luK highmem"
 #endif
 		")\n",
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
 		codesize >> 10, datasize >> 10, rosize >> 10,
 		(init_data_size + init_code_size) >> 10, bss_size >> 10,
-		(physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT - 10),
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
 #ifdef	CONFIG_HIGHMEM
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
 #endif
 		);
 }
Signature · 1 line
2.23.0
#5 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

Hello.

Quoted 23 lines · On pondělí 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote:

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---
 mm/page_alloc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +1 -2
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void
 *end, int poison, const char }
 
 	if (pages && s)
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
 	return pages;
 }

mm/page_alloc.c void __init mem_init_print_info(void) · line 8187

Quoted 9 lines
mm/page_alloc.c +1 -3
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
 		", %luK highmem"
 #endif
 		")\n",
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
 		codesize >> 10, datasize >> 10, rosize >> 10,
 		(init_data_size + init_code_size) >> 10, bss_size >> 10,
-		(physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT 

- 10),

mm/page_alloc.c void __init mem_init_print_info(void) · line 8191

Quoted 9 lines
mm/page_alloc.c +3 -2
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
 #ifdef	CONFIG_HIGHMEM
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
 #endif
 		);
 }

(my concern is not quite within the scope of this submission, but I'll ask anyway)

Given we have this:

```
git grep '#define K(x)' v5.14
v5.14:drivers/base/node.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:drivers/net/hamradio/scc.c:#define K(x) kiss->x
v5.14:kernel/debug/kdb/kdb_main.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/backing-dev.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/memcontrol.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/oom_kill.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/page_alloc.c:#define K(x) ((x) << (PAGE_SHIFT-10))
```

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Thanks.

Signature · 1 line
Oleksandr Natalenko (post-factum)
author
#6 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

Quoted 62 lines · Oleksandr Natalenko

Hello.

Quoted 23 lines · On pondělí 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote:

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---
 mm/page_alloc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +1 -2
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void
 *end, int poison, const char }
 
 	if (pages && s)
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
 	return pages;
 }

mm/page_alloc.c void __init mem_init_print_info(void) · line 8187

Quoted 9 lines
mm/page_alloc.c +1 -3
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
 		", %luK highmem"
 #endif
 		")\n",
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
 		codesize >> 10, datasize >> 10, rosize >> 10,
 		(init_data_size + init_code_size) >> 10, bss_size >> 10,
-		(physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT 

- 10),

mm/page_alloc.c void __init mem_init_print_info(void) · line 8191

Quoted 9 lines
mm/page_alloc.c +3 -2
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
 #ifdef	CONFIG_HIGHMEM
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
 #endif
 		);
 }

(my concern is not quite within the scope of this submission, but I'll ask anyway)

Given we have this:

```
git grep '#define K(x)' v5.14
v5.14:drivers/base/node.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:drivers/net/hamradio/scc.c:#define K(x) kiss->x
v5.14:kernel/debug/kdb/kdb_main.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/backing-dev.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/memcontrol.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/oom_kill.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/page_alloc.c:#define K(x) ((x) << (PAGE_SHIFT-10))
```
Quoted 2 lines

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Many thanks for figuring this out. I think we should get rid of these repetitions too. But I'am not sure where this definition should be. Any suggestion? Thanks.

Quoted 3 lines

Thanks.

#7 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

Hello.

Quoted 80 lines · On úterý 31. srpna 2021 13:08:42 CEST Miaohe Lin wrote:
Quoted 79 lines · Oleksandr Natalenko

Hello.

Quoted 32 lines · On pondělí 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote:

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---

 mm/page_alloc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +1 -2
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void
 *end, int poison, const char }
 
 	if (pages && s)
 
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
 	return pages;

}

mm/page_alloc.c +0 -0
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
 
 		", %luK highmem"
 
 #endif
 

mm/page_alloc.c void __init mem_init_print_info(void) · line 8193

Quoted 10 lines
mm/page_alloc.c +1 -3
 		")\n",
 
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
 
 		codesize >> 10, datasize >> 10, rosize >> 10,
 		(init_data_size + init_code_size) >> 10, bss_size >> 10,
 
-		(physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT

- 10),

Quoted 4 lines
mm/page_alloc.c +2 -1
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
 

mm/page_alloc.c void __init mem_init_print_info(void) · line 8191

Quoted 10 lines
mm/page_alloc.c +1 -1
 #ifdef	CONFIG_HIGHMEM
 
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
 
 #endif
 
 		);
 
 }

(my concern is not quite within the scope of this submission, but I'll ask anyway)

Given we have this:

```
git grep '#define K(x)' v5.14
v5.14:drivers/base/node.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:drivers/net/hamradio/scc.c:#define K(x) kiss->x
v5.14:kernel/debug/kdb/kdb_main.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/backing-dev.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/memcontrol.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/oom_kill.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/page_alloc.c:#define K(x) ((x) << (PAGE_SHIFT-10))
```
Quoted 6 lines
Quoted 2 lines

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Many thanks for figuring this out. I think we should get rid of these repetitions too. But I'am not sure where this definition should be. Any suggestion? Thanks.

I'm not sure what place suits best. At first I thought maybe linux/mm.h or linux/mm_inline.h, but since PAGE_SHIFT is declared in asm-generic/page.h, probably K(x) can also go there as well?

Signature · 1 line
Oleksandr Natalenko (post-factum)
author
#8 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

Quoted 86 lines · Oleksandr Natalenko

Hello.

Quoted 83 lines · On úterý 31. srpna 2021 13:08:42 CEST Miaohe Lin wrote:
Quoted 81 lines · Oleksandr Natalenko

Hello.

Quoted 32 lines · On pondělí 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote:

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---

 mm/page_alloc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +1 -2
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void
 *end, int poison, const char }
 
 	if (pages && s)
 
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
 	return pages;

}

mm/page_alloc.c +0 -0
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
 
 		", %luK highmem"
 
 #endif
 

mm/page_alloc.c void __init mem_init_print_info(void) · line 8193

Quoted 10 lines
mm/page_alloc.c +1 -3
 		")\n",
 
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
 
 		codesize >> 10, datasize >> 10, rosize >> 10,
 		(init_data_size + init_code_size) >> 10, bss_size >> 10,
 
-		(physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT

- 10),

Quoted 4 lines
mm/page_alloc.c +2 -1
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
 

mm/page_alloc.c void __init mem_init_print_info(void) · line 8191

Quoted 10 lines
mm/page_alloc.c +1 -1
 #ifdef	CONFIG_HIGHMEM
 
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
 
 #endif
 
 		);
 
 }

(my concern is not quite within the scope of this submission, but I'll ask anyway)

Given we have this:

```
git grep '#define K(x)' v5.14
v5.14:drivers/base/node.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:drivers/net/hamradio/scc.c:#define K(x) kiss->x
v5.14:kernel/debug/kdb/kdb_main.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/backing-dev.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/memcontrol.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/oom_kill.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/page_alloc.c:#define K(x) ((x) << (PAGE_SHIFT-10))
```

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Quoted 7 lines
Quoted 3 lines

Many thanks for figuring this out. I think we should get rid of these repetitions too. But I'am not sure where this definition should be. Any suggestion? Thanks.

I'm not sure what place suits best. At first I thought maybe linux/mm.h or linux/mm_inline.h, but since PAGE_SHIFT is declared in asm-generic/page.h, probably K(x) can also go there as well?

K(x) is relevant with PAGE_SHIFT. So I think K(x) can also go asm-generic/page.h too. Am I supposed to do this when free or will you kindly do this?

Many thanks.

Quoted 1 line
#9 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

Hello.

Quoted 39 lines · On středa 1. září 2021 9:37:49 CEST Miaohe Lin wrote:
Quoted 38 lines · Oleksandr Natalenko
Quoted 37 lines · On úterý 31. srpna 2021 13:08:42 CEST Miaohe Lin wrote:
Quoted 36 lines · Oleksandr Natalenko
Quoted 35 lines · On pondělí 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote:

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---

 mm/page_alloc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +0 -0
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start,

void
*end, int poison, const char }

mm/page_alloc.c +1 -2
 	if (pages && s)
 
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
 	return pages;
 
 }
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
 
 		", %luK highmem"
 
 #endif
 
 		")\n",
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

mm/page_alloc.c void __init mem_init_print_info(void)

Quoted 8 lines
mm/page_alloc.c +1 -3
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
 
 		codesize >> 10, datasize >> 10, rosize >> 10,
 		(init_data_size + init_code_size) >> 10, bss_size >> 10,
 
-		(physpages - totalram_pages() - totalcma_pages) << 

(PAGE_SHIFT

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 36 lines

- 10),

Quoted 4 lines
mm/page_alloc.c +2 -1
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
 

mm/page_alloc.c void __init mem_init_print_info(void) · line 8191

Quoted 10 lines
mm/page_alloc.c +1 -1
 #ifdef	CONFIG_HIGHMEM
 
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
 
 #endif
 
 		);
 
 }

(my concern is not quite within the scope of this submission, but I'll ask
anyway)

Given we have this:

```
git grep '#define K(x)' v5.14
v5.14:drivers/base/node.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:drivers/net/hamradio/scc.c:#define K(x) kiss->x
v5.14:kernel/debug/kdb/kdb_main.c:#define K(x) ((x) << (PAGE_SHIFT -
10))
v5.14:mm/backing-dev.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/memcontrol.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/oom_kill.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/page_alloc.c:#define K(x) ((x) << (PAGE_SHIFT-10))
```
Quoted 2 lines

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Many thanks for figuring this out. I think we should get rid of these repetitions too. But I'am not sure where this definition should be. Any suggestion? Thanks.

Quoted 6 lines
Quoted 3 lines

I'm not sure what place suits best. At first I thought maybe linux/mm.h or linux/mm_inline.h, but since PAGE_SHIFT is declared in asm-generic/page.h, probably K(x) can also go there as well?

K(x) is relevant with PAGE_SHIFT. So I think K(x) can also go asm-generic/page.h too.

Actually, the comment in this file says:

```
4 /*
5  * Generic page.h implementation, for NOMMU architectures.
6  * This provides the dummy definitions for the memory management.
7  */
```

so it seems I was wrong about this being an appropriate place.

Quoted 2 lines

Am I supposed to do this when free or will you
kindly do this?

Let me just try to cram this into mm.h and send it out, and then we'll see what comments people suggest.

Thanks.

Signature · 1 line
Oleksandr Natalenko (post-factum)
author
#10 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

Quoted 103 lines · Oleksandr Natalenko

Hello.

Quoted 39 lines · On středa 1. září 2021 9:37:49 CEST Miaohe Lin wrote:
Quoted 38 lines · Oleksandr Natalenko
Quoted 37 lines · On úterý 31. srpna 2021 13:08:42 CEST Miaohe Lin wrote:
Quoted 36 lines · Oleksandr Natalenko
Quoted 35 lines · On pondělí 30. srpna 2021 16:10:47 CEST Miaohe Lin wrote:

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---

 mm/page_alloc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +0 -0
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start,

void
*end, int poison, const char }

mm/page_alloc.c +1 -2
 	if (pages && s)
 
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
 	return pages;
 
 }
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
 
 		", %luK highmem"
 
 #endif
 
 		")\n",
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

mm/page_alloc.c void __init mem_init_print_info(void)

Quoted 8 lines
mm/page_alloc.c +1 -3
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
 
 		codesize >> 10, datasize >> 10, rosize >> 10,
 		(init_data_size + init_code_size) >> 10, bss_size >> 10,
 
-		(physpages - totalram_pages() - totalcma_pages) << 

(PAGE_SHIFT

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines
Quoted 36 lines

- 10),

Quoted 4 lines
mm/page_alloc.c +2 -1
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
 

mm/page_alloc.c void __init mem_init_print_info(void) · line 8191

Quoted 10 lines
mm/page_alloc.c +1 -1
 #ifdef	CONFIG_HIGHMEM
 
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
 
 #endif
 
 		);
 
 }

(my concern is not quite within the scope of this submission, but I'll ask
anyway)

Given we have this:

```
git grep '#define K(x)' v5.14
v5.14:drivers/base/node.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:drivers/net/hamradio/scc.c:#define K(x) kiss->x
v5.14:kernel/debug/kdb/kdb_main.c:#define K(x) ((x) << (PAGE_SHIFT -
10))
v5.14:mm/backing-dev.c:#define K(x) ((x) << (PAGE_SHIFT - 10))
v5.14:mm/memcontrol.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/oom_kill.c:#define K(x) ((x) << (PAGE_SHIFT-10))
v5.14:mm/page_alloc.c:#define K(x) ((x) << (PAGE_SHIFT-10))
```
Quoted 2 lines

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Many thanks for figuring this out. I think we should get rid of these repetitions too. But I'am not sure where this definition should be. Any suggestion? Thanks.

Quoted 6 lines
Quoted 3 lines

I'm not sure what place suits best. At first I thought maybe linux/mm.h or linux/mm_inline.h, but since PAGE_SHIFT is declared in asm-generic/page.h, probably K(x) can also go there as well?

K(x) is relevant with PAGE_SHIFT. So I think K(x) can also go asm-generic/page.h too.

Actually, the comment in this file says:

Quoted 8 lines
```
4 /*
5  * Generic page.h implementation, for NOMMU architectures.
6  * This provides the dummy definitions for the memory management.
7  */
```

so it seems I was wrong about this being an appropriate place.

It's hard to find the appropriate place.

Quoted 7 lines
Quoted 3 lines

Am I supposed to do this when free or will you
kindly do this?

Let me just try to cram this into mm.h and send it out, and then we'll see what comments people suggest.

Many thanks for doing this. :)

Quoted 2 lines

Thanks.

#11 lore raw

RE: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

In reply to Miaohe Lin

From: Miaohe Lin

Quoted 1 line

Sent: 01 September 2021 08:38

...

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Many thanks for figuring this out. I think we should get rid of these repetitions too. But I'am not sure where this definition should be. Any suggestion? Thanks.

Quoted 6 lines
Quoted 3 lines

I'm not sure what place suits best. At first I thought maybe linux/mm.h or linux/mm_inline.h, but since PAGE_SHIFT is declared in asm-generic/page.h, probably K(x) can also go there as well?

K(x) is relevant with PAGE_SHIFT. So I think K(x) can also go asm-generic/page.h too. Am I supposed to do this when free or will you kindly do this?

It is a bit of a short name to go in a public header file.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author
#12 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

Quoted 10 lines · David Laight

From: Miaohe Lin

Quoted 1 line

Sent: 01 September 2021 08:38

...

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Shouldn't this macro go to some header file instead to get rid of define repetitions?

Many thanks for figuring this out. I think we should get rid of these repetitions too. But I'am not sure where this definition should be. Any suggestion? Thanks.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

I'm not sure what place suits best. At first I thought maybe linux/mm.h or linux/mm_inline.h, but since PAGE_SHIFT is declared in asm-generic/page.h, probably K(x) can also go there as well?

K(x) is relevant with PAGE_SHIFT. So I think K(x) can also go asm-generic/page.h too. Am I supposed to do this when free or will you kindly do this?

It is a bit of a short name to go in a public header file.

It seems K(x) is a bit of short and it needs a more self-annotated name. We can discuss this there:
https://lkml.org/lkml/2021/9/1/334

Thanks.

Quoted 6 lines

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

Reviewed-by on v1 2/6
#14 lore raw

Re: [PATCH 2/6] mm/page_alloc.c: simplify the code by using macro K()

In reply to Miaohe Lin
Quoted 32 lines · Miaohe Lin

Use helper macro K() to convert the pages to the corresponding size. Minor readability improvement.

---
  mm/page_alloc.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
mm/page_alloc.c +2 -4
index dbb3338d9287..d3983244f56f 100644
@@ -8134,8 +8134,7 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
  	}
 
  	if (pages && s)
-		pr_info("Freeing %s memory: %ldK\n",
-			s, pages << (PAGE_SHIFT - 10));
+		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
 
  	return pages;
  }
@@ -8180,14 +8179,13 @@ void __init mem_init_print_info(void)
  		", %luK highmem"
  #endif
  		")\n",
-		nr_free_pages() << (PAGE_SHIFT - 10),
-		physpages << (PAGE_SHIFT - 10),
+		K(nr_free_pages()), K(physpages),
  		codesize >> 10, datasize >> 10, rosize >> 10,
  		(init_data_size + init_code_size) >> 10, bss_size >> 10,

mm/page_alloc.c void __init mem_init_print_info(void) · line 8191

Quoted 10 lines
mm/page_alloc.c +3 -3
-		(physpages - totalram_pages() - totalcma_pages) << (PAGE_SHIFT - 10),
-		totalcma_pages << (PAGE_SHIFT - 10)
+		K(physpages - totalram_pages() - totalcma_pages),
+		K(totalcma_pages)
  #ifdef	CONFIG_HIGHMEM
-		, totalhigh_pages() << (PAGE_SHIFT - 10)
+		, K(totalhigh_pages())
  #endif
  		);
  }
Signature · 3 lines
Thanks,

David / dhildenb
author
#15 lore raw

PATCH 3/6 mm/page_alloc.c: remove obsolete comment in free_pcppages_bulk()

In reply to Miaohe Lin

It's also confusing now. Remove it.

---
 mm/page_alloc.c | 11 -----------
 1 file changed, 11 deletions(-)
mm/page_alloc.c +0 -11
index d3983244f56f..b5edcfe112aa 100644
@@ -1424,17 +1424,6 @@ static inline void prefetch_buddy(struct page *page)
 	prefetch(buddy);
 }
 
-/*
- * Frees a number of pages from the PCP lists
- * Assumes all pages on list are in same zone, and of same order.
- * count is the number of pages to free.
- *
- * If the zone was previously in an "all pages pinned" state then look to
- * see if this freeing clears that state.
- *
- * And clear the zone's pages_scanned counter, to hold off the "all pages are
- * pinned" detection logic.
- */
 static void free_pcppages_bulk(struct zone *zone, int count,
 					struct per_cpu_pages *pcp)
 {
Signature · 1 line
2.23.0
#16 lore raw

Re: [PATCH 3/6] mm/page_alloc.c: remove obsolete comment in free_pcppages_bulk()

Quoted 2 lines · Miaohe Lin

It's also confusing now. Remove it.

Why is the whole comment obsolete?

The second two paragraphs about "all pages pinned" and pages_scanned is obsolete and can go but the first paragraph is valid.

Signature · 2 lines
Mel Gorman
SUSE Labs
author
#17 lore raw

Re: [PATCH 3/6] mm/page_alloc.c: remove obsolete comment in free_pcppages_bulk()

Quoted 9 lines · Mel Gorman
Quoted 2 lines · Miaohe Lin

It's also confusing now. Remove it.

Why is the whole comment obsolete?

The second two paragraphs about "all pages pinned" and pages_scanned is obsolete and can go but the first paragraph is valid.

I think the first paragraph is invalid due to the below statement:
"Assumes all pages on list are in same zone, and of same order." There are NR_PCP_LISTS lists and PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP orders in pcp. So I think it's obsolete.

Should I delete this statement in the first paragraph only?

Many Thanks.

#18 lore raw

Re: [PATCH 3/6] mm/page_alloc.c: remove obsolete comment in free_pcppages_bulk()

Quoted 7 lines · Miaohe Lin
Quoted 6 lines · Mel Gorman
Quoted 2 lines · Miaohe Lin

It's also confusing now. Remove it.

Why is the whole comment obsolete?

Quoted 9 lines
Quoted 3 lines

The second two paragraphs about "all pages pinned" and pages_scanned is obsolete and can go but the first paragraph is valid.

I think the first paragraph is invalid due to the below statement:
"Assumes all pages on list are in same zone, and of same order." There are NR_PCP_LISTS lists and PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP orders in pcp. So I think it's obsolete.

Ah.

Quoted 2 lines

Should I delete this statement in the first paragraph only?

Remove ", and of same order"

Signature · 2 lines
Mel Gorman
SUSE Labs
author
#19 lore raw

Re: [PATCH 3/6] mm/page_alloc.c: remove obsolete comment in free_pcppages_bulk()

Quoted 18 lines · Mel Gorman
Quoted 7 lines · Miaohe Lin
Quoted 6 lines · Mel Gorman
Quoted 2 lines · Miaohe Lin

It's also confusing now. Remove it.

Why is the whole comment obsolete?

Quoted 9 lines
Quoted 3 lines

The second two paragraphs about "all pages pinned" and pages_scanned is obsolete and can go but the first paragraph is valid.

I think the first paragraph is invalid due to the below statement:
"Assumes all pages on list are in same zone, and of same order." There are NR_PCP_LISTS lists and PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP orders in pcp. So I think it's obsolete.

Quoted 6 lines

Ah.

Quoted 2 lines

Should I delete this statement in the first paragraph only?

Remove ", and of same order"

Will do this in v2. Thanks.

Quoted 1 line
author
#20 lore raw

PATCH 4/6 mm/page_alloc.c: use helper function zone_spans_pfn()

In reply to Miaohe Lin

Use helper function zone_spans_pfn() to check whether pfn is within a zone to simplify the code slightly.

---
 mm/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
index b5edcfe112aa..7bb79e959ab4 100644
@@ -1576,7 +1576,7 @@ static void __meminit init_reserved_page(unsigned long pfn)
 	for (zid = 0; zid < MAX_NR_ZONES; zid++) {
 		struct zone *zone = &pgdat->node_zones[zid];
 
-		if (pfn >= zone->zone_start_pfn && pfn < zone_end_pfn(zone))
+		if (zone_spans_pfn(zone, pfn))
 			break;
 	}
 	__init_single_page(pfn_to_page(pfn), pfn, zid, nid);
Signature · 1 line
2.23.0
Reviewed-by on v1 4/6
#22 lore raw

Re: [PATCH 4/6] mm/page_alloc.c: use helper function zone_spans_pfn()

In reply to Miaohe Lin
Quoted 14 lines · Miaohe Lin

Use helper function zone_spans_pfn() to check whether pfn is within a zone to simplify the code slightly.

---
  mm/page_alloc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +0 -0
index b5edcfe112aa..7bb79e959ab4 100644

mm/page_alloc.c static void __meminit init_reserved_page(unsigned long pfn) · line 1582

Quoted 8 lines
mm/page_alloc.c +1 -1
@@ -1576,7 +1576,7 @@ static void __meminit init_reserved_page(unsigned long pfn)
  	for (zid = 0; zid < MAX_NR_ZONES; zid++) {
  		struct zone *zone = &pgdat->node_zones[zid];
 
-		if (pfn >= zone->zone_start_pfn && pfn < zone_end_pfn(zone))
+		if (zone_spans_pfn(zone, pfn))
  			break;
  	}
  	__init_single_page(pfn_to_page(pfn), pfn, zid, nid);
Signature · 3 lines
Thanks,

David / dhildenb
author
#23 lore raw

PATCH 5/6 mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

In reply to Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")
---
 mm/page_alloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/page_alloc.c +3 -1
index 7bb79e959ab4..d87b7e6e9e6b 100644
@@ -3415,8 +3415,10 @@ void free_unref_page_list(struct list_head *list)
 	/* Prepare pages for freeing */
 	list_for_each_entry_safe(page, next, list, lru) {
 		pfn = page_to_pfn(page);
-		if (!free_unref_page_prepare(page, pfn, 0))
+		if (!free_unref_page_prepare(page, pfn, 0)) {
 			list_del(&page->lru);
+			continue;
+		}
 
 		/*
 		 * Free isolated pages directly to the allocator, see
Signature · 1 line
2.23.0
Acked-by on v1 5/6
#24 lore raw

Re: [PATCH 5/6] mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

Quoted 7 lines · Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

This fix is fairly important. Take this patch out and send it on its own so it gets picked up relatively quickly. It does not belong in a series that is mostly cosmetic cleanups.

Signature · 2 lines
Mel Gorman
SUSE Labs
#25 lore raw

Re: [PATCH 5/6] mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

Quoted 6 lines · Mel Gorman
Quoted 5 lines · Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Quoted 8 lines
Quoted 2 lines
Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

This fix is fairly important. Take this patch out and send it on its own so it gets picked up relatively quickly. It does not belong in a series that is mostly cosmetic cleanups.

I think the commit id is wrong. Shouldn't that be

df1acc856923 ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

?

Signature · 3 lines
Thanks,

David / dhildenb
author
#26 lore raw

Re: [PATCH 5/6] mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

Quoted 16 lines · David Hildenbrand
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Quoted 8 lines
Quoted 2 lines
Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

This fix is fairly important. Take this patch out and send it on its own so it gets picked up relatively quickly. It does not belong in a series that is mostly cosmetic cleanups.

Quoted 6 lines

I think the commit id is wrong. Shouldn't that be

df1acc856923 ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

?

Many thanks for pointing this out.

I used to save the git log in a file to make life easier. But it seems this leads to the old commit id above.

commit 3dcbe270d8ec57e534f5c605279cdc3ceb1f044a

Author: Mel Gorman <[email protected]>
Date:   Fri Jun 4 14:20:03 2021 +1000
    mm/page_alloc: avoid conflating IRQs disabled with zone->lock

git name-rev 3dcbe270d8ec
3dcbe270d8ec tags/next-20210604~2^2~196

vs

commit df1acc856923c0a65c28b588585449106c316b71

Author: Mel Gorman <[email protected]>
Date:   Mon Jun 28 19:42:00 2021 -0700
    mm/page_alloc: avoid conflating IRQs disabled with zone->lock

git name-rev df1acc856923
df1acc856923 tags/next-20210630~2^2~278

Their contents are same but with different commit id. The previous one could have been git-rebased.

#27 lore raw

Re: [PATCH 5/6] mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

Quoted 44 lines · Miaohe Lin
Quoted 16 lines · David Hildenbrand
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Quoted 8 lines
Quoted 2 lines
Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

This fix is fairly important. Take this patch out and send it on its own so it gets picked up relatively quickly. It does not belong in a series that is mostly cosmetic cleanups.

Quoted 6 lines

I think the commit id is wrong. Shouldn't that be

df1acc856923 ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

?

Many thanks for pointing this out.

I used to save the git log in a file to make life easier. But it seems this leads to the old commit id above.

commit 3dcbe270d8ec57e534f5c605279cdc3ceb1f044a

Author: Mel Gorman <[email protected]>
Date:   Fri Jun 4 14:20:03 2021 +1000
     mm/page_alloc: avoid conflating IRQs disabled with zone->lock

git name-rev 3dcbe270d8ec
3dcbe270d8ec tags/next-20210604~2^2~196

vs

commit df1acc856923c0a65c28b588585449106c316b71

Author: Mel Gorman <[email protected]>
Date:   Mon Jun 28 19:42:00 2021 -0700
Quoted 8 lines
     mm/page_alloc: avoid conflating IRQs disabled with zone->lock

git name-rev df1acc856923
df1acc856923 tags/next-20210630~2^2~278

Their contents are same but with different commit id. The previous one could have been git-rebased.

-mm tree commit ids keep changing until patches are upstream. Therefore, you can observe changing commit ids in -next. Always use the ones from Linus' tree, they are stable.

Signature · 3 lines
Thanks,

David / dhildenb
author
#28 lore raw

Re: [PATCH 5/6] mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

Quoted 47 lines · David Hildenbrand
Quoted 46 lines · Miaohe Lin
Quoted 16 lines · David Hildenbrand
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Quoted 8 lines
Quoted 2 lines
Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

This fix is fairly important. Take this patch out and send it on its own so it gets picked up relatively quickly. It does not belong in a series that is mostly cosmetic cleanups.

Quoted 6 lines

I think the commit id is wrong. Shouldn't that be

df1acc856923 ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

?

Many thanks for pointing this out.

I used to save the git log in a file to make life easier. But it seems this leads to the old commit id above.

commit 3dcbe270d8ec57e534f5c605279cdc3ceb1f044a
Author: Mel Gorman <[email protected]>
Date:   Fri Jun 4 14:20:03 2021 +1000

     mm/page_alloc: avoid conflating IRQs disabled with zone->lock

git name-rev 3dcbe270d8ec
3dcbe270d8ec tags/next-20210604~2^2~196

vs

commit df1acc856923c0a65c28b588585449106c316b71
Author: Mel Gorman <[email protected]>
Date:   Mon Jun 28 19:42:00 2021 -0700

     mm/page_alloc: avoid conflating IRQs disabled with zone->lock

Quoted 9 lines
Quoted 6 lines

git name-rev df1acc856923
df1acc856923 tags/next-20210630~2^2~278

Their contents are same but with different commit id. The previous one could have been git-rebased.

-mm tree commit ids keep changing until patches are upstream. Therefore, you can observe changing commit ids in -next. Always use the ones from Linus' tree, they are stable.

Many thanks for your advice, David. :)

#29 lore raw

Re: [PATCH 5/6] mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

In reply to Mel Gorman
Quoted 6 lines · Mel Gorman
Quoted 5 lines · Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Quoted 8 lines
Quoted 2 lines
Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")

This fix is fairly important. Take this patch out and send it on its own so it gets picked up relatively quickly. It does not belong in a series that is mostly cosmetic cleanups.

Also Cc: stable, please.

author
#30 lore raw

Re: [PATCH 5/6] mm/page_alloc.c: avoid accessing uninitialized pcp page migratetype

Quoted 10 lines · Vlastimil Babka
Quoted 9 lines · Mel Gorman
Quoted 7 lines · Miaohe Lin

If it's not prepared to free unref page, the pcp page migratetype is unset. Thus We will get rubbish from get_pcppage_migratetype() and might list_del &page->lru again after it's already deleted from the list leading to grumble about data corruption.

Fixes 3dcbe270d8ec ("mm/page_alloc: avoid conflating IRQs disabled with zone->lock")
Quoted 9 lines
Quoted 5 lines

This fix is fairly important. Take this patch out and send it on its own so it gets picked up relatively quickly. It does not belong in a series that is mostly cosmetic cleanups.

Also Cc: stable, please.

Will do. Many thanks for both of your suggestions!

Quoted 3 lines

.

author
#31 lore raw

PATCH 6/6 mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact_nid()

In reply to Miaohe Lin

Don't use with __GFP_HIGHMEM because page_address() cannot represent highmem pages without kmap(). Newly allocated pages would leak as page_address() will return NULL for highmem pages here. But It works now because the only caller does not specify __GFP_HIGHMEM now.

---
 mm/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
index d87b7e6e9e6b..858fd45ecaea 100644
@@ -5639,7 +5639,7 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask)
 	if (WARN_ON_ONCE(gfp_mask & __GFP_COMP))
 		gfp_mask &= ~__GFP_COMP;
 
-	p = alloc_pages_node(nid, gfp_mask, order);
+	p = alloc_pages_node(nid, gfp_mask & ~__GFP_HIGHMEM, order);
 	if (!p)
 		return NULL;
 	return make_alloc_exact((unsigned long)page_address(p), order, size);
Signature · 1 line
2.23.0
#32 lore raw

Re: [PATCH 6/6] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact_nid()

Quoted 4 lines · Miaohe Lin

Don't use with __GFP_HIGHMEM because page_address() cannot represent highmem pages without kmap(). Newly allocated pages would leak as page_address() will return NULL for highmem pages here. But It works now because the only caller does not specify __GFP_HIGHMEM now.

This is a misunderstanding of how alloc_pages_exact() / alloc_pages_exact_nid() work. You simply can't call them with GFP_HIGHMEM.

If you really must change anything here, s/__GFP_COMP/(__GFP_COMP|__GFP_HIGHMEM)/g throughout both alloc_pages_exact() and alloc_pages_exact_nid().

author
#33 lore raw

Re: [PATCH 6/6] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact_nid()

Quoted 10 lines · Matthew Wilcox
Quoted 4 lines · Miaohe Lin

Don't use with __GFP_HIGHMEM because page_address() cannot represent highmem pages without kmap(). Newly allocated pages would leak as page_address() will return NULL for highmem pages here. But It works now because the only caller does not specify __GFP_HIGHMEM now.

This is a misunderstanding of how alloc_pages_exact() / alloc_pages_exact_nid() work. You simply can't call them with GFP_HIGHMEM.

Yep, they can't work with GFP_HIGHMEM. So IMO it might be better to get rid of GFP_HIGHMEM explicitly or add a comment to clarify this situation to avoid future misbehavior. But this may be a unnecessary worry... Do you prefer to not change anything here?

Many thanks.

Quoted 5 lines

If you really must change anything here, s/__GFP_COMP/(__GFP_COMP|__GFP_HIGHMEM)/g throughout both alloc_pages_exact() and alloc_pages_exact_nid(). .

#34 lore raw

Re: [PATCH 6/6] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact_nid()

Quoted 12 lines · Miaohe Lin
Quoted 10 lines · Matthew Wilcox
Quoted 4 lines · Miaohe Lin

Don't use with __GFP_HIGHMEM because page_address() cannot represent highmem pages without kmap(). Newly allocated pages would leak as page_address() will return NULL for highmem pages here. But It works now because the only caller does not specify __GFP_HIGHMEM now.

This is a misunderstanding of how alloc_pages_exact() / alloc_pages_exact_nid() work. You simply can't call them with GFP_HIGHMEM.

Quoted 4 lines

Yep, they can't work with GFP_HIGHMEM. So IMO it might be better to get rid of GFP_HIGHMEM explicitly or add a comment to clarify this situation to avoid future misbehavior. But this may be a unnecessary worry... Do you prefer to not change anything here?

I agree with the suggestion below...

Quoted 5 lines

Many thanks.

Quoted 3 lines

If you really must change anything here, s/__GFP_COMP/(__GFP_COMP|__GFP_HIGHMEM)/g throughout both alloc_pages_exact() and alloc_pages_exact_nid().

... which means __GFP_HIGHMEM would be stripped and additionally there would be a warning.

author
#35 lore raw

Re: [PATCH 6/6] mm/page_alloc.c: avoid allocating highmem pages via alloc_pages_exact_nid()

Quoted 20 lines · Vlastimil Babka
Quoted 12 lines · Miaohe Lin
Quoted 10 lines · Matthew Wilcox
Quoted 4 lines · Miaohe Lin

Don't use with __GFP_HIGHMEM because page_address() cannot represent highmem pages without kmap(). Newly allocated pages would leak as page_address() will return NULL for highmem pages here. But It works now because the only caller does not specify __GFP_HIGHMEM now.

This is a misunderstanding of how alloc_pages_exact() / alloc_pages_exact_nid() work. You simply can't call them with GFP_HIGHMEM.

Quoted 4 lines

Yep, they can't work with GFP_HIGHMEM. So IMO it might be better to get rid of GFP_HIGHMEM explicitly or add a comment to clarify this situation to avoid future misbehavior. But this may be a unnecessary worry... Do you prefer to not change anything here?

I agree with the suggestion below...

Quoted 9 lines
Quoted 5 lines

Many thanks.

Quoted 3 lines

If you really must change anything here, s/__GFP_COMP/(__GFP_COMP|__GFP_HIGHMEM)/g throughout both alloc_pages_exact() and alloc_pages_exact_nid().

... which means __GFP_HIGHMEM would be stripped and additionally there would be a warning.

Looks good for me. Will do. Many thanks!

Quoted 2 lines

.