Skip to contentSkip to conversation

Some cleanups and improvements for hugetlb

PATCH Applied Baolin Wang 2 participants 9 messages Oct 21, 2021 – Oct 22, 2021

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

cover Some cleanups and improvements for hugetlb

Hi,

This patchset did some cleanups and improvements for the hugetlb and hugetlb_cgroup. Please help to review. Thanks.

Baolin Wang (4):
hugetlb_cgroup: Remove unused hugetlb_cgroup_from_counter macro
hugetlb: Replace the obsolete hugetlb_instantiation_mutex in the
comments
hugetlb: Remove redundant validation in has_same_uncharge_info()
hugetlb: Remove redundant VM_BUG_ON() in add_reservation_in_range()

 mm/hugetlb.c        | 6 ++----
 mm/hugetlb_cgroup.c | 3 ---
 2 files changed, 2 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/4 hugetlb_cgroup: Remove unused hugetlb_cgroup_from_counter macro

Since commit 726b7bbe ("hugetlb_cgroup: fix illegal access to memory"), the hugetlb_cgroup_from_counter() macro is not used any more, remove it.

---
 mm/hugetlb_cgroup.c | 3 ---
 1 file changed, 3 deletions(-)
mm/hugetlb_cgroup.c +0 -3
index 5383023..79d9353 100644
@@ -27,9 +27,6 @@
 #define MEMFILE_IDX(val)	(((val) >> 16) & 0xffff)
 #define MEMFILE_ATTR(val)	((val) & 0xffff)
 
-#define hugetlb_cgroup_from_counter(counter, idx)                   \
-	container_of(counter, struct hugetlb_cgroup, hugepage[idx])
-
 static struct hugetlb_cgroup *root_h_cgroup __read_mostly;
 
 static inline struct page_counter *
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] hugetlb_cgroup: Remove unused hugetlb_cgroup_from_counter macro

Quoted 7 lines · Baolin Wang

Since commit 726b7bbe ("hugetlb_cgroup: fix illegal access to memory"), the hugetlb_cgroup_from_counter() macro is not used any more, remove it.

---
 mm/hugetlb_cgroup.c | 3 ---
 1 file changed, 3 deletions(-)

Thanks!

Signature · 1 line
Mike Kravetz
Quoted 16 lines
mm/hugetlb_cgroup.c +0 -3
index 5383023..79d9353 100644
@@ -27,9 +27,6 @@
 #define MEMFILE_IDX(val)	(((val) >> 16) & 0xffff)
 #define MEMFILE_ATTR(val)	((val) & 0xffff)
 
-#define hugetlb_cgroup_from_counter(counter, idx)                   \
-	container_of(counter, struct hugetlb_cgroup, hugepage[idx])
-
 static struct hugetlb_cgroup *root_h_cgroup __read_mostly;
 
 static inline struct page_counter *
#3 lore raw

PATCH 2/4 hugetlb: Replace the obsolete hugetlb_instantiation_mutex in the comments

In reply to Baolin Wang

After commit 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability"), the hugetlb_instantiation_mutex lock had been replaced by hugetlb_fault_mutex_table to serializes faults on the same logical page. Thus update the obsolete hugetlb_instantiation_mutex related comments.

---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +1 -1
index ee0db48..8902b07 100644
@@ -5012,7 +5012,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
 
 /*
  * Hugetlb_cow() should be called with page lock of the original hugepage held.
- * Called with hugetlb_instantiation_mutex held and pte_page locked so we
+ * Called with hugetlb_fault_mutex_table held and pte_page locked so we
  * cannot race with other handlers or page migration.
  * Keep the pte_same checks anyway to make transition from the mutex easier.
  */
Signature · 1 line
1.8.3.1
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] hugetlb: Replace the obsolete hugetlb_instantiation_mutex in the comments

Quoted 9 lines · Baolin Wang

After commit 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability"), the hugetlb_instantiation_mutex lock had been replaced by hugetlb_fault_mutex_table to serializes faults on the same logical page. Thus update the obsolete hugetlb_instantiation_mutex related comments.

---
 mm/hugetlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!

