fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/huge_memory: move writeback and truncation checks early
@ 2024-04-24 22:57 Luis Chamberlain
  2024-04-25  1:07 ` Zi Yan
  2024-04-25  9:40 ` David Hildenbrand
  0 siblings, 2 replies; 4+ messages in thread
From: Luis Chamberlain @ 2024-04-24 22:57 UTC (permalink / raw)
  To: akpm, ziy, linux-mm
  Cc: fstests, linux-xfs, linux-kernel, willy, hare, john.g.garry,
	p.raghav, da.gomez, mcgrof

We should check as early as possible if we should bail due to writeback
or truncation. This will allow us to add further sanity checks earlier
as well.

This introduces no functional changes.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 mm/huge_memory.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

While working on min order support for LBS this came up as an improvement
as we can check for the min order early earlier, so this sets the stage
up for that.

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 86a8c7b3b8dc..32c701821e0d 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
 	if (new_order >= folio_order(folio))
 		return -EINVAL;
 
-	/* Cannot split anonymous THP to order-1 */
-	if (new_order == 1 && folio_test_anon(folio)) {
+	if (folio_test_writeback(folio))
+		return -EBUSY;
+
+	if (!folio_test_anon(folio)) {
+		/* Truncated ? */
+		if (!folio->mapping) {
+			ret = -EBUSY;
+			goto out;
+		}
+	} else if (new_order == 1) {
+		/* Cannot split anonymous THP to order-1 */
 		VM_WARN_ONCE(1, "Cannot split to order-1 folio");
 		return -EINVAL;
 	}
@@ -3079,16 +3088,12 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
 		}
 	}
 
-
 	is_hzp = is_huge_zero_page(&folio->page);
 	if (is_hzp) {
 		pr_warn_ratelimited("Called split_huge_page for huge zero page\n");
 		return -EBUSY;
 	}
 
