Skip to contentSkip to conversation

mm/hugetlb: use helper huge_page_size() to get hugepage size

PATCH Superseded Miaohe Lin 2 participants 5 messages Feb 8, 2021 – Feb 9, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 mm/hugetlb: use helper huge_page_size() to get hugepage size

We can use helper huge_page_size() to get the hugepage size directly to simplify the code slightly.

---
 mm/hugetlb.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/hugetlb.c +6 -8
index 18628f8dbfb0..6cdb59d8f663 100644
@@ -3199,7 +3199,7 @@ void __init hugetlb_add_hstate(unsigned int order)
 	BUG_ON(order == 0);
 	h = &hstates[hugetlb_max_hstate++];
 	h->order = order;
-	h->mask = ~((1ULL << (order + PAGE_SHIFT)) - 1);
+	h->mask = ~(huge_page_size(h) - 1);
 	for (i = 0; i < MAX_NUMNODES; ++i)
 		INIT_LIST_HEAD(&h->hugepage_freelists[i]);
 	INIT_LIST_HEAD(&h->hugepage_activelist);
@@ -3474,7 +3474,7 @@ void hugetlb_report_meminfo(struct seq_file *m)
 	for_each_hstate(h) {
 		unsigned long count = h->nr_huge_pages;
 
-		total += (PAGE_SIZE << huge_page_order(h)) * count;
+		total += huge_page_size(h) * count;
 
 		if (h == &default_hstate)
 			seq_printf(m,
@@ -3487,10 +3487,10 @@ void hugetlb_report_meminfo(struct seq_file *m)
 				   h->free_huge_pages,
 				   h->resv_huge_pages,
 				   h->surplus_huge_pages,
-				   (PAGE_SIZE << huge_page_order(h)) / 1024);
+				   huge_page_size(h) / SZ_1K);
 	}
 
-	seq_printf(m, "Hugetlb:        %8lu kB\n", total / 1024);
+	seq_printf(m, "Hugetlb:        %8lu kB\n", total / SZ_1K);
 }
 
 int hugetlb_report_node_meminfo(char *buf, int len, int nid)
@@ -3524,7 +3524,7 @@ void hugetlb_show_meminfo(void)
 				h->nr_huge_pages_node[nid],
 				h->free_huge_pages_node[nid],
 				h->surplus_huge_pages_node[nid],
-				1UL << (huge_page_order(h) + PAGE_SHIFT - 10));
+				huge_page_size(h) >> 10);
 }
 
 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm)
