Skip to contentSkip to conversation

mm/huge_memory: consolidate order-related checks into folio_split_supported()

PATCH Superseded Wei Yang 5 participants 14 messages Nov 14, 2025 – Dec 4, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm/huge_memory: consolidate order-related checks into folio_split_supported()

The primary goal of the folio_split_supported() function is to validate whether a folio is suitable for splitting and to bail out early if it is not.

Currently, some order-related checks are scattered throughout the calling code rather than being centralized in folio_split_supported().

This commit moves all remaining order-related validation logic into folio_split_supported(). This consolidation ensures that the function serves its intended purpose as a single point of failure and improves the clarity and maintainability of the surrounding code.

---
 include/linux/pagemap.h |  6 +++
 mm/huge_memory.c        | 88 +++++++++++++++++++++--------------------
 2 files changed, 51 insertions(+), 43 deletions(-)
include/linux/pagemap.h +6 -0
index 09b581c1d878..d8c8df629b90 100644
@@ -516,6 +516,12 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
 	return mapping_max_folio_order(mapping) > 0;
 }
 
+static inline bool
+mapping_folio_order_supported(const struct address_space *mapping, unsigned int order)
+{
+	return (order >= mapping_min_folio_order(mapping) && order <= mapping_max_folio_order(mapping));
+}
+
 /* Return the maximum folio size for this pagecache mapping, in bytes. */
 static inline size_t mapping_max_folio_size(const struct address_space *mapping)
 {
mm/huge_memory.c +45 -43

116 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw
Quoted 11 lines · Wei Yang

The primary goal of the folio_split_supported() function is to validate whether a folio is suitable for splitting and to bail out early if it is not.

Currently, some order-related checks are scattered throughout the calling code rather than being centralized in folio_split_supported().

This commit moves all remaining order-related validation logic into folio_split_supported(). This consolidation ensures that the function serves its intended purpose as a single point of failure and improves the clarity and maintainability of the surrounding code.

Combining the EINVAL handling sounds reasonable.

Quoted 12 lines
---
  include/linux/pagemap.h |  6 +++
  mm/huge_memory.c        | 88 +++++++++++++++++++++--------------------
  2 files changed, 51 insertions(+), 43 deletions(-)
include/linux/pagemap.h +0 -0
index 09b581c1d878..d8c8df629b90 100644

include/linux/pagemap.h static inline bool mapping_large_folio_support(const struct address_space *mappi · line 523

Quoted 8 lines
include/linux/pagemap.h +5 -0
@@ -516,6 +516,12 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
  	return mapping_max_folio_order(mapping) > 0;
  }
 
+static inline bool
+mapping_folio_order_supported(const struct address_space *mapping, unsigned int order)
+{
+	return (order >= mapping_min_folio_order(mapping) && order <= mapping_max_folio_order(mapping));
+}

(unnecessary () and unnecessary long line)

Style in the file seems to want:

static inline bool mapping_folio_order_supported(const struct address_space *mapping,
unsigned int order)

{
	return order >= mapping_min_folio_order(mapping) &&
	       order <= mapping_max_folio_order(mapping);
}

The mapping_max_folio_order() check is new now. What is the default value of that? Is it always initialized properly?

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3693

Quoted 13 lines
include/linux/pagemap.h +1 -0
+
  /* Return the maximum folio size for this pagecache mapping, in bytes. */
  static inline size_t mapping_max_folio_size(const struct address_space *mapping)
  {
mm/huge_memory.c +1 -0
index 0184cd915f44..68faac843527 100644
@@ -3690,34 +3690,58 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
  bool folio_split_supported(struct folio *folio, unsigned int new_order,
  		enum split_type split_type, bool warns)
  {
+	const int old_order = folio_order(folio);

While at it, make it "unsigned int" like new_order.

Quoted 24 lines
mm/huge_memory.c +4 -14
+
+	if (new_order >= old_order)
+		return -EINVAL;
+
  	if (folio_test_anon(folio)) {
  		/* order-1 is not supported for anonymous THP. */
  		VM_WARN_ONCE(warns && new_order == 1,
  				"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.
-			 *

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3707

Quoted 10 lines
mm/huge_memory.c +4 -6
-			 * 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 {
+		const struct address_space *mapping = NULL;
+
+		mapping = folio->mapping;

const struct address_space *mapping = folio->mapping;

Quoted 21 lines
mm/huge_memory.c +21 -0
+
+		/* Truncated ? */
+		/*
+		 * TODO: add support for large shmem folio in swap cache.
+		 * When shmem is in swap cache, mapping is NULL and
+		 * folio_test_swapcache() is true.
+		 */
+		if (!mapping)
+			return false;
+
+		/*
+		 * We have two types of split:
+		 *
+		 *   a) uniform split: split folio directly to new_order.
+		 *   b) non-uniform split: create after-split folios with
+		 *      orders from (old_order - 1) to new_order.
+		 *
+		 * For file system, we encodes it supported folio order in
+		 * mapping->flags, which could be checked by
+		 * mapping_folio_order_supported().
+		 *

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3738

Quoted 10 lines
mm/huge_memory.c +10 -0
+		 * With these knowledge, we can know whether folio support
+		 * split to new_order by:
+		 *
+		 *   1. check new_order is supported first
+		 *   2. check (old_order - 1) is supported if
+		 *      SPLIT_TYPE_NON_UNIFORM
+		 */
+		if (!mapping_folio_order_supported(mapping, new_order)) {
+			VM_WARN_ONCE(warns,
+				"Cannot split file folio to unsupported order: %d", new_order);

Is that really worth a VM_WARN_ONCE? We didn't have that previously IIUC, we would only return -EINVAL.

Signature · 3 lines
Cheers

David
reviewer
#2 lore raw
Quoted 128 lines · David Hildenbrand (Red Hat)
Quoted 11 lines · Wei Yang

The primary goal of the folio_split_supported() function is to validate whether a folio is suitable for splitting and to bail out early if it is not.

Currently, some order-related checks are scattered throughout the calling code rather than being centralized in folio_split_supported().

This commit moves all remaining order-related validation logic into folio_split_supported(). This consolidation ensures that the function serves its intended purpose as a single point of failure and improves the clarity and maintainability of the surrounding code.

Combining the EINVAL handling sounds reasonable.

Quoted 12 lines
---
  include/linux/pagemap.h |  6 +++
  mm/huge_memory.c        | 88 +++++++++++++++++++++--------------------
  2 files changed, 51 insertions(+), 43 deletions(-)
include/linux/pagemap.h +0 -0
index 09b581c1d878..d8c8df629b90 100644

include/linux/pagemap.h static inline bool mapping_large_folio_support(const struct address_space *mappi · line 522

Quoted 7 lines
include/linux/pagemap.h +4 -0
@@ -516,6 +516,12 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
  	return mapping_max_folio_order(mapping) > 0;
  }
 +static inline bool
+mapping_folio_order_supported(const struct address_space *mapping, unsigned int order)
+{
+	return (order >= mapping_min_folio_order(mapping) && order <= mapping_max_folio_order(mapping));
+}

(unnecessary () and unnecessary long line)

Style in the file seems to want:

static inline bool mapping_folio_order_supported(const struct address_space *mapping,
unsigned int order)

{
	return order >= mapping_min_folio_order(mapping) &&
	       order <= mapping_max_folio_order(mapping);
}

The mapping_max_folio_order() check is new now. What is the default value of that? Is it always initialized properly?

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3693

Quoted 13 lines
include/linux/pagemap.h +1 -0
+
  /* Return the maximum folio size for this pagecache mapping, in bytes. */
  static inline size_t mapping_max_folio_size(const struct address_space *mapping)
  {
mm/huge_memory.c +1 -0
index 0184cd915f44..68faac843527 100644
@@ -3690,34 +3690,58 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
  bool folio_split_supported(struct folio *folio, unsigned int new_order,
  		enum split_type split_type, bool warns)
  {
+	const int old_order = folio_order(folio);

While at it, make it "unsigned int" like new_order.

Quoted 24 lines
mm/huge_memory.c +4 -14
+
+	if (new_order >= old_order)
+		return -EINVAL;
+
  	if (folio_test_anon(folio)) {
  		/* order-1 is not supported for anonymous THP. */
  		VM_WARN_ONCE(warns && new_order == 1,
  				"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.
-			 *

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3707

Quoted 10 lines
mm/huge_memory.c +4 -6
-			 * 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 {
+		const struct address_space *mapping = NULL;
+
+		mapping = folio->mapping;

const struct address_space *mapping = folio->mapping;

Quoted 26 lines
mm/huge_memory.c +26 -0
+
+		/* Truncated ? */
+		/*
+		 * TODO: add support for large shmem folio in swap cache.
+		 * When shmem is in swap cache, mapping is NULL and
+		 * folio_test_swapcache() is true.
+		 */
+		if (!mapping)
+			return false;
+
+		/*
+		 * We have two types of split:
+		 *
+		 *   a) uniform split: split folio directly to new_order.
+		 *   b) non-uniform split: create after-split folios with
+		 *      orders from (old_order - 1) to new_order.
+		 *
+		 * For file system, we encodes it supported folio order in
+		 * mapping->flags, which could be checked by
+		 * mapping_folio_order_supported().
+		 *
+		 * With these knowledge, we can know whether folio support
+		 * split to new_order by:
+		 *
+		 *   1. check new_order is supported first
+		 *   2. check (old_order - 1) is supported if
Quoted 8 lines

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3738

Quoted 5 lines
mm/huge_memory.c +5 -0
+		 *      SPLIT_TYPE_NON_UNIFORM
+		 */
+		if (!mapping_folio_order_supported(mapping, new_order)) {
+			VM_WARN_ONCE(warns,
+				"Cannot split file folio to unsupported order: %d", new_order);

Is that really worth a VM_WARN_ONCE? We didn't have that previously IIUC, we would only return -EINVAL.

No, and it causes undesired warning when LBS folio is enabled. I explicitly removed this warning one month ago in the LBS related patch[1].

It is so frustrating to see this part of patch. Wei has RB in the aforementioned patch and still add this warning blindly. I am not sure if Wei understands what he is doing, since he threw the idea to me and I told him to just move the code without changing the logic, but he insisted doing it in his own way and failed[2]. This retry is still wrong.

Wei, please make sure you understand the code before sending any patch.

[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/20251114030301.hkestzrk534ik7q4@master/

Best Regards,
Yan, Zi

author
#3 lore raw
Quoted 2 lines · Zi Yan

On 14 Nov 2025, at 3:49, David Hildenbrand (Red Hat) wrote:

[...]

Quoted 63 lines
Quoted 63 lines
Quoted 24 lines
mm/huge_memory.c +4 -14
+
+	if (new_order >= old_order)
+		return -EINVAL;
+
  	if (folio_test_anon(folio)) {
  		/* order-1 is not supported for anonymous THP. */
  		VM_WARN_ONCE(warns && new_order == 1,
  				"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.
-			 *

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3707

Quoted 10 lines
mm/huge_memory.c +4 -6
-			 * 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 {
+		const struct address_space *mapping = NULL;
+
+		mapping = folio->mapping;

const struct address_space *mapping = folio->mapping;

Quoted 26 lines
mm/huge_memory.c +26 -0
+
+		/* Truncated ? */
+		/*
+		 * TODO: add support for large shmem folio in swap cache.
+		 * When shmem is in swap cache, mapping is NULL and
+		 * folio_test_swapcache() is true.
+		 */
+		if (!mapping)
+			return false;
+
+		/*
+		 * We have two types of split:
+		 *
+		 *   a) uniform split: split folio directly to new_order.
+		 *   b) non-uniform split: create after-split folios with
+		 *      orders from (old_order - 1) to new_order.
+		 *
+		 * For file system, we encodes it supported folio order in
+		 * mapping->flags, which could be checked by
+		 * mapping_folio_order_supported().
+		 *
+		 * With these knowledge, we can know whether folio support
+		 * split to new_order by:
+		 *
+		 *   1. check new_order is supported first
+		 *   2. check (old_order - 1) is supported if
Quoted 9 lines
Quoted 8 lines

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3738

Quoted 5 lines
mm/huge_memory.c +5 -0
+		 *      SPLIT_TYPE_NON_UNIFORM
+		 */
+		if (!mapping_folio_order_supported(mapping, new_order)) {
+			VM_WARN_ONCE(warns,
+				"Cannot split file folio to unsupported order: %d", new_order);

Is that really worth a VM_WARN_ONCE? We didn't have that previously IIUC, we would only return -EINVAL.

Sorry for introducing this unpleasant affair.

Hope I can explain what I have done.

Quoted 3 lines

No, and it causes undesired warning when LBS folio is enabled. I explicitly removed this warning one month ago in the LBS related patch[1].

Yes, I see you removal of a warning in [1].

While in the discussion in [2], you mentioned:

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.

I thought you agree to print a warning message here. So I am confused.

Quoted 6 lines

It is so frustrating to see this part of patch. Wei has RB in the aforementioned patch and still add this warning blindly. I am not sure if Wei understands what he is doing, since he threw the idea to me and I told him to just move the code without changing the logic, but he insisted doing it in his own way and failed[2]. This retry is still wrong.

I think we are still discussing the problem and a patch maybe more convenient to proceed. I didn't insist anything and actually I am looking forward your option and always respect your insight. Never thought to offend you.

In discussion [2], you pointed out two concerns:

1) new_order < min_order is meaning less if min_order is 0
2) how to do the check if new_order is 0 for non-uniform split

For 1), you suggested to add mapping_folio_order_supported(). For 2), I come up an idea to check (old_order - 1) <= max_order. Originally, we just check !max_order. I think this could cover it.

So I gather them together here to see whether it is suitable.

If I missed some part, hope you could let me know.

Quoted 7 lines

Wei, please make sure you understand the code before sending any patch.

[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/20251114030301.hkestzrk534ik7q4@master/

Best Regards,
Yan, Zi

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#4 lore raw
Quoted 89 lines · Wei Yang
Quoted 2 lines · Zi Yan

On 14 Nov 2025, at 3:49, David Hildenbrand (Red Hat) wrote:

[...]

Quoted 63 lines
Quoted 63 lines
Quoted 24 lines
mm/huge_memory.c +4 -14
+
+	if (new_order >= old_order)
+		return -EINVAL;
+
  	if (folio_test_anon(folio)) {
  		/* order-1 is not supported for anonymous THP. */
  		VM_WARN_ONCE(warns && new_order == 1,
  				"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.
-			 *

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3707

Quoted 10 lines
mm/huge_memory.c +4 -6
-			 * 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 {
+		const struct address_space *mapping = NULL;
+
+		mapping = folio->mapping;

const struct address_space *mapping = folio->mapping;

Quoted 26 lines
mm/huge_memory.c +26 -0
+
+		/* Truncated ? */
+		/*
+		 * TODO: add support for large shmem folio in swap cache.
+		 * When shmem is in swap cache, mapping is NULL and
+		 * folio_test_swapcache() is true.
+		 */
+		if (!mapping)
+			return false;
+
+		/*
+		 * We have two types of split:
+		 *
+		 *   a) uniform split: split folio directly to new_order.
+		 *   b) non-uniform split: create after-split folios with
+		 *      orders from (old_order - 1) to new_order.
+		 *
+		 * For file system, we encodes it supported folio order in
+		 * mapping->flags, which could be checked by
+		 * mapping_folio_order_supported().
+		 *
+		 * With these knowledge, we can know whether folio support
+		 * split to new_order by:
+		 *
+		 *   1. check new_order is supported first
+		 *   2. check (old_order - 1) is supported if
Quoted 9 lines
Quoted 8 lines

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3738

Quoted 5 lines
mm/huge_memory.c +5 -0
+		 *      SPLIT_TYPE_NON_UNIFORM
+		 */
+		if (!mapping_folio_order_supported(mapping, new_order)) {
+			VM_WARN_ONCE(warns,
+				"Cannot split file folio to unsupported order: %d", new_order);

Is that really worth a VM_WARN_ONCE? We didn't have that previously IIUC, we would only return -EINVAL.

Sorry for introducing this unpleasant affair.

Hope I can explain what I have done.

Quoted 3 lines

No, and it causes undesired warning when LBS folio is enabled. I explicitly removed this warning one month ago in the LBS related patch[1].

Yes, I see you removal of a warning in [1].

While in the discussion in [2], you mentioned:

Quoted 7 lines

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.

I thought you agree to print a warning message here. So I am confused.

This is exactly my point. You need to know what you are doing. You should not write a patch because of what I said. And my above comment is to CONFIG_READ_ONLY_THP_FOR_FS part of code. It has nothing
to do with the check pulled into folio_split_supported().

Quoted 11 lines
Quoted 7 lines

It is so frustrating to see this part of patch. Wei has RB in the aforementioned patch and still add this warning blindly. I am not sure if Wei understands what he is doing, since he threw the idea to me and I told him to just move the code without changing the logic, but he insisted doing it in his own way and failed[2]. This retry is still wrong.

I think we are still discussing the problem and a patch maybe more convenient to proceed. I didn't insist anything and actually I am looking forward your option and always respect your insight. Never thought to offend you.

Not offended.

Quoted 6 lines

In discussion [2], you pointed out two concerns:

1) new_order < min_order is meaning less if min_order is 0
2) how to do the check if new_order is 0 for non-uniform split

Quoted 7 lines

For 1), you suggested to add mapping_folio_order_supported(). For 2), I come up an idea to check (old_order - 1) <= max_order. Originally, we just check !max_order. I think this could cover it.

So I gather them together here to see whether it is suitable.

If I missed some part, hope you could let me know.

Based on the discussion in [2], your patch mixes the checks for FS does not support large folio and FS supporting large folio has min_order requirement and I told you that it does not work well and suggested you to just move “if (new_order < min_order) {“ part into folio_split_supported() as an easy approach. Why not do that?

Quoted 12 lines
Quoted 8 lines

Wei, please make sure you understand the code before sending any patch.

[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/20251114030301.hkestzrk534ik7q4@master/

Best Regards,
Yan, Zi

Signature · 2 lines
Wei Yang
Help you, Help me

Best Regards,
Yan, Zi

author
#5 lore raw
Quoted 97 lines · Zi Yan
Quoted 95 lines · Wei Yang
Quoted 2 lines · Zi Yan

On 14 Nov 2025, at 3:49, David Hildenbrand (Red Hat) wrote:

[...]

Quoted 63 lines
Quoted 63 lines
Quoted 24 lines
(quoted diff) +4 -14
+
+	if (new_order >= old_order)
+		return -EINVAL;
+
  	if (folio_test_anon(folio)) {
  		/* order-1 is not supported for anonymous THP. */
  		VM_WARN_ONCE(warns && new_order == 1,
  				"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.
-			 *

Review

Quoted 10 lines
(quoted diff) +4 -6
-			 * 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 {
+		const struct address_space *mapping = NULL;
+
+		mapping = folio->mapping;

const struct address_space *mapping = folio->mapping;

Quoted 26 lines
(quoted diff) +26 -0
+
+		/* Truncated ? */
+		/*
+		 * TODO: add support for large shmem folio in swap cache.
+		 * When shmem is in swap cache, mapping is NULL and
+		 * folio_test_swapcache() is true.
+		 */
+		if (!mapping)
+			return false;
+
+		/*
+		 * We have two types of split:
+		 *
+		 *   a) uniform split: split folio directly to new_order.
+		 *   b) non-uniform split: create after-split folios with
+		 *      orders from (old_order - 1) to new_order.
+		 *
+		 * For file system, we encodes it supported folio order in
+		 * mapping->flags, which could be checked by
+		 * mapping_folio_order_supported().
+		 *
+		 * With these knowledge, we can know whether folio support
+		 * split to new_order by:
+		 *
+		 *   1. check new_order is supported first
+		 *   2. check (old_order - 1) is supported if
Quoted 9 lines
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		 *      SPLIT_TYPE_NON_UNIFORM
+		 */
+		if (!mapping_folio_order_supported(mapping, new_order)) {
+			VM_WARN_ONCE(warns,
+				"Cannot split file folio to unsupported order: %d", new_order);

Is that really worth a VM_WARN_ONCE? We didn't have that previously IIUC, we would only return -EINVAL.

Sorry for introducing this unpleasant affair.

Hope I can explain what I have done.

Quoted 3 lines

No, and it causes undesired warning when LBS folio is enabled. I explicitly removed this warning one month ago in the LBS related patch[1].

Yes, I see you removal of a warning in [1].

While in the discussion in [2], you mentioned:

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.

Quoted 7 lines
Quoted 1 line

I thought you agree to print a warning message here. So I am confused.

This is exactly my point. You need to know what you are doing. You should not write a patch because of what I said. And my above comment is to CONFIG_READ_ONLY_THP_FOR_FS part of code. It has nothing
to do with the check pulled into folio_split_supported().

Yes, I thought they serve the same purpose(checking supported folio order), so print the warning both.

If should not, I will remove it.

Quoted 25 lines
Quoted 11 lines
Quoted 7 lines

It is so frustrating to see this part of patch. Wei has RB in the aforementioned patch and still add this warning blindly. I am not sure if Wei understands what he is doing, since he threw the idea to me and I told him to just move the code without changing the logic, but he insisted doing it in his own way and failed[2]. This retry is still wrong.

I think we are still discussing the problem and a patch maybe more convenient to proceed. I didn't insist anything and actually I am looking forward your option and always respect your insight. Never thought to offend you.

Not offended.

Quoted 12 lines

In discussion [2], you pointed out two concerns:

1) new_order < min_order is meaning less if min_order is 0
2) how to do the check if new_order is 0 for non-uniform split

For 1), you suggested to add mapping_folio_order_supported(). For 2), I come up an idea to check (old_order - 1) <= max_order. Originally, we just check !max_order. I think this could cover it.

So I gather them together here to see whether it is suitable.

Quoted 8 lines
Quoted 1 line

If I missed some part, hope you could let me know.

Based on the discussion in [2], your patch mixes the checks for FS does not support large folio and FS supporting large folio has min_order requirement and I told you that it does not work well and suggested you to just move “if (new_order < min_order) {“ part into folio_split_supported() as an easy approach. Why not do that?

I may not follow you. Let me try to clear my mind.

My first approach is :

mm/huge_memory.c +2 -2
index dee416b3f6ed..ef05f246df73 100644
@@ -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) {
 			/*
 			 * We can always split a folio down to a single page
 			 * (new_order == 0) uniformly.

Current patch does 3 major changes.

1)

Your comment to above change:

```
   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.

   ...
   
   OK, basically the check should be:
   
     if (new_order < mapping_min_folio_order() || new_order > mapping_max_folio_order()).
   
   Then, you might want to add a helper function mapping_folio_order_supported().
```

So in this patch, I introduce mapping_folio_order_supported() and replace the (new_order < min_order) check. Still use (new_order < min_order) looks not correct. Or I misunderstand your suggestion?

2)

And then you mentioned this check is not enough:

```
    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.
```

What come up my mind is to check with old_orer - 1 is also supported. So for SPLIT_TYPE_NON_UNIFORM, the after-split folio range [min_order, old_order - 1] are all checked.

3)

Also I remove the first "if (split_type == SPLIT_TYPE_NON_UNIFORM || new_order)".

Because in original logic, when split_type == SPLIT_TYPE_UNIFORM && new_order == 0, we should still check (new_order < min_order). If not we would miss that.

But sounds I misunderstand you insight, I am sorry for that. If not too bother, would you mind sharing it again?

Quoted 16 lines
Quoted 12 lines
Quoted 8 lines

Wei, please make sure you understand the code before sending any patch.

[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/20251114030301.hkestzrk534ik7q4@master/

Best Regards,
Yan, Zi

Signature · 2 lines
Wei Yang
Help you, Help me

Best Regards,
Yan, Zi

Signature · 2 lines
Wei Yang
Help you, Help me
author
#6 lore raw
In reply to David Hildenbrand (Red Hat)
Quoted 8 lines · David Hildenbrand (Red Hat)
Quoted 7 lines · Wei Yang

The primary goal of the folio_split_supported() function is to validate whether a folio is suitable for splitting and to bail out early if it is not.

Currently, some order-related checks are scattered throughout the calling code rather than being centralized in folio_split_supported().

Quoted 7 lines
Quoted 4 lines

This commit moves all remaining order-related validation logic into folio_split_supported(). This consolidation ensures that the function serves its intended purpose as a single point of failure and improves the clarity and maintainability of the surrounding code.

Combining the EINVAL handling sounds reasonable.

You mean:

This commit combines the EINVAL handling logic into folio_split_supported(). This consolidation ... ?

Quoted 22 lines
Quoted 12 lines
---
  include/linux/pagemap.h |  6 +++
  mm/huge_memory.c        | 88 +++++++++++++++++++++--------------------
  2 files changed, 51 insertions(+), 43 deletions(-)
include/linux/pagemap.h +0 -0
index 09b581c1d878..d8c8df629b90 100644

include/linux/pagemap.h static inline bool mapping_large_folio_support(const struct address_space *mappi · line 522

Quoted 7 lines
include/linux/pagemap.h +5 -0
@@ -516,6 +516,12 @@ static inline bool mapping_large_folio_support(const struct address_space *mappi
  	return mapping_max_folio_order(mapping) > 0;
  }
+static inline bool
+mapping_folio_order_supported(const struct address_space *mapping, unsigned int order)
+{
+	return (order >= mapping_min_folio_order(mapping) && order <= mapping_max_folio_order(mapping));
+}

(unnecessary () and unnecessary long line)

Quoted 9 lines

Style in the file seems to want:

static inline bool mapping_folio_order_supported(const struct address_space *mapping,
unsigned int order)

{
	return order >= mapping_min_folio_order(mapping) &&
	       order <= mapping_max_folio_order(mapping);
}

Adjusted.

Quoted 3 lines

The mapping_max_folio_order() check is new now. What is the default value of that? Is it always initialized properly?

Not sure "is new now" means what?

Original check use mapping_large_folio_support() which calls mapping_max_folio_order(). It looks not new to me.

If my understanding is correct, struct address_mapping is part of struct inode, which is initialized by inode_init_once() which clears flags. So the default value is 0.

Quoted 7 lines
Quoted 7 lines
include/linux/pagemap.h +1 -0
+
  /* Return the maximum folio size for this pagecache mapping, in bytes. */
  static inline size_t mapping_max_folio_size(const struct address_space *mapping)
  {
mm/huge_memory.c +0 -1
index 0184cd915f44..68faac843527 100644
--- a/mm/huge_memory.c
Quoted 9 lines

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3693

Quoted 6 lines

+++ b/mm/huge_memory.c

mm/huge_memory.c +1 -0
@@ -3690,34 +3690,58 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
  bool folio_split_supported(struct folio *folio, unsigned int new_order,
  		enum split_type split_type, bool warns)
  {
+	const int old_order = folio_order(folio);

While at it, make it "unsigned int" like new_order.

Adjusted.

Quoted 28 lines
Quoted 28 lines
mm/huge_memory.c +4 -18
+
+	if (new_order >= old_order)
+		return -EINVAL;
+
  	if (folio_test_anon(folio)) {
  		/* order-1 is not supported for anonymous THP. */
  		VM_WARN_ONCE(warns && new_order == 1,
  				"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
Quoted 9 lines

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3707

Quoted 6 lines
mm/huge_memory.c +4 -2
-			 * folios properly.
-			 */
+	} else {
+		const struct address_space *mapping = NULL;
+
+		mapping = folio->mapping;

const struct address_space *mapping = folio->mapping;

Adjusted.

Quoted 26 lines
Quoted 26 lines
mm/huge_memory.c +26 -0
+
+		/* Truncated ? */
+		/*
+		 * TODO: add support for large shmem folio in swap cache.
+		 * When shmem is in swap cache, mapping is NULL and
+		 * folio_test_swapcache() is true.
+		 */
+		if (!mapping)
+			return false;
+
+		/*
+		 * We have two types of split:
+		 *
+		 *   a) uniform split: split folio directly to new_order.
+		 *   b) non-uniform split: create after-split folios with
+		 *      orders from (old_order - 1) to new_order.
+		 *
+		 * For file system, we encodes it supported folio order in
+		 * mapping->flags, which could be checked by
+		 * mapping_folio_order_supported().
+		 *
+		 * With these knowledge, we can know whether folio support
+		 * split to new_order by:
+		 *
+		 *   1. check new_order is supported first
+		 *   2. check (old_order - 1) is supported if
Quoted 8 lines

mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3738

Quoted 5 lines
mm/huge_memory.c +5 -0
+		 *      SPLIT_TYPE_NON_UNIFORM
+		 */
+		if (!mapping_folio_order_supported(mapping, new_order)) {
+			VM_WARN_ONCE(warns,
+				"Cannot split file folio to unsupported order: %d", new_order);

Is that really worth a VM_WARN_ONCE? We didn't have that previously IIUC, we would only return -EINVAL.

Hmm.. it seems not necessary. Thanks

Quoted 5 lines
Signature · 4 lines
-- 
Cheers

David
Signature · 2 lines
Wei Yang
Help you, Help me
#7 lore raw
Quoted 14 lines · Wei Yang
Quoted 13 lines · David Hildenbrand (Red Hat)
Quoted 11 lines · Wei Yang

The primary goal of the folio_split_supported() function is to validate whether a folio is suitable for splitting and to bail out early if it is not.

Currently, some order-related checks are scattered throughout the calling code rather than being centralized in folio_split_supported().

This commit moves all remaining order-related validation logic into folio_split_supported(). This consolidation ensures that the function serves its intended purpose as a single point of failure and improves the clarity and maintainability of the surrounding code.

Quoted 7 lines
Quoted 2 lines

Combining the EINVAL handling sounds reasonable.

You mean:

This commit combines the EINVAL handling logic into folio_split_supported(). This consolidation ... ?

It was not a suggestion to change, it was rather only a comment from my side :)

[...]

Quoted 8 lines
Quoted 3 lines

The mapping_max_folio_order() check is new now. What is the default value of that? Is it always initialized properly?

Not sure "is new now" means what?

Original check use mapping_large_folio_support() which calls mapping_max_folio_order(). It looks not new to me.

Right, but we did not actually care about the exact value.

IOW, we didn't check for order <= mapping_max_folio_order() before.

SO I'm just curious if that is universally fine.

Signature · 3 lines
Cheers

David
author
#8 lore raw
Quoted 34 lines · David Hildenbrand (Red Hat)
Quoted 14 lines · Wei Yang
Quoted 13 lines · David Hildenbrand (Red Hat)
Quoted 11 lines · Wei Yang

The primary goal of the folio_split_supported() function is to validate whether a folio is suitable for splitting and to bail out early if it is not.

Currently, some order-related checks are scattered throughout the calling code rather than being centralized in folio_split_supported().

This commit moves all remaining order-related validation logic into folio_split_supported(). This consolidation ensures that the function serves its intended purpose as a single point of failure and improves the clarity and maintainability of the surrounding code.

Quoted 7 lines
Quoted 2 lines

Combining the EINVAL handling sounds reasonable.

You mean:

This commit combines the EINVAL handling logic into folio_split_supported(). This consolidation ... ?

It was not a suggestion to change, it was rather only a comment from my side :)

[...]

Quoted 6 lines
Quoted 3 lines

The mapping_max_folio_order() check is new now. What is the default value of that? Is it always initialized properly?

Not sure "is new now" means what?

Quoted 9 lines
Quoted 2 lines

Original check use mapping_large_folio_support() which calls mapping_max_folio_order(). It looks not new to me.

Right, but we did not actually care about the exact value.

IOW, we didn't check for order <= mapping_max_folio_order() before.

SO I'm just curious if that is universally fine.

Thanks, I got your point.

I am not 100% for sure. While if we trust it returns 0 if folio doesn't support large folio, I am afraid we can trust it returns correct value it supports. Or that would be the issue to related file system.

To be honest, I am lack of the capability to investigate all file system to make sure this value is properly setup.

Quoted 4 lines
Signature · 3 lines
Cheers

David
Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#9 lore raw
Quoted 6 lines · Wei Yang

I am not 100% for sure. While if we trust it returns 0 if folio doesn't support large folio, I am afraid we can trust it returns correct value it supports. Or that would be the issue to related file system.

To be honest, I am lack of the capability to investigate all file system to make sure this value is properly setup.

Maybe you should just give up on this instead of asking so many questions, misunderstanding the answers, and sending more patches full of mistakes?

author
#10 lore raw
Quoted 11 lines · Matthew Wilcox
Quoted 6 lines · Wei Yang

I am not 100% for sure. While if we trust it returns 0 if folio doesn't support large folio, I am afraid we can trust it returns correct value it supports. Or that would be the issue to related file system.

To be honest, I am lack of the capability to investigate all file system to make sure this value is properly setup.

Maybe you should just give up on this instead of asking so many questions, misunderstanding the answers, and sending more patches full of mistakes?

Hi, Matthew

I am glad to see your reply, but your comment makes me feel frustrated.

Well, I think we still talk about the fact. You pointed out three flaws:

* too many questions
* too many misunderstandings
* full of mistakes

Per my understanding, there is only one question: whether mapping_max_folio_order() works universally. I think it does and also Zi suggested to use it. But since I am not sure about this, we can revert it to keep the logic same as current.

For misunderstandings, I use the word to be polite and avoid conflict. I went through the discussion with Zi and thought I did what he suggested. In case I do miss something, Zi would correct me.

For full of mistakes, I am confused. I did some contributions in kernel, small of course. Mostly correct and get merged. I know sometimes I made mistakes, but full of mistakes, it seems not to be true.

Well, I still think this is a common review process, I am open to comment and questions. And also glad to take suggestions from community. I still think it is reasonable to combine the EINVAL handling, while the detail need to be settled down.

Have a nice weekend all.

Signature · 2 lines
Wei Yang
Help you, Help me
author
#11 lore raw
In reply to David Hildenbrand (Red Hat)
Quoted 34 lines · David Hildenbrand (Red Hat)
Quoted 14 lines · Wei Yang
Quoted 13 lines · David Hildenbrand (Red Hat)
Quoted 11 lines · Wei Yang

The primary goal of the folio_split_supported() function is to validate whether a folio is suitable for splitting and to bail out early if it is not.

Currently, some order-related checks are scattered throughout the calling code rather than being centralized in folio_split_supported().

This commit moves all remaining order-related validation logic into folio_split_supported(). This consolidation ensures that the function serves its intended purpose as a single point of failure and improves the clarity and maintainability of the surrounding code.

Quoted 7 lines
Quoted 2 lines

Combining the EINVAL handling sounds reasonable.

You mean:

This commit combines the EINVAL handling logic into folio_split_supported(). This consolidation ... ?

It was not a suggestion to change, it was rather only a comment from my side :)

[...]

Quoted 6 lines
Quoted 3 lines

The mapping_max_folio_order() check is new now. What is the default value of that? Is it always initialized properly?

Not sure "is new now" means what?

Quoted 9 lines
Quoted 2 lines

Original check use mapping_large_folio_support() which calls mapping_max_folio_order(). It looks not new to me.

Right, but we did not actually care about the exact value.

IOW, we didn't check for order <= mapping_max_folio_order() before.

SO I'm just curious if that is universally fine.

Hi, David

I just happened to come across some code that might address your question here.

Take a look at the function __filemap_get_folio(). It uses mapping_max_folio_order() and mapping_min_folio_order() to determine the appropriate folio order for page cache allocation.

Just want to share what I found.

Quoted 4 lines
Signature · 3 lines
Cheers

David
Signature · 2 lines
Wei Yang
Help you, Help me
build bot
#12 lore raw
In reply to Wei Yang
BCC: [email protected] CC: [email protected] In-Reply-To: <[email protected]> References: <[email protected]> TO: Wei Yang…

BCC: [email protected]
CC: [email protected]
In-Reply-To: <[email protected]>
References: <[email protected]>
TO: Wei Yang <[email protected]>
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
TO: [email protected]
CC: [email protected]
CC: [email protected]
CC: Wei Yang <[email protected]>

Hi Wei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/mm-huge_memory-consolidate-order-related-checks-into-folio_split_supported/20251114-155833
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20251114075703.10434-1-richard.weiyang%40gmail.com
patch subject: [PATCH] mm/huge_memory: consolidate order-related checks into folio_split_supported()

:::::: branch date: 25 hours ago
:::::: commit date: 25 hours ago
config: i386-randconfig-141-20251115 (https://download.01.org/0day-ci/archive/20251115/[email protected]/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
mm/huge_memory.c:3696 folio_split_supported() warn: signedness bug returning '(-22)'

vim +3696 mm/huge_memory.c

00527733d0dc80 Zi Yan   2025-03-07  3689  
aa27253af32c74 Wei Yang 2025-11-06  3690  bool folio_split_supported(struct folio *folio, unsigned int new_order,
aa27253af32c74 Wei Yang 2025-11-06  3691  		enum split_type split_type, bool warns)
58729c04cf1092 Zi Yan   2025-03-07  3692  {
ab62f1bb0caaa5 Wei Yang 2025-11-14  3693  	const int old_order = folio_order(folio);
ab62f1bb0caaa5 Wei Yang 2025-11-14  3694  
ab62f1bb0caaa5 Wei Yang 2025-11-14  3695  	if (new_order >= old_order)
ab62f1bb0caaa5 Wei Yang 2025-11-14 @3696  		return -EINVAL;
ab62f1bb0caaa5 Wei Yang 2025-11-14  3697  
58729c04cf1092 Zi Yan   2025-03-07  3698  	if (folio_test_anon(folio)) {
58729c04cf1092 Zi Yan   2025-03-07  3699  		/* order-1 is not supported for anonymous THP. */
58729c04cf1092 Zi Yan   2025-03-07  3700  		VM_WARN_ONCE(warns && new_order == 1,
58729c04cf1092 Zi Yan   2025-03-07  3701  				"Cannot split to order-1 folio");
28753037121116 Zi Yan   2025-11-05  3702  		if (new_order == 1)
28753037121116 Zi Yan   2025-11-05  3703  			return false;
ab62f1bb0caaa5 Wei Yang 2025-11-14  3704  	} else {
ab62f1bb0caaa5 Wei Yang 2025-11-14  3705  		const struct address_space *mapping = NULL;
ab62f1bb0caaa5 Wei Yang 2025-11-14  3706  
ab62f1bb0caaa5 Wei Yang 2025-11-14  3707  		mapping = folio->mapping;
ab62f1bb0caaa5 Wei Yang 2025-11-14  3708  
ab62f1bb0caaa5 Wei Yang 2025-11-14  3709  		/* Truncated ? */
ab62f1bb0caaa5 Wei Yang 2025-11-14  3710  		/*
ab62f1bb0caaa5 Wei Yang 2025-11-14  3711  		 * TODO: add support for large shmem folio in swap cache.
ab62f1bb0caaa5 Wei Yang 2025-11-14  3712  		 * When shmem is in swap cache, mapping is NULL and
ab62f1bb0caaa5 Wei Yang 2025-11-14  3713  		 * folio_test_swapcache() is true.
ab62f1bb0caaa5 Wei Yang 2025-11-14  3714  		 */
ab62f1bb0caaa5 Wei Yang 2025-11-14  3715  		if (!mapping)
ab62f1bb0caaa5 Wei Yang 2025-11-14  3716  			return false;
ab62f1bb0caaa5 Wei Yang 2025-11-14  3717  
58729c04cf1092 Zi Yan   2025-03-07  3718  		/*
ab62f1bb0caaa5 Wei Yang 2025-11-14  3719  		 * We have two types of split:
ab62f1bb0caaa5 Wei Yang 2025-11-14  3720  		 *
ab62f1bb0caaa5 Wei Yang 2025-11-14  3721  		 *   a) uniform split: split folio directly to new_order.
ab62f1bb0caaa5 Wei Yang 2025-11-14  3722  		 *   b) non-uniform split: create after-split folios with
ab62f1bb0caaa5 Wei Yang 2025-11-14  3723  		 *      orders from (old_order - 1) to new_order.
ab62f1bb0caaa5 Wei Yang 2025-11-14  3724  		 *
ab62f1bb0caaa5 Wei Yang 2025-11-14  3725  		 * For file system, we encodes it supported folio order in
ab62f1bb0caaa5 Wei Yang 2025-11-14  3726  		 * mapping->flags, which could be checked by
ab62f1bb0caaa5 Wei Yang 2025-11-14  3727  		 * mapping_folio_order_supported().
aa27253af32c74 Wei Yang 2025-11-06  3728  		 *
ab62f1bb0caaa5 Wei Yang 2025-11-14  3729  		 * With these knowledge, we can know whether folio support
ab62f1bb0caaa5 Wei Yang 2025-11-14  3730  		 * split to new_order by:
aa27253af32c74 Wei Yang 2025-11-06  3731  		 *
ab62f1bb0caaa5 Wei Yang 2025-11-14  3732  		 *   1. check new_order is supported first
ab62f1bb0caaa5 Wei Yang 2025-11-14  3733  		 *   2. check (old_order - 1) is supported if
ab62f1bb0caaa5 Wei Yang 2025-11-14  3734  		 *      SPLIT_TYPE_NON_UNIFORM
58729c04cf1092 Zi Yan   2025-03-07  3735  		 */
ab62f1bb0caaa5 Wei Yang 2025-11-14  3736  		if (!mapping_folio_order_supported(mapping, new_order)) {
58729c04cf1092 Zi Yan   2025-03-07  3737  			VM_WARN_ONCE(warns,
ab62f1bb0caaa5 Wei Yang 2025-11-14  3738  				"Cannot split file folio to unsupported order: %d", new_order);
ab62f1bb0caaa5 Wei Yang 2025-11-14  3739  			return false;
ab62f1bb0caaa5 Wei Yang 2025-11-14  3740  		}
ab62f1bb0caaa5 Wei Yang 2025-11-14  3741  		if (split_type == SPLIT_TYPE_NON_UNIFORM
ab62f1bb0caaa5 Wei Yang 2025-11-14  3742  		    && !mapping_folio_order_supported(mapping, old_order - 1)) {
ab62f1bb0caaa5 Wei Yang 2025-11-14  3743  			VM_WARN_ONCE(warns,
ab62f1bb0caaa5 Wei Yang 2025-11-14  3744  				"Cannot split file folio to unsupported order: %d", old_order - 1);
58729c04cf1092 Zi Yan   2025-03-07  3745  			return false;
58729c04cf1092 Zi Yan   2025-03-07  3746  		}
58729c04cf1092 Zi Yan   2025-03-07  3747  	}
58729c04cf1092 Zi Yan   2025-03-07  3748  
aa27253af32c74 Wei Yang 2025-11-06  3749  	/*
aa27253af32c74 Wei Yang 2025-11-06  3750  	 * swapcache folio could only be split to order 0
aa27253af32c74 Wei Yang 2025-11-06  3751  	 *
aa27253af32c74 Wei Yang 2025-11-06  3752  	 * non-uniform split creates after-split folios with orders from
aa27253af32c74 Wei Yang 2025-11-06  3753  	 * folio_order(folio) - 1 to new_order, making it not suitable for any
aa27253af32c74 Wei Yang 2025-11-06  3754  	 * swapcache folio split. Only uniform split to order-0 can be used
aa27253af32c74 Wei Yang 2025-11-06  3755  	 * here.
aa27253af32c74 Wei Yang 2025-11-06  3756  	 */
aa27253af32c74 Wei Yang 2025-11-06  3757  	if ((split_type == SPLIT_TYPE_NON_UNIFORM || new_order) && folio_test_swapcache(folio)) {
58729c04cf1092 Zi Yan   2025-03-07  3758  		VM_WARN_ONCE(warns,
58729c04cf1092 Zi Yan   2025-03-07  3759  			"Cannot split swapcache folio to non-0 order");
58729c04cf1092 Zi Yan   2025-03-07  3760  		return false;
58729c04cf1092 Zi Yan   2025-03-07  3761  	}
58729c04cf1092 Zi Yan   2025-03-07  3762  
58729c04cf1092 Zi Yan   2025-03-07  3763  	return true;
58729c04cf1092 Zi Yan   2025-03-07  3764  }
58729c04cf1092 Zi Yan   2025-03-07  3765  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#13 lore raw
Quoted 24 lines · Dan Carpenter

Hi Wei,

kernel test robot noticed the following build warnings:

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/mm-huge_memory-consolidate-order-related-checks-into-folio_split_supported/20251114-155833
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20251114075703.10434-1-richard.weiyang%40gmail.com
patch subject: [PATCH] mm/huge_memory: consolidate order-related checks into folio_split_supported()
config: i386-randconfig-141-20251115 (https://download.01.org/0day-ci/archive/20251115/[email protected]/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags

| Reported-by: kernel test robot <[email protected]>
| Reported-by: Dan Carpenter <[email protected]>
| Closes: https://lore.kernel.org/r/[email protected]/

smatch warnings:
mm/huge_memory.c:3696 folio_split_supported() warn: signedness bug returning '(-22)'

vim +3696 mm/huge_memory.c

aa27253af32c74 Wei Yang 2025-11-06 3690 bool folio_split_supported(struct folio *folio, unsigned int new_order,

                                         ^^^^
Quoted 8 lines

This is a bool function.

aa27253af32c74 Wei Yang 2025-11-06  3691  		enum split_type split_type, bool warns)
58729c04cf1092 Zi Yan   2025-03-07  3692  {
ab62f1bb0caaa5 Wei Yang 2025-11-14  3693  	const int old_order = folio_order(folio);
ab62f1bb0caaa5 Wei Yang 2025-11-14  3694  
ab62f1bb0caaa5 Wei Yang 2025-11-14  3695  	if (new_order >= old_order)

ab62f1bb0caaa5 Wei Yang 2025-11-14 @3696 return -EINVAL;

Thanks, this is noticed.

Quoted 14 lines

s/-EINVAL/false/

ab62f1bb0caaa5 Wei Yang 2025-11-14  3697  
58729c04cf1092 Zi Yan   2025-03-07  3698  	if (folio_test_anon(folio)) {
58729c04cf1092 Zi Yan   2025-03-07  3699  		/* order-1 is not supported for anonymous THP. */
58729c04cf1092 Zi Yan   2025-03-07  3700  		VM_WARN_ONCE(warns && new_order == 1,
58729c04cf1092 Zi Yan   2025-03-07  3701  				"Cannot split to order-1 folio");
28753037121116 Zi Yan   2025-11-05  3702  		if (new_order == 1)
28753037121116 Zi Yan   2025-11-05  3703  			return false;
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Signature · 2 lines
Wei Yang
Help you, Help me