-	if (folio_test_writeback(folio))
-		return -EBUSY;
-
 	if (folio_test_anon(folio)) {
 		/*
 		 * The caller does not necessarily hold an mmap_lock that would
@@ -3111,12 +3116,6 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
 
 		mapping = folio->mapping;
 
-		/* Truncated ? */
-		if (!mapping) {
-			ret = -EBUSY;
-			goto out;
-		}
-
 		/*
 		 * Do not split if mapping has minimum folio order
 		 * requirement.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/huge_memory: move writeback and truncation checks early
  2024-04-24 22:57 [PATCH] mm/huge_memory: move writeback and truncation checks early Luis Chamberlain
@ 2024-04-25  1:07 ` Zi Yan
  2024-04-25  9:40 ` David Hildenbrand
  1 sibling, 0 replies; 4+ messages in thread
From: Zi Yan @ 2024-04-25  1:07 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: akpm, linux-mm, fstests, linux-xfs, linux-kernel, willy, hare,
	john.g.garry, p.raghav, da.gomez

[-- Attachment #1: Type: text/plain, Size: 2291 bytes --]

On 24 Apr 2024, at 18:57, Luis Chamberlain wrote:

> We should check as early as possible if we should bail due to writeback
> or truncation. This will allow us to add further sanity checks earlier
> as well.
>
> This introduces no functional changes.
>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
>  mm/huge_memory.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
>
> While working on min order support for LBS this came up as an improvement
> as we can check for the min order early earlier, so this sets the stage
> up for that.
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 86a8c7b3b8dc..32c701821e0d 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
>  	if (new_order >= folio_order(folio))
>  		return -EINVAL;
>
> -	/* Cannot split anonymous THP to order-1 */
> -	if (new_order == 1 && folio_test_anon(folio)) {
> +	if (folio_test_writeback(folio))
> +		return -EBUSY;
> +
> +	if (!folio_test_anon(folio)) {
> +		/* Truncated ? */
> +		if (!folio->mapping) {
> +			ret = -EBUSY;
> +			goto out;
> +		}
> +	} else if (new_order == 1) {
> +		/* Cannot split anonymous THP to order-1 */
>  		VM_WARN_ONCE(1, "Cannot split to order-1 folio");
>  		return -EINVAL;
>  	}
> @@ -3079,16 +3088,12 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
>  		}
>  	}
>
> -
>  	is_hzp = is_huge_zero_page(&folio->page);
>  	if (is_hzp) {
>  		pr_warn_ratelimited("Called split_huge_page for huge zero page\n");
>  		return -EBUSY;
>  	}
>
> -	if (folio_test_writeback(folio))
> -		return -EBUSY;
> -
>  	if (folio_test_anon(folio)) {
>  		/*
>  		 * The caller does not necessarily hold an mmap_lock that would
> @@ -3111,12 +3116,6 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
>
>  		mapping = folio->mapping;
>
> -		/* Truncated ? */
> -		if (!mapping) {
> -			ret = -EBUSY;
> -			goto out;
> -		}
> -
>  		/*
>  		 * Do not split if mapping has minimum folio order
>  		 * requirement.
> -- 
> 2.43.0
LGTM. Reviewed-by: Zi Yan <ziy@nvidia.com>

--
Best Regards,
Yan, Zi

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/huge_memory: move writeback and truncation checks early
  2024-04-24 22:57 [PATCH] mm/huge_memory: move writeback and truncation checks early Luis Chamberlain
  2024-04-25  1:07 ` Zi Yan
@ 2024-04-25  9:40 ` David Hildenbrand
  2024-05-01 22:06   ` Luis Chamberlain
  1 sibling, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2024-04-25  9:40 UTC (permalink / raw)
  To: Luis Chamberlain, akpm, ziy, linux-mm
  Cc: fstests, linux-xfs, linux-kernel, willy, hare, john.g.garry,
	p.raghav, da.gomez

On 25.04.24 00:57, Luis Chamberlain wrote:
> We should check as early as possible if we should bail due to writeback
> or truncation. This will allow us to add further sanity checks earlier
> as well.
> 
> This introduces no functional changes.
> 
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
>   mm/huge_memory.c | 23 +++++++++++------------
>   1 file changed, 11 insertions(+), 12 deletions(-)
> 
> While working on min order support for LBS this came up as an improvement
> as we can check for the min order early earlier, so this sets the stage
> up for that.
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 86a8c7b3b8dc..32c701821e0d 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
>   	if (new_order >= folio_order(folio))
>   		return -EINVAL;
>   
> -	/* Cannot split anonymous THP to order-1 */
> -	if (new_order == 1 && folio_test_anon(folio)) {
> +	if (folio_test_writeback(folio))
> +		return -EBUSY;
> +

Why earlier than basic input parameter checks (new_order?

Sorry, but I don't see the reason for that change. It's all happening 
extremely early, what are we concerned about?

It's likely better to send that patch with the actual patch "to add 
further sanity checks earlier as well", and why they have to be that early.

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/huge_memory: move writeback and truncation checks early
  2024-04-25  9:40 ` David Hildenbrand
@ 2024-05-01 22:06   ` Luis Chamberlain
  0 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2024-05-01 22:06 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: akpm, ziy, linux-mm, fstests, linux-xfs, linux-kernel, willy,
	hare, john.g.garry, p.raghav, da.gomez

On Thu, Apr 25, 2024 at 11:40:48AM +0200, David Hildenbrand wrote:
> On 25.04.24 00:57, Luis Chamberlain wrote:
> > We should check as early as possible if we should bail due to writeback
> > or truncation. This will allow us to add further sanity checks earlier
> > as well.
> > 
> > This introduces no functional changes.
> > 
> > Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> > ---
> >   mm/huge_memory.c | 23 +++++++++++------------
> >   1 file changed, 11 insertions(+), 12 deletions(-)
> > 
> > While working on min order support for LBS this came up as an improvement
> > as we can check for the min order early earlier, so this sets the stage
> > up for that.
> > 
> > diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> > index 86a8c7b3b8dc..32c701821e0d 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
> >   	if (new_order >= folio_order(folio))
> >   		return -EINVAL;
> > -	/* Cannot split anonymous THP to order-1 */
> > -	if (new_order == 1 && folio_test_anon(folio)) {
> > +	if (folio_test_writeback(folio))
> > +		return -EBUSY;
> > +
> 
> Why earlier than basic input parameter checks (new_order?
> 
> Sorry, but I don't see the reason for that change. It's all happening
> extremely early, what are we concerned about?
> 
> It's likely better to send that patch with the actual patch "to add further
> sanity checks earlier as well", and why they have to be that early.

It's a clear eye-sore when we add min order, I'll leave the eyesores for
others. It can wait.

  Luis

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-01 22:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24 22:57 [PATCH] mm/huge_memory: move writeback and truncation checks early Luis Chamberlain
2024-04-25  1:07 ` Zi Yan
2024-04-25  9:40 ` David Hildenbrand
2024-05-01 22:06   ` Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).