Skip to contentSkip to conversation

s390/mm: get total ram pages from memblock

PATCH Applied Wei Yang 3 participants 3 messages Jun 16, 2024 – Jun 19, 2024

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 s390/mm: get total ram pages from memblock

On s390, zero page's size relies on total ram pages.

Since we plan to move the accounting into __free_pages_core(), totalram_pages may not represent the total usable pages on system at this point when defer_init is enabled.

We can get the total usable pages from memblock directly. The size maybe not accurate due to the alignment, but enough for the calculation.

CC Mike Rapoport (IBM) <[email protected]>
CC David Hildenbrand <[email protected]>

---
Not tested on a machine, hope it is fine.

---
 arch/s390/mm/init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/mm/init.c +2 -1
index e769d2726f4e..d811ffa5e147 100644
@@ -65,12 +65,13 @@ static void __init setup_zero_pages(void)
 	unsigned int order;
 	struct page *page;
 	int i;
+	unsigned long total_pages = PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
 
 	/* Latest machines require a mapping granularity of 512KB */
 	order = 7;
 
 	/* Limit number of empty zero pages for small memory sizes */
-	while (order > 2 && (totalram_pages() >> 10) < (1UL << order))
+	while (order > 2 && (total_pages >> 10) < (1UL << order))
 		order--;
 
 	empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Wei Yang

On s390, zero page's size relies on total ram pages.

Since we plan to move the accounting into __free_pages_core(), totalram_pages may not represent the total usable pages on system at this point when defer_init is enabled.

We can get the total usable pages from memblock directly. The size maybe not accurate due to the alignment, but enough for the calculation.

CC Mike Rapoport (IBM) <[email protected]>
CC David Hildenbrand <[email protected]>

---
Not tested on a machine, hope it is fine.

---
  arch/s390/mm/init.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/mm/init.c +1 -0
index e769d2726f4e..d811ffa5e147 100644
@@ -65,12 +65,13 @@ static void __init setup_zero_pages(void)
  	unsigned int order;
  	struct page *page;
  	int i;
+	unsigned long total_pages = PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());

arch/s390/mm/init.c static void __init setup_zero_pages(void) · line 77

Quoted 10 lines
arch/s390/mm/init.c +1 -1
 
  	/* Latest machines require a mapping granularity of 512KB */
  	order = 7;
 
  	/* Limit number of empty zero pages for small memory sizes */
-	while (order > 2 && (totalram_pages() >> 10) < (1UL << order))
+	while (order > 2 && (total_pages >> 10) < (1UL << order))
  		order--;
 
  	empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);

I suspect that this is good enough as an approximation for that purpose.

Signature · 3 lines
Cheers,

David / dhildenb
maintainer Applied
#2 lore raw
Quoted 39 lines · David Hildenbrand
Quoted 25 lines · Wei Yang

On s390, zero page's size relies on total ram pages.

Since we plan to move the accounting into __free_pages_core(), totalram_pages may not represent the total usable pages on system at this point when defer_init is enabled.

We can get the total usable pages from memblock directly. The size maybe not accurate due to the alignment, but enough for the calculation.

CC Mike Rapoport (IBM) <[email protected]>
CC David Hildenbrand <[email protected]>

---
Not tested on a machine, hope it is fine.

---
  arch/s390/mm/init.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/mm/init.c +0 -0
index e769d2726f4e..d811ffa5e147 100644
@@ -65,12 +65,13 @@ static void __init setup_zero_pages(void)
  	unsigned int order;

arch/s390/mm/init.c static void __init setup_zero_pages(void) · line 74

Quoted 10 lines
arch/s390/mm/init.c +2 -1
  	struct page *page;
  	int i;
+	unsigned long total_pages = PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
  	/* Latest machines require a mapping granularity of 512KB */
  	order = 7;
  	/* Limit number of empty zero pages for small memory sizes */
-	while (order > 2 && (totalram_pages() >> 10) < (1UL << order))
+	while (order > 2 && (total_pages >> 10) < (1UL << order))
  		order--;
  	empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);

I suspect that this is good enough as an approximation for that purpose.

Quoted 1 line

Applied, thanks!