All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: Zi Yan <ziy@nvidia.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
	akpm@linux-foundation.org, david@kernel.org,
	lorenzo.stoakes@oracle.com, baolin.wang@linux.alibaba.com,
	Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com,
	dev.jain@arm.com, baohua@kernel.org, lance.yang@linux.dev,
	linux-mm@kvack.org
Subject: Re: [Patch v3 2/2] mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported()
Date: Fri, 7 Nov 2025 07:29:44 +0000	[thread overview]
Message-ID: <20251107072944.zvqvr4kyibyofhuw@master> (raw)
In-Reply-To: <9271B00E-FF43-4EA5-B180-7A509E839DEB@nvidia.com>

On Thu, Nov 06, 2025 at 10:21:21PM -0500, Zi Yan wrote:
>On 6 Nov 2025, at 21:49, Wei Yang wrote:
>
>> On Thu, Nov 06, 2025 at 09:07:22PM -0500, Zi Yan wrote:
>>> On 6 Nov 2025, at 20:17, Wei Yang wrote:
>>>
>>>> On Thu, Nov 06, 2025 at 07:46:14PM -0500, Zi Yan wrote:
>>>>> On 5 Nov 2025, at 22:41, Wei Yang wrote:
>>>>>
>>>>>> The functions uniform_split_supported() and
>>>>>> non_uniform_split_supported() share significantly similar logic.
>>>>>>
>>>>>> The only functional difference is that uniform_split_supported()
>>>>>> includes an additional check on the requested @new_order.
>>>>>>
>>>>>> The reason for this check comes from the following two aspects:
>>>>>>
>>>>>>   * some file system or swap cache just supports order-0 folio
>>>>>>   * the behavioral difference between uniform/non-uniform split
>>>>>>
>>>>>> The behavioral difference between uniform split and non-uniform:
>>>>>>
>>>>>>   * uniform split splits folio directly to @new_order
>>>>>>   * non-uniform split creates after-split folios with orders from
>>>>>>     folio_order(folio) - 1 to new_order.
>>>>>>
>>>>>> This means for non-uniform split or !new_order split we should check the
>>>>>> file system and swap cache respectively.
>>>>>>
>>>>>> This commit unifies the logic and merge the two functions into a single
>>>>>> combined helper, removing redundant code and simplifying the split
>>>>>> support checking mechanism.
>>>>>>
>>>>>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>>>>>> Cc: Zi Yan <ziy@nvidia.com>
>>>>>> Cc: "David Hildenbrand (Red Hat)" <david@kernel.org>
>>>>>>
>>>>>> ---
>>>>>> v3:
>>>>>>   * adjust to use split_type
>>>>>>   * rebase on Zi Yan fix lkml.kernel.org/r/20251105162910.752266-1-ziy@nvidia.com
>>>>>> v2:
>>>>>>   * remove need_check
>>>>>>   * update comment
>>>>>>   * add more explanation in change log
>>>>>> ---
>>>>>>  include/linux/huge_mm.h |  8 ++---
>>>>>>  mm/huge_memory.c        | 71 +++++++++++++++++------------------------
>>>>>>  2 files changed, 33 insertions(+), 46 deletions(-)
>>>>>>
>>>>> LGTM. Thanks. Reviewed-by: Zi Yan <ziy@nvidia.com>
>>>>
>>>> Hi, Zi
>>>>
>>>> I am thinking whether it is proper to move the check (new_order < min_order)
>>>> from __folio_split() to folio_split_supported(). So that we could bail out
>>>> early if file system couldn't split to new_order.
>>>>
>>>> Not sure you like it or not.
>>>
>>> It sounds reasonable. My only concern is that that might add another
>>> indentation to the else branch in folio_split_supported().
>>>
>>> You can send a patch, so we can see how it looks.
>>>
>>
>> Here is what come up my mind.
>>
>> If !CONFIG_READ_ONLY_THP_FOR_FS, we directly compare new_order and min_order.
>>
>> If CONFIG_READ_ONLY_THP_FOR_FS, one thing I am not sure is for the khugepaged
>> collapsed THP. If its min_order is 0, it looks we can cover it with following
>> check.
>
>1. mapping_large_folio_support() checks if mapping_max_folio_order() > 0, meaning
>   !mapping_large_folio_support() is mapping_max_folio_order() == 0,
>2. mapping_max_folio_order() >= mapping_min_folio_order(),
>3. combining 1) and 2) means
>   mapping_min_folio_order() <= mapping_max_folio_order() == 0,
>   meaning mapping_min_folio_order() == 0.
>
>so a FS without large folio support always has min_order == 0.
>
>>
>> Look forward your insight.
>>
>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
>> index dee416b3f6ed..ef05f246df73 100644
>> --- a/mm/huge_memory.c
>> +++ b/mm/huge_memory.c
>> @@ -3704,8 +3704,8 @@ bool folio_split_supported(struct folio *folio, unsigned int new_order,
>>  		if (new_order == 1)
>>  			return false;
>>  	} else if (split_type == SPLIT_TYPE_NON_UNIFORM || new_order) {
>> -		if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
>> -		    !mapping_large_folio_support(folio->mapping)) {
>> +		unsigned int min_order = mapping_min_folio_order(folio->mapping);
>> +		if (new_order < min_order) {
>
>This check is good for !CONFIG_READ_ONLY_THP_FOR_FS, but
>for CONFIG_READ_ONLY_THP_FOR_FS and !mapping_large_folio_support(),
>min_order is always 0, how can new_order be smaller than min_order
>to trigger the warning below? You will need to check new_order against
>mapping_max_folio_order().
>
>OK, basically the check should be:
>

Thanks for your analysis.

>if (new_order < mapping_min_folio_order() || new_order > mapping_max_folio_order()).
>

This reminds me one thing, we don't check on max_order now.

For example, the supported split order is [3, 5]. But new_order is set to 6.

In current kernel, we don't do this. try_folio_split_or_unmap() pass
min_order. But selftest will split from pmd_order - 1.

>Then, you might want to add a helper function mapping_folio_order_supported()
>instead and change the warning message below to "Cannot split file folio to
>unsupported order [%d, %d]", min_order, max_order (showing min/max order
>is optional since it kinda defeat the purpose of having the helper function).
>Of course, the comment needs to be changed.
>
>Hmm, but still how could the above check to trigger the warning when
>split_type == SPLIT_TYPE_NON_UNIFORM and new_order is 0? It will not
>trigger, since new_order (as 0) is supported by the mapping.
>
>I guess the min_order check code has to be in the else branch along
>with the existing "if (split_type == SPLIT_TYPE_NON_UNIFORM || new_order)".
>

I am trying to think another way.

For uniform split, after-split folio order is new_order.
For non-uniform split, after-split folio order is [new_order, old_order - 1].

So I come up following draft change.

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index dee416b3f6ed..873680ab4cbb 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3703,28 +3703,18 @@ bool folio_split_supported(struct folio *folio, unsigned int new_order,
 				"Cannot split to order-1 folio");
 		if (new_order == 1)
 			return false;
-	} else if (split_type == SPLIT_TYPE_NON_UNIFORM || new_order) {
-		if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) &&
-		    !mapping_large_folio_support(folio->mapping)) {
-			/*
-			 * We can always split a folio down to a single page
-			 * (new_order == 0) uniformly.
-			 *
-			 * For any other scenario
-			 *   a) uniform split targeting a large folio
-			 *      (new_order > 0)
-			 *   b) any non-uniform split
-			 * we must confirm that the file system supports large
-			 * folios.
-			 *
-			 * Note that we might still have THPs in such
-			 * mappings, which is created from khugepaged when
-			 * CONFIG_READ_ONLY_THP_FOR_FS is enabled. But in that
-			 * case, the mapping does not actually support large
-			 * folios properly.
-			 */
+	} else {
+		/*
+		 * Some explanation here.
+		 */
+		if (new_order && !mapping_folio_order_supported(new_order)) {
+			VM_WARN_ONCE(warns,
+				"Cannot split file folio to unsupported order: %d", new_order);
+			return false;
+		}
+		if (split_type == SPLIT_TYPE_NON_UNIFORM && !mapping_folio_order_supported(old_order - 1)) {
 			VM_WARN_ONCE(warns,
-				"Cannot split file folio to non-0 order");
+				"Cannot split file folio to unsupported order: %d", old_order - 1);
 			return false;
 		}
 	}