Signature · 1 line
Mike Kravetz
Quoted 15 lines
mm/hugetlb.c +1 -1
index ee0db48..8902b07 100644
@@ -5012,7 +5012,7 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
 
 /*
  * Hugetlb_cow() should be called with page lock of the original hugepage held.
- * Called with hugetlb_instantiation_mutex held and pte_page locked so we
+ * Called with hugetlb_fault_mutex_table held and pte_page locked so we
  * cannot race with other handlers or page migration.
  * Keep the pte_same checks anyway to make transition from the mutex easier.
  */
#5 lore raw

PATCH 3/4 hugetlb: Remove redundant validation in has_same_uncharge_info()

In reply to Baolin Wang

The callers of has_same_uncharge_info() has accessed the original file_region and new file_region, and they are impossible to be NULL now. So we can remove the file_region validation in has_same_uncharge_info() to simplify the code.

---
 mm/hugetlb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/hugetlb.c +1 -2
index 8902b07..5922629 100644
@@ -333,8 +333,7 @@ static bool has_same_uncharge_info(struct file_region *rg,
 				   struct file_region *org)
 {
 #ifdef CONFIG_CGROUP_HUGETLB
-	return rg && org &&
-	       rg->reservation_counter == org->reservation_counter &&
+	return rg->reservation_counter == org->reservation_counter &&
 	       rg->css == org->css;
 
 #else
Signature · 1 line
1.8.3.1
Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] hugetlb: Remove redundant validation in has_same_uncharge_info()

Quoted 8 lines · Baolin Wang

The callers of has_same_uncharge_info() has accessed the original file_region and new file_region, and they are impossible to be NULL now. So we can remove the file_region validation in has_same_uncharge_info() to simplify the code.

---
 mm/hugetlb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Thanks!

Signature · 1 line
Mike Kravetz
Quoted 16 lines
mm/hugetlb.c +1 -2
index 8902b07..5922629 100644
@@ -333,8 +333,7 @@ static bool has_same_uncharge_info(struct file_region *rg,
 				   struct file_region *org)
 {
 #ifdef CONFIG_CGROUP_HUGETLB
-	return rg && org &&
-	       rg->reservation_counter == org->reservation_counter &&
+	return rg->reservation_counter == org->reservation_counter &&
 	       rg->css == org->css;
 
 #else
#7 lore raw

PATCH 4/4 hugetlb: Remove redundant VM_BUG_ON() in add_reservation_in_range()

In reply to Baolin Wang

When calling hugetlb_resv_map_add(), we've guaranteed that the parameter 'to' is always larger than 'from', so it never returns a negative value from hugetlb_resv_map_add(). Thus remove the redundant VM_BUG_ON().

---
 mm/hugetlb.c | 1 -
 1 file changed, 1 deletion(-)
mm/hugetlb.c +0 -1
index 5922629..166cfa1 100644
@@ -446,7 +446,6 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t,
 		add += hugetlb_resv_map_add(resv, rg, last_accounted_offset,
 					    t, h, h_cg, regions_needed);
 
-	VM_BUG_ON(add < 0);
 	return add;
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] hugetlb: Remove redundant VM_BUG_ON() in add_reservation_in_range()

Quoted 8 lines · Baolin Wang

When calling hugetlb_resv_map_add(), we've guaranteed that the parameter 'to' is always larger than 'from', so it never returns a negative value from hugetlb_resv_map_add(). Thus remove the redundant VM_BUG_ON().

---
 mm/hugetlb.c | 1 -
 1 file changed, 1 deletion(-)

Thanks! You are correct, we could never trigger that VM_BUG_ON.

Signature · 1 line
Mike Kravetz
Quoted 14 lines
mm/hugetlb.c +0 -1
index 5922629..166cfa1 100644
@@ -446,7 +446,6 @@ static long add_reservation_in_range(struct resv_map *resv, long f, long t,
 		add += hugetlb_resv_map_add(resv, rg, last_accounted_offset,
 					    t, h, h_cg, regions_needed);
 
-	VM_BUG_ON(add < 0);
 	return add;
 }