Skip to contentSkip to conversation

fs: hugetlb: simplify remove_inode_hugepages() return type

PATCH Superseded Jiaqi Yan 4 participants 5 messages Feb 2 – Feb 4

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiaqi Yan

author
#0 lore raw

PATCH 1/1 fs: hugetlb: simplify remove_inode_hugepages() return type

When remove_inode_hugepages is introduced in
commit c86272287bc6 ("hugetlb: create remove_inode_single_folio to remove single file folio") it used to return a boolean to indicate if it bailed out due to race with
page faults. However, since the race is already solved by [1], remove_inode_hugepages() doesn't have any path to return false anymore.

Simplify remove_inode_hugepages() return type to void, remove the unnecessary ret variable, and adjust the call site in remove_inode_hugepages(). No functional change in this commit.

[1] https://lore.kernel.org/all/[email protected]

---
 fs/hugetlbfs/inode.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
fs/hugetlbfs/inode.c +7 -11
index 3b4c152c5c73a..83d71cea7e384 100644
@@ -515,13 +515,11 @@ hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end,
  * Called with hugetlb fault mutex held.
  * Returns true if page was actually removed, false otherwise.
  */
-static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
-					struct address_space *mapping,
-					struct folio *folio, pgoff_t index,
-					bool truncate_op)
+static void remove_inode_single_folio(struct hstate *h, struct inode *inode,
+				      struct address_space *mapping,
+				      struct folio *folio, pgoff_t index,
+				      bool truncate_op)
 {
-	bool ret = false;
-
 	/*
 	 * If folio is mapped, it was faulted in after being
 	 * unmapped in caller or hugetlb_vmdelete_list() skips
@@ -543,7 +541,6 @@ static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
 	 */
 	VM_BUG_ON_FOLIO(folio_test_hugetlb_restore_reserve(folio), folio);
 	hugetlb_delete_from_page_cache(folio);
-	ret = true;
 	if (!truncate_op) {
 		if (unlikely(hugetlb_unreserve_pages(inode, index,
 							index + 1, 1)))
@@ -551,7 +548,6 @@ static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
 	}
 
 	folio_unlock(folio);
-	return ret;
 }
 
 /*
@@ -599,9 +595,9 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
 			/*
 			 * Remove folio that was part of folio_batch.
 			 */
-			if (remove_inode_single_folio(h, inode, mapping, folio,
-							index, truncate_op))
-				freed++;
+			remove_inode_single_folio(h, inode, mapping, folio,
+						  index, truncate_op);
+			freed++;
 
 			mutex_unlock(&hugetlb_fault_mutex_table[hash]);
 		}
Signature · 1 line
2.53.0.rc1.225.gd81095ad13-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 59 lines · Jiaqi Yan

When remove_inode_hugepages is introduced in
commit c86272287bc6 ("hugetlb: create remove_inode_single_folio to remove single file folio") it used to return a boolean to indicate if it bailed out due to race with
page faults. However, since the race is already solved by [1], remove_inode_hugepages() doesn't have any path to return false anymore.

Simplify remove_inode_hugepages() return type to void, remove the unnecessary ret variable, and adjust the call site in remove_inode_hugepages(). No functional change in this commit.

[1] https://lore.kernel.org/all/[email protected]

---
  fs/hugetlbfs/inode.c | 18 +++++++-----------
  1 file changed, 7 insertions(+), 11 deletions(-)
fs/hugetlbfs/inode.c +4 -8
index 3b4c152c5c73a..83d71cea7e384 100644
@@ -515,13 +515,11 @@ hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end,
   * Called with hugetlb fault mutex held.
   * Returns true if page was actually removed, false otherwise.
   */
-static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
-					struct address_space *mapping,
-					struct folio *folio, pgoff_t index,
-					bool truncate_op)
+static void remove_inode_single_folio(struct hstate *h, struct inode *inode,
+				      struct address_space *mapping,
+				      struct folio *folio, pgoff_t index,
+				      bool truncate_op)
  {
-	bool ret = false;
-
  	/*
  	 * If folio is mapped, it was faulted in after being
  	 * unmapped in caller or hugetlb_vmdelete_list() skips
@@ -543,7 +541,6 @@ static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
  	 */
  	VM_BUG_ON_FOLIO(folio_test_hugetlb_restore_reserve(folio), folio);
  	hugetlb_delete_from_page_cache(folio);
-	ret = true;
  	if (!truncate_op) {
  		if (unlikely(hugetlb_unreserve_pages(inode, index,
  							index + 1, 1)))
@@ -551,7 +548,6 @@ static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
  	}
 
  	folio_unlock(folio);
-	return ret;
  }
 
  /*
@@ -599,9 +595,9 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
  			/*
  			 * Remove folio that was part of folio_batch.

fs/hugetlbfs/inode.c static void remove_inode_hugepages(struct inode *inode, loff_t lstart, · line 603

Quoted 10 lines
fs/hugetlbfs/inode.c +3 -3
  			 */