@@ -3647,9 +3647,7 @@ static int hugetlb_vm_op_split(struct vm_area_struct *vma, unsigned long addr)
 
 static unsigned long hugetlb_vm_op_pagesize(struct vm_area_struct *vma)
 {
-	struct hstate *hstate = hstate_vma(vma);
-
-	return 1UL << huge_page_shift(hstate);
+	return huge_page_size(hstate_vma(vma));
 }
 
 /*
Signature · 1 line
2.19.1
#1 lore raw
Quoted 44 lines · Miaohe Lin

We can use helper huge_page_size() to get the hugepage size directly to simplify the code slightly.

---
 mm/hugetlb.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/hugetlb.c +4 -4
index 18628f8dbfb0..6cdb59d8f663 100644
@@ -3199,7 +3199,7 @@ void __init hugetlb_add_hstate(unsigned int order)
 	BUG_ON(order == 0);
 	h = &hstates[hugetlb_max_hstate++];
 	h->order = order;
-	h->mask = ~((1ULL << (order + PAGE_SHIFT)) - 1);
+	h->mask = ~(huge_page_size(h) - 1);
 	for (i = 0; i < MAX_NUMNODES; ++i)
 		INIT_LIST_HEAD(&h->hugepage_freelists[i]);
 	INIT_LIST_HEAD(&h->hugepage_activelist);
@@ -3474,7 +3474,7 @@ void hugetlb_report_meminfo(struct seq_file *m)
 	for_each_hstate(h) {
 		unsigned long count = h->nr_huge_pages;
 
-		total += (PAGE_SIZE << huge_page_order(h)) * count;
+		total += huge_page_size(h) * count;
 
 		if (h == &default_hstate)
 			seq_printf(m,
@@ -3487,10 +3487,10 @@ void hugetlb_report_meminfo(struct seq_file *m)
 				   h->free_huge_pages,
 				   h->resv_huge_pages,
 				   h->surplus_huge_pages,
-				   (PAGE_SIZE << huge_page_order(h)) / 1024);
+				   huge_page_size(h) / SZ_1K);
 	}
 
-	seq_printf(m, "Hugetlb:        %8lu kB\n", total / 1024);
+	seq_printf(m, "Hugetlb:        %8lu kB\n", total / SZ_1K);
 }
 
 int hugetlb_report_node_meminfo(char *buf, int len, int nid)

mm/hugetlb.c void hugetlb_show_meminfo(void) · line 3527

Quoted 5 lines
mm/hugetlb.c +1 -1
@@ -3524,7 +3524,7 @@ void hugetlb_show_meminfo(void)
 				h->nr_huge_pages_node[nid],
 				h->free_huge_pages_node[nid],
 				h->surplus_huge_pages_node[nid],
-				1UL << (huge_page_order(h) + PAGE_SHIFT - 10));
+				huge_page_size(h) >> 10);

Should we change this to

				huge_page_size(h) / SZ_1K);

as in hugetlb_report_meminfo above? Or, is that one where it takes an additional instruction to do the divide as opposed to the shift? I would rather add the instruction and keep everything consistent.

Signature · 1 line
Mike Kravetz
Quoted 15 lines
mm/hugetlb.c +1 -3
 }
 
 void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm)
@@ -3647,9 +3647,7 @@ static int hugetlb_vm_op_split(struct vm_area_struct *vma, unsigned long addr)
 
 static unsigned long hugetlb_vm_op_pagesize(struct vm_area_struct *vma)
 {
-	struct hstate *hstate = hstate_vma(vma);
-
-	return 1UL << huge_page_shift(hstate);
+	return huge_page_size(hstate_vma(vma));
 }
 
 /*
author
#2 lore raw

Hi:

Quoted 53 lines · Mike Kravetz
Quoted 44 lines · Miaohe Lin

We can use helper huge_page_size() to get the hugepage size directly to simplify the code slightly.

---
 mm/hugetlb.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/hugetlb.c +4 -4
index 18628f8dbfb0..6cdb59d8f663 100644
@@ -3199,7 +3199,7 @@ void __init hugetlb_add_hstate(unsigned int order)
 	BUG_ON(order == 0);
 	h = &hstates[hugetlb_max_hstate++];
 	h->order = order;
-	h->mask = ~((1ULL << (order + PAGE_SHIFT)) - 1);
+	h->mask = ~(huge_page_size(h) - 1);
 	for (i = 0; i < MAX_NUMNODES; ++i)
 		INIT_LIST_HEAD(&h->hugepage_freelists[i]);
 	INIT_LIST_HEAD(&h->hugepage_activelist);
@@ -3474,7 +3474,7 @@ void hugetlb_report_meminfo(struct seq_file *m)
 	for_each_hstate(h) {
 		unsigned long count = h->nr_huge_pages;
 
-		total += (PAGE_SIZE << huge_page_order(h)) * count;
+		total += huge_page_size(h) * count;
 
 		if (h == &default_hstate)
 			seq_printf(m,
@@ -3487,10 +3487,10 @@ void hugetlb_report_meminfo(struct seq_file *m)
 				   h->free_huge_pages,
 				   h->resv_huge_pages,
 				   h->surplus_huge_pages,
-				   (PAGE_SIZE << huge_page_order(h)) / 1024);
+				   huge_page_size(h) / SZ_1K);
 	}
 
-	seq_printf(m, "Hugetlb:        %8lu kB\n", total / 1024);
+	seq_printf(m, "Hugetlb:        %8lu kB\n", total / SZ_1K);
 }
 
 int hugetlb_report_node_meminfo(char *buf, int len, int nid)

mm/hugetlb.c void hugetlb_show_meminfo(void) · line 3527

Quoted 5 lines
mm/hugetlb.c +1 -1
@@ -3524,7 +3524,7 @@ void hugetlb_show_meminfo(void)
 				h->nr_huge_pages_node[nid],
 				h->free_huge_pages_node[nid],
 				h->surplus_huge_pages_node[nid],
-				1UL << (huge_page_order(h) + PAGE_SHIFT - 10));
+				huge_page_size(h) >> 10);

Should we change this to

Quoted 4 lines
				huge_page_size(h) / SZ_1K);
Quoted 1 line

as in hugetlb_report_meminfo above? Or, is that one where it takes an

additional instruction to do the divide as opposed to the shift? I would> rather add the instruction and keep everything consistent.

Yes, it takes an additional instruction to do the divide as opposed to the shift. So I did not change this. But it seems keeping everything consistent in a function is more important. So should I send a V2 to change this or Andrew would kindly handle this ?

Many thanks.

Reviewed-by
#3 lore raw
Quoted 55 lines · Miaohe Lin

Hi:

Quoted 53 lines · Mike Kravetz
Quoted 44 lines · Miaohe Lin

We can use helper huge_page_size() to get the hugepage size directly to simplify the code slightly.

---
 mm/hugetlb.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/hugetlb.c +4 -4
index 18628f8dbfb0..6cdb59d8f663 100644
@@ -3199,7 +3199,7 @@ void __init hugetlb_add_hstate(unsigned int order)
 	BUG_ON(order == 0);
 	h = &hstates[hugetlb_max_hstate++];
 	h->order = order;
-	h->mask = ~((1ULL << (order + PAGE_SHIFT)) - 1);
+	h->mask = ~(huge_page_size(h) - 1);
 	for (i = 0; i < MAX_NUMNODES; ++i)
 		INIT_LIST_HEAD(&h->hugepage_freelists[i]);
 	INIT_LIST_HEAD(&h->hugepage_activelist);
@@ -3474,7 +3474,7 @@ void hugetlb_report_meminfo(struct seq_file *m)
 	for_each_hstate(h) {
 		unsigned long count = h->nr_huge_pages;
 
-		total += (PAGE_SIZE << huge_page_order(h)) * count;
+		total += huge_page_size(h) * count;
 
 		if (h == &default_hstate)
 			seq_printf(m,
@@ -3487,10 +3487,10 @@ void hugetlb_report_meminfo(struct seq_file *m)
 				   h->free_huge_pages,
 				   h->resv_huge_pages,
 				   h->surplus_huge_pages,
-				   (PAGE_SIZE << huge_page_order(h)) / 1024);
+				   huge_page_size(h) / SZ_1K);
 	}
 
-	seq_printf(m, "Hugetlb:        %8lu kB\n", total / 1024);
+	seq_printf(m, "Hugetlb:        %8lu kB\n", total / SZ_1K);
 }
 
 int hugetlb_report_node_meminfo(char *buf, int len, int nid)

mm/hugetlb.c void hugetlb_show_meminfo(void) · line 3527

Quoted 5 lines
mm/hugetlb.c +1 -1
@@ -3524,7 +3524,7 @@ void hugetlb_show_meminfo(void)
 				h->nr_huge_pages_node[nid],
 				h->free_huge_pages_node[nid],
 				h->surplus_huge_pages_node[nid],
-				1UL << (huge_page_order(h) + PAGE_SHIFT - 10));
+				huge_page_size(h) >> 10);

Should we change this to

Quoted 8 lines
Quoted 4 lines
				huge_page_size(h) / SZ_1K);
Quoted 1 line

as in hugetlb_report_meminfo above? Or, is that one where it takes an

additional instruction to do the divide as opposed to the shift? I would> rather add the instruction and keep everything consistent.

Yes, it takes an additional instruction to do the divide as opposed to the shift. So I did not change this. But it seems keeping everything consistent in a function is more important. So should I send a V2 to change this or Andrew would kindly handle this ?

I would go ahead and put together a v2 and let Andrew decide how he wants to handle it. You can include,

Thanks

Signature · 1 line
Mike Kravetz
author
#4 lore raw
Quoted 61 lines · Mike Kravetz
Quoted 60 lines · Miaohe Lin

Hi:

Quoted 57 lines · Mike Kravetz
Quoted 44 lines · Miaohe Lin

We can use helper huge_page_size() to get the hugepage size directly to simplify the code slightly.

---
 mm/hugetlb.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
mm/hugetlb.c +4 -4
index 18628f8dbfb0..6cdb59d8f663 100644
@@ -3199,7 +3199,7 @@ void __init hugetlb_add_hstate(unsigned int order)
 	BUG_ON(order == 0);
 	h = &hstates[hugetlb_max_hstate++];
 	h->order = order;
-	h->mask = ~((1ULL << (order + PAGE_SHIFT)) - 1);
+	h->mask = ~(huge_page_size(h) - 1);
 	for (i = 0; i < MAX_NUMNODES; ++i)
 		INIT_LIST_HEAD(&h->hugepage_freelists[i]);
 	INIT_LIST_HEAD(&h->hugepage_activelist);
@@ -3474,7 +3474,7 @@ void hugetlb_report_meminfo(struct seq_file *m)
 	for_each_hstate(h) {
 		unsigned long count = h->nr_huge_pages;
 
-		total += (PAGE_SIZE << huge_page_order(h)) * count;
+		total += huge_page_size(h) * count;
 
 		if (h == &default_hstate)
 			seq_printf(m,
@@ -3487,10 +3487,10 @@ void hugetlb_report_meminfo(struct seq_file *m)
 				   h->free_huge_pages,
 				   h->resv_huge_pages,
 				   h->surplus_huge_pages,
-				   (PAGE_SIZE << huge_page_order(h)) / 1024);
+				   huge_page_size(h) / SZ_1K);
 	}
 
-	seq_printf(m, "Hugetlb:        %8lu kB\n", total / 1024);
+	seq_printf(m, "Hugetlb:        %8lu kB\n", total / SZ_1K);
 }
 
 int hugetlb_report_node_meminfo(char *buf, int len, int nid)

mm/hugetlb.c void hugetlb_show_meminfo(void) · line 3527

Quoted 5 lines
mm/hugetlb.c +1 -1
@@ -3524,7 +3524,7 @@ void hugetlb_show_meminfo(void)
 				h->nr_huge_pages_node[nid],
 				h->free_huge_pages_node[nid],
 				h->surplus_huge_pages_node[nid],
-				1UL << (huge_page_order(h) + PAGE_SHIFT - 10));
+				huge_page_size(h) >> 10);

Should we change this to

				huge_page_size(h) / SZ_1K);
Quoted 1 line

as in hugetlb_report_meminfo above? Or, is that one where it takes an

additional instruction to do the divide as opposed to the shift? I would> rather add the instruction and keep everything consistent.

Quoted 7 lines
Quoted 3 lines

Yes, it takes an additional instruction to do the divide as opposed to the shift. So I did not change this. But it seems keeping everything consistent in a function is more important. So should I send a V2 to change this or Andrew would kindly handle this ?

I would go ahead and put together a v2 and let Andrew decide how he wants to handle it. You can include,

Will do. Thanks a lot.

Quoted 4 lines

Thanks