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

Jiaqi Yan posted 1 patch 4 days, 14 hours ago
There is a newer version of this series
fs/hugetlbfs/inode.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
[PATCH v1] fs: hugetlb: simplify remove_inode_hugepages() return type
Posted by Jiaqi Yan 4 days, 14 hours ago
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/20220914221810.95771-10-mike.kravetz@oracle.com

Suggested-by: Jane Chu <jane.chu@oracle.com>
Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
---
 fs/hugetlbfs/inode.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 3b4c152c5c73a..83d71cea7e384 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -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]);
 		}
-- 
2.53.0.rc1.225.gd81095ad13-goog
Re: [PATCH v1] fs: hugetlb: simplify remove_inode_hugepages() return type
Posted by David Hildenbrand (arm) 3 days, 2 hours ago
On 2/3/26 00:36, Jiaqi Yan wrote:
> 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/20220914221810.95771-10-mike.kravetz@oracle.com
> 
> Suggested-by: Jane Chu <jane.chu@oracle.com>
> Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
> ---
>   fs/hugetlbfs/inode.c | 18 +++++++-----------
>   1 file changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 3b4c152c5c73a..83d71cea7e384 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -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)

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

Acked-by: David Hildenbrand (arm) <david@kernel.org>

-- 
Cheers,

David
Re: [PATCH v1] fs: hugetlb: simplify remove_inode_hugepages() return type
Posted by Jiaqi Yan 2 days, 16 hours ago
Thanks for your reviews, Jane, Muchun, and David

On Wed, Feb 4, 2026 at 3:41 AM David Hildenbrand (arm) <david@kernel.org> wrote:
>
> On 2/3/26 00:36, Jiaqi Yan wrote:
> > 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/20220914221810.95771-10-mike.kravetz@oracle.com
> >
> > Suggested-by: Jane Chu <jane.chu@oracle.com>
> > Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
> > ---
> >   fs/hugetlbfs/inode.c | 18 +++++++-----------
> >   1 file changed, 7 insertions(+), 11 deletions(-)
> >
> > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> > index 3b4c152c5c73a..83d71cea7e384 100644
> > --- a/fs/hugetlbfs/inode.c
> > +++ b/fs/hugetlbfs/inode.c
> > @@ -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)
>
> 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/20260204214741.3161520-1-jiaqiyan@google.com

>
> Acked-by: David Hildenbrand (arm) <david@kernel.org>
>
> --
> Cheers,
>
> David
Re: [PATCH v1] hugetlb: simplify remove_inode_hugepages() return type
Posted by Muchun Song 3 days, 7 hours ago

> On Feb 3, 2026, at 07:36, Jiaqi Yan <jiaqiyan@google.com> wrote:
> 
> 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/20220914221810.95771-10-mike.kravetz@oracle.com
> 
> Suggested-by: Jane Chu <jane.chu@oracle.com>
> Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>

Reviewed-by: Muchun Song <muchun.song@linux.dev>
Re: [PATCH v1] fs: hugetlb: simplify remove_inode_hugepages() return type
Posted by jane.chu@oracle.com 3 days, 9 hours ago
On 2/2/2026 3:36 PM, Jiaqi Yan wrote:
> 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/20220914221810.95771-10-mike.kravetz@oracle.com
> 
> Suggested-by: Jane Chu <jane.chu@oracle.com>
> Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
> ---
>   fs/hugetlbfs/inode.c | 18 +++++++-----------
>   1 file changed, 7 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
> index 3b4c152c5c73a..83d71cea7e384 100644
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -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]);
>   		}


Looks good, thanks for the clean up.

Reviewed-by: Jane Chu <jane.chu@oracle.com>

-jane