-			if (remove_inode_single_folio(h, inode, mapping, folio,
-							index, truncate_op))
-				freed++;
+			remove_inode_single_folio(h, inode, mapping, folio,
+						  index, truncate_op);
+			freed++;
 
  			mutex_unlock(&hugetlb_fault_mutex_table[hash]);
  		}

Looks good, thanks for the clean up.

-jane

maintainer Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH v1] hugetlb: simplify remove_inode_hugepages() return type

In reply to Jiaqi Yan
Quoted 10 lines · Jiaqi Yan

When remove_inode_hugepages is introduced in
commit c86272287bc6 ("hugetlb: create remove_inode_single_folio to remove single file folio") it used to return a boolean to indicate if it bailed out due to race with
page faults. However, since the race is already solved by [1], remove_inode_hugepages() doesn't have any path to return false anymore.

Quoted 8 lines

Simplify remove_inode_hugepages() return type to void, remove the unnecessary ret variable, and adjust the call site in remove_inode_hugepages(). No functional change in this commit.

[1] https://lore.kernel.org/all/[email protected]

reviewer Acked-by on v1 1/1
#3 lore raw
In reply to Jiaqi Yan
Quoted 24 lines · Jiaqi Yan

When remove_inode_hugepages is introduced in
commit c86272287bc6 ("hugetlb: create remove_inode_single_folio to remove single file folio") it used to return a boolean to indicate if it bailed out due to race with
page faults. However, since the race is already solved by [1], remove_inode_hugepages() doesn't have any path to return false anymore.

Simplify remove_inode_hugepages() return type to void, remove the unnecessary ret variable, and adjust the call site in remove_inode_hugepages(). No functional change in this commit.

[1] https://lore.kernel.org/all/[email protected]

---
  fs/hugetlbfs/inode.c | 18 +++++++-----------
  1 file changed, 7 insertions(+), 11 deletions(-)
fs/hugetlbfs/inode.c +0 -0
index 3b4c152c5c73a..83d71cea7e384 100644
@@ -515,13 +515,11 @@ hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end,
   * Called with hugetlb fault mutex held.

fs/hugetlbfs/inode.c hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end, · line 521

Quoted 10 lines
fs/hugetlbfs/inode.c +4 -4
   * Returns true if page was actually removed, false otherwise.
   */
-static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
-					struct address_space *mapping,
-					struct folio *folio, pgoff_t index,
-					bool truncate_op)
+static void remove_inode_single_folio(struct hstate *h, struct inode *inode,
+				      struct address_space *mapping,
+				      struct folio *folio, pgoff_t index,
+				      bool truncate_op)

While you are touching this, this would look better with two-tab alignment on second parameter line.

Signature · 3 lines
Cheers,

David
author
#4 lore raw

Thanks for your reviews, Jane, Muchun, and David

Quoted 31 lines · David Hildenbrand (arm)
Quoted 29 lines · Jiaqi Yan

When remove_inode_hugepages is introduced in
commit c86272287bc6 ("hugetlb: create remove_inode_single_folio to remove single file folio") it used to return a boolean to indicate if it bailed out due to race with
page faults. However, since the race is already solved by [1], remove_inode_hugepages() doesn't have any path to return false anymore.

Simplify remove_inode_hugepages() return type to void, remove the unnecessary ret variable, and adjust the call site in remove_inode_hugepages(). No functional change in this commit.

[1] https://lore.kernel.org/all/[email protected]

---
  fs/hugetlbfs/inode.c | 18 +++++++-----------
  1 file changed, 7 insertions(+), 11 deletions(-)
fs/hugetlbfs/inode.c +0 -3
index 3b4c152c5c73a..83d71cea7e384 100644
@@ -515,13 +515,11 @@ hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end,
   * Called with hugetlb fault mutex held.
   * Returns true if page was actually removed, false otherwise.
   */
-static bool remove_inode_single_folio(struct hstate *h, struct inode *inode,
-                                     struct address_space *mapping,
-                                     struct folio *folio, pgoff_t index,
Quoted 8 lines

fs/hugetlbfs/inode.c hugetlb_vmdelete_list(struct rb_root_cached *root, pgoff_t start, pgoff_t end, · line 521

Quoted 5 lines
fs/hugetlbfs/inode.c +4 -1
-                                     bool truncate_op)
+static void remove_inode_single_folio(struct hstate *h, struct inode *inode,
+                                   struct address_space *mapping,
+                                   struct folio *folio, pgoff_t index,
+                                   bool truncate_op)

While you are touching this, this would look better with two-tab alignment on second parameter line.

For sure, it is adjusted in v2:
https://lore.kernel.org/linux-mm/[email protected]

Quoted 7 lines

--
Cheers,

David