Skip to contentSkip to conversation

x86/setup: Use a more concise memblock API

PATCH Superseded Yuntao Wang 2 participants 4 messages Nov 14, 2023

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

PATCH 1/1 x86/setup: Use a more concise memblock API

When executing relocate_initrd(), the memblock.current_limit field has already been set to max_pfn_mapped << PAGE_SHIFT, so we can replace memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same functionality but is more concise.

---
 arch/x86/kernel/setup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/setup.c +1 -2
index ec2c21a1844e..422497c17eec 100644
@@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
 
 	/* We need to move the initrd down into directly mapped mem */
-	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
-						      PFN_PHYS(max_pfn_mapped));
+	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
 	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
 		      ramdisk_size);
Signature · 1 line
2.42.1
#1 lore raw
Quoted 4 lines · Yuntao Wang

When executing relocate_initrd(), the memblock.current_limit field has already been set to max_pfn_mapped << PAGE_SHIFT, so we can replace memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same functionality but is more concise.

Fine to me, do we need consider other places in:

numa_alloc_distance()
numa_emulation()

Quoted 23 lines
---
 arch/x86/kernel/setup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/setup.c +1 -2
index ec2c21a1844e..422497c17eec 100644
@@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
 
 	/* We need to move the initrd down into directly mapped mem */
-	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
-						      PFN_PHYS(max_pfn_mapped));
+	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
 	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
 		      ramdisk_size);
Signature · 1 line
2.42.1
#2 lore raw

PATCH v2 1/1 x86/setup: Use a more concise memblock API

When executing relocate_initrd()/numa_emulation()/numa_alloc_distance(), the memblock.current_limit field has already been set to max_pfn_mapped << PAGE_SHIFT, therefore we can replace memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same functionality but is more concise.

---
v1 -> v2:

Also replace memblock_phys_alloc_range() in numa_emulation() and numa_alloc_distance() with memblock_phys_alloc()

 arch/x86/kernel/setup.c      | 3 +--
 arch/x86/mm/numa.c           | 3 +--
 arch/x86/mm/numa_emulation.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/setup.c +1 -2
index ec2c21a1844e..422497c17eec 100644
@@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
 
 	/* We need to move the initrd down into directly mapped mem */
-	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
-						      PFN_PHYS(max_pfn_mapped));
+	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
 	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
 		      ramdisk_size);
arch/x86/mm/numa.c +1 -2
index b29ceb19e46e..29cd8fc8ede1 100644
@@ -378,8 +378,7 @@ static int __init numa_alloc_distance(void)
 	cnt++;
 	size = cnt * cnt * sizeof(numa_distance[0]);
 
-	phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0,
-					 PFN_PHYS(max_pfn_mapped));
+	phys = memblock_phys_alloc(size, PAGE_SIZE);
 	if (!phys) {
 		pr_warn("Warning: can't allocate distance table!\n");
 		/* don't retry until explicitly reset */
arch/x86/mm/numa_emulation.c +1 -2
index 9a9305367fdd..8acb8d0f7d0f 100644
@@ -447,8 +447,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
 	if (numa_dist_cnt) {
 		u64 phys;
 
-		phys = memblock_phys_alloc_range(phys_size, PAGE_SIZE, 0,
-						 PFN_PHYS(max_pfn_mapped));
+		phys = memblock_phys_alloc(phys_size, PAGE_SIZE);
 		if (!phys) {
 			pr_warn("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n");
 			goto no_emu;

--
2.42.1

Reviewed-by on v2 1/1
#3 lore raw
Quoted 6 lines · Yuntao Wang

When executing relocate_initrd()/numa_emulation()/numa_alloc_distance(), the memblock.current_limit field has already been set to max_pfn_mapped << PAGE_SHIFT, therefore we can replace memblock_phys_alloc_range() with memblock_phys_alloc(), which has the same functionality but is more concise.

Quoted 6 lines

---
v1 -> v2:

Also replace memblock_phys_alloc_range() in numa_emulation() and numa_alloc_distance() with memblock_phys_alloc()

LGTM,

Quoted 51 lines
 arch/x86/kernel/setup.c      | 3 +--
 arch/x86/mm/numa.c           | 3 +--
 arch/x86/mm/numa_emulation.c | 3 +--
 3 files changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/setup.c +1 -2
index ec2c21a1844e..422497c17eec 100644
@@ -259,8 +259,7 @@ static void __init relocate_initrd(void)
 	u64 area_size     = PAGE_ALIGN(ramdisk_size);
 
 	/* We need to move the initrd down into directly mapped mem */
-	u64 relocated_ramdisk = memblock_phys_alloc_range(area_size, PAGE_SIZE, 0,
-						      PFN_PHYS(max_pfn_mapped));
+	u64 relocated_ramdisk = memblock_phys_alloc(area_size, PAGE_SIZE);
 	if (!relocated_ramdisk)
 		panic("Cannot find place for new RAMDISK of size %lld\n",
 		      ramdisk_size);
arch/x86/mm/numa.c +1 -2
index b29ceb19e46e..29cd8fc8ede1 100644
@@ -378,8 +378,7 @@ static int __init numa_alloc_distance(void)
 	cnt++;
 	size = cnt * cnt * sizeof(numa_distance[0]);
 
-	phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0,
-					 PFN_PHYS(max_pfn_mapped));
+	phys = memblock_phys_alloc(size, PAGE_SIZE);
 	if (!phys) {
 		pr_warn("Warning: can't allocate distance table!\n");
 		/* don't retry until explicitly reset */
arch/x86/mm/numa_emulation.c +1 -3
index 9a9305367fdd..8acb8d0f7d0f 100644
@@ -447,8 +447,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
 	if (numa_dist_cnt) {
 		u64 phys;
 
-		phys = memblock_phys_alloc_range(phys_size, PAGE_SIZE, 0,
-						 PFN_PHYS(max_pfn_mapped));
+		phys = memblock_phys_alloc(phys_size, PAGE_SIZE);
 		if (!phys) {
 			pr_warn("NUMA: Warning: can't allocate copy of distance table, disabling emulation\n");
 			goto no_emu;
--

2.42.1