-- 
Wei Yang
Help you, Help me


  reply	other threads:[~2025-11-07  7:29 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06  3:41 [Patch v3 0/2] mm/huge_memory: Define split_type and consolidate split support checks Wei Yang
2025-11-06  3:41 ` [Patch v3 1/2] mm/huge_memory: introduce enum split_type for clarity Wei Yang
2025-11-06 10:17   ` David Hildenbrand (Red Hat)
2025-11-06 14:57     ` Wei Yang
2025-11-07  0:44   ` Zi Yan
2025-11-06  3:41 ` [Patch v3 2/2] mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported() Wei Yang
2025-11-06 10:20   ` David Hildenbrand (Red Hat)
2025-11-07  0:46   ` Zi Yan
2025-11-07  1:17     ` Wei Yang
2025-11-07  2:07       ` Zi Yan
2025-11-07  2:49         ` Wei Yang
2025-11-07  3:21           ` Zi Yan
2025-11-07  7:29             ` Wei Yang [this message]
2025-11-14  3:03               ` Wei Yang
2025-11-17  1:22   ` Wei Yang
2025-11-17 15:56     ` Zi Yan
2025-11-18  2:10       ` Wei Yang
2025-11-18  3:33       ` Wei Yang
2025-11-18  4:10         ` Zi Yan
2025-11-18 18:32           ` Andrew Morton
2025-11-18 18:55             ` Zi Yan
2025-11-18 22:06               ` Andrew Morton
2025-11-19  0:52                 ` Wei Yang
2025-11-20 21:16                   ` Andrew Morton
2025-11-21  0:55                     ` Zi Yan
2025-11-21  9:00                     ` Wei Yang
2025-11-21 14:59                       ` Zi Yan
2025-11-21 16:50                         ` Andrew Morton
2025-11-21 17:00                           ` Zi Yan
2025-11-21 18:39                             ` Andrew Morton
2025-11-21 19:09                               ` Zi Yan
2025-11-21 19:15                                 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251107072944.zvqvr4kyibyofhuw@master \
    --to=richard.weiyang@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=lance.yang@linux.dev \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.com \
    --cc=ryan.roberts@arm.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.