[PATCH 4/6] x86, mm: make split_mem_range() more easy to read

Wei Yang
2019-02-12T02:13:36Z

As the comment explains, there are at most 5 possible ranges:

kkkmmmGGGmmmkkk
(A)(B)(C)(D)(E)

While there are two ways to perceive:

* C & D are extra ranges on X86_64
* B & C are extra ranges on X86_64

Current implementation takes the first way, which leads to handling
end_pfn of B differently:

* align to PMD on X86_32
* align to PUD on X86_64

If we take the second way, we don't need to handle it differently.

* the end_pfn of B only need to align to PUD
* the end_pfn of D only need to align to PMD

This patch changes the implementation from the first perception to the
second to reduce one different handling on end_pfn. After doing so, the
code is easier to read.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
arch/x86/mm/init.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 2b782dcd6d71..87275238dbb0 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -389,25 +389,21 @@ static int __meminit split_mem_range(struct map_range *mr,
pfn = end_pfn;
}

+#ifdef CONFIG_X86_64
/*
* Range (B):
* big page (2M) range
*/
start_pfn = round_up(pfn, PFN_DOWN(PMD_SIZE));
-#ifdef CONFIG_X86_32
- end_pfn = round_down(limit_pfn, PFN_DOWN(PMD_SIZE));
-#else /* CONFIG_X86_64 */
end_pfn = round_up(pfn, PFN_DOWN(PUD_SIZE));
if (end_pfn > round_down(limit_pfn, PFN_DOWN(PMD_SIZE)))
end_pfn = round_down(limit_pfn, PFN_DOWN(PMD_SIZE));
-#endif
if (start_pfn < end_pfn) {
nr_range = save_mr(mr, nr_range, start_pfn, end_pfn,
page_size_mask & (1<<PG_LEVEL_2M));
pfn = end_pfn;
}

-#ifdef CONFIG_X86_64
/*
* Range (C):
* big page (1G) range
@@ -420,6 +416,7 @@ static int __meminit split_mem_range(struct map_range *mr,
((1<<PG_LEVEL_2M)|(1<<PG_LEVEL_1G)));
pfn = end_pfn;
}
+#endif

/*
* Range (D):
@@ -432,7 +429,6 @@ static int __meminit split_mem_range(struct map_range *mr,
page_size_mask & (1<<PG_LEVEL_2M));
pfn = end_pfn;
}
-#endif

/*
* Range (E):
--
2.19.1