diff mbox series

mm/page_alloc:Check pfn valid once in every page blocks

Message ID 20200627171722.GA16398@roro-Lenovo-Y520-15IKBN (mailing list archive)
State New, archived
Headers show
Series mm/page_alloc:Check pfn valid once in every page blocks | expand

Commit Message

DaeRo Lee June 27, 2020, 5:17 p.m. UTC
Hi, all

Please check the patch below.
Thanks:)


No need to check validity for every pfn in [spfn, epfn).
---
 mm/page_alloc.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Matthew Wilcox June 27, 2020, 5:46 p.m. UTC | #1
On Sun, Jun 28, 2020 at 02:17:22AM +0900, skseofh wrote:
> Hi, all
> 
> Please check the patch below.
> Thanks:)
> 
> 
> No need to check validity for every pfn in [spfn, epfn).
> ---
>  mm/page_alloc.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

OK, so first, this is more code and added complexity.  You haven't justified
the extra code or complexity by giving us performance numbers.

>  {
> -	unsigned long pfn;
> +	unsigned long pfn, block_pfn;
>  	u64 pgcnt = 0;
> +	bool in_block = 0;

If something's a bool, then use 'true' and 'false', not 1 and 0.
diff mbox series

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 174c849ba9f2..212460c9fe0f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6936,11 +6936,19 @@  void __init free_area_init_memoryless_node(int nid)
  */
 static u64 __init init_unavailable_range(unsigned long spfn, unsigned long epfn)
 {
-	unsigned long pfn;
+	unsigned long pfn, block_pfn;
 	u64 pgcnt = 0;
+	bool in_block = 0;
+
+	block_pfn = ALIGN_DOWN(spfn, pageblock_nr_pages);
 
 	for (pfn = spfn; pfn < epfn; pfn++) {
-		if (!pfn_valid(ALIGN_DOWN(pfn, pageblock_nr_pages))) {
+		if (block_pfn != ALIGN_DOWN(pfn, pageblock_nr_pages)) {
+			block_pfn = ALIGN_DOWN(pfn, pageblock_nr_pages);
+			in_block = 0;
+		}
+
+		if (!in_block && !pfn_valid(ALIGN_DOWN(pfn, pageblock_nr_pages))) {
 			pfn = ALIGN_DOWN(pfn, pageblock_nr_pages)
 				+ pageblock_nr_pages - 1;
 			continue;
@@ -6953,6 +6961,7 @@  static u64 __init init_unavailable_range(unsigned long spfn, unsigned long epfn)
 		__init_single_page(pfn_to_page(pfn), pfn, 0, 0);
 		__SetPageReserved(pfn_to_page(pfn));
 		pgcnt++;
+		in_block = 1;
 	}
 
 	return pgcnt;