mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported()
Subsystems (2)
PATCH 1/1 mm/huge_memory: merge uniform_split_supported() and non_uniform_split_supported()
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 before proceeding with further validation.
This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)
include/linux/huge_mm.h +3 -5
@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);
@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }
mm/huge_memory.c +15 -40
81 lines not on this page · raw message
Signature · 1 line
2.34.1
Dev Jain
reviewerQuoted 123 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 before proceeding with further validation.This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +14
-35@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns) { -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" ); -return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true; -return true; -} - -/* See comments in non_uniform_split_supported() */ -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !mapping_large_folio_support (folio->mapping)) { +/* +* No split if the file system does not support large +* folio. Note that we might still have THPs in such +* mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in +* that case, the mapping does not actually support +* large folios properly. +*/ VM_WARN_ONCE (warns,"Cannot split file folio to non-0 order" );return false; } } -if (new_order &&folio_test_swapcache (folio)) { +/* Only swapping a whole PMD-mapped folio is supported */ +if (need_check &&folio_test_swapcache (folio)) {VM_WARN_ONCE (warns,"Cannot split swapcache folio to non-0 order" );return false;@@ -3779,11 +3758,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (new_order >= old_order)return -EINVAL ;
mm/huge_memory.c static int __folio_split(struct folio *folio, unsigned int new_order, · line 3764
Quoted 10 lines
mm/huge_memory.c +1
-5-if (uniform_split && !uniform_split_supported (folio, new_order, true)) -return -EINVAL ; - -if (!uniform_split && - !non_uniform_split_supported (folio, new_order, true)) +if (!folio_split_supported (folio, new_order, uniform_split,/* warn = */ true))return -EINVAL ; is_hzp =is_huge_zero_folio (folio);
@Zi, I am confused on the code. Is there something stopping us from passing a zero new_order to non_uniform_split_supported()?
David Hildenbrand (Red Hat)
maintainerQuoted 51 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 before proceeding with further validation.This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +0
-0
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3677
Quoted 7 lines
mm/huge_memory.c +2
-2@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns)
Likely a simple
enum split_type {
SPLIT_TYPE_UNIFORM, SPLIT_TYPE_NON_UNIFORM, // or SPLIT_TYPE_BUDDY?
};
Could make invocations easier to read.
Quoted 16 lines
mm/huge_memory.c +0
-15{ -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" );
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3679
Quoted 10 lines
mm/huge_memory.c +1
-9-return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true;
(could be const)
Not really a great name for that variable (what needs a check?). Maybe simply ...
Quoted 5 lines
mm/huge_memory.c +0
-4-return true; -} - -/* See comments in non_uniform_split_supported() */
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3686
Quoted 10 lines
mm/huge_memory.c +2
-4-bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {
... change this to ("!uniform_split || new_order")
} else if (!uniform_split || new_order) {
Zi Yan
reviewerQuoted 123 lines · Dev Jain
Quoted 122 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 before proceeding with further validation.This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +2
-4@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list); @@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order(struct folio *folio,
struct page *page, unsigned intnew_order)
{include/linux/huge_mm.h +1
-1-if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +14
-34@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported(struct folio *folio, unsigned int new_order, - bool warns) +bool folio_split_supported(struct folio *folio, unsigned int new_order, + bool uniform_split, bool warns) { - 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"); -return new_order !=1 ; - } else if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" ); -return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } + bool need_check = uniform_split ? new_order : true; - return true; -} - -/* See comments in non_uniform_split_supported() */ -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !mapping_large_folio_support (folio->mapping)) { +/* +* No split if the file system does not support large +* folio. Note that we might still have THPs in such +* mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in +* that case, the mapping does not actually support +* large folios properly. +*/ VM_WARN_ONCE (warns,"Cannot split file folio to non-0 order" );return false; } } - if (new_order && folio_test_swapcache(folio)) { +/* Only swapping a whole PMD-mapped folio is supported */ +if (need_check &&folio_test_swapcache (folio)) {VM_WARN_ONCE (warns,"Cannot split swapcache folio to non-0 order" );return false;@@ -3779,11 +3758,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (new_order >= old_order)return -EINVAL ; - if (uniform_split && !uniform_split_supported(folio, new_order, true)) - return -EINVAL; -
Quoted 8 lines
mm/huge_memory.c static int __folio_split(struct folio *folio, unsigned int new_order, · line 3764
Quoted 5 lines
mm/huge_memory.c +1
-2-if (!uniform_split && - !non_uniform_split_supported (folio, new_order, true)) +if (!folio_split_supported (folio, new_order, uniform_split,/* warn = */ true))return -EINVAL ; is_hzp =is_huge_zero_folio (folio);@Zi, I am confused on the code. Is there something stopping us from passing a zero
new_ordertonon_uniform_split_supported()?
Yes, for filesystems without large folio support and a PMD size file-backed THP is created via khugepaged (with CONFIG_READ_ONLY_THP_FOR_FS), the THP can only be split to order-0. Non uniform split would create other orders and causes issues.
Best Regards,
Yan, Zi
Zi Yan
reviewerQuoted 5 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 before
Please elaborate on what the check is for.
Quoted 93 lines
proceeding with further validation.
This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +4
-34@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns) { -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" ); -return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true; -return true; -} - -/* See comments in non_uniform_split_supported() */ -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) {
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3695
Quoted 10 lines
mm/huge_memory.c +8
-0+ }else if (need_check) {if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !mapping_large_folio_support (folio->mapping)) { +/* +* No split if the file system does not support large +* folio. Note that we might still have THPs in such +* mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in +* that case, the mapping does not actually support +* large folios properly. +*/
Blindly copying the comment here causes fusion. The checks for uniform and non uniform look similar but this comment is specific for non uniform split. The “No split” only applies to non uniform split, but for uniform split as long as order is 0, the folio can be split.
Please rewrite this comment to clarify both uniform and non uniform cases.
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3702
Quoted 8 lines
mm/huge_memory.c +1
-1VM_WARN_ONCE (warns,"Cannot split file folio to non-0 order" );return false; } } -if (new_order &&folio_test_swapcache (folio)) { +/* Only swapping a whole PMD-mapped folio is supported */
The same issue like the above one. Please rewrite this comment as well.
Quoted 19 lines
mm/huge_memory.c +2
-5+if (need_check &&folio_test_swapcache (folio)) {VM_WARN_ONCE (warns,"Cannot split swapcache folio to non-0 order" );return false;@@ -3779,11 +3758,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (new_order >= old_order)return -EINVAL ; -if (uniform_split && !uniform_split_supported (folio, new_order, true)) -return -EINVAL ; - -if (!uniform_split && - !non_uniform_split_supported (folio, new_order, true)) +if (!folio_split_supported (folio, new_order, uniform_split,/* warn = */ true))return -EINVAL ; is_hzp =is_huge_zero_folio (folio);Signature · 1 line
2.34.1
Best Regards,
Yan, Zi
Quoted 11 lines · Zi Yan
Quoted 5 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 beforePlease elaborate on what the check is for.
Quoted 1 line
proceeding with further validation.
How about this:
The only functional difference is that uniform_split_supported() includes an additional check on the requested @new_order and split type to confirm support from file system or swap cache.
Quoted 100 lines
Quoted 100 lines
This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +10
-34@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns) { -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" ); -return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true; -return true; -} - -/* See comments in non_uniform_split_supported() */ -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !mapping_large_folio_support (folio->mapping)) { +/* +* No split if the file system does not support large +* folio. Note that we might still have THPs in such +* mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in +* that case, the mapping does not actually support
Quoted 9 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3695
Quoted 2 lines
mm/huge_memory.c +2
-0+* large folios properly. +*/ Blindly copying the comment here causes fusion. The checks for uniform and non uniform look similar but this comment is specific for non uniform split. The “No split” only applies to non uniform split, but for uniform split as long as order is 0, the folio can be split.
Per my understanding, "no split" applies to both uniform/non uniform split when new_order is not 0.
So the logic here is:
* uniform split && !new_order: no more check
* non uniform split: do the check regardless of the new_order
But I am lack of some background knowledge, if it is wrong, please correct me.
Quoted 2 lines
Please rewrite this comment to clarify both uniform and non uniform cases.
Not sure this one would be better?
We can always split a folio down to a single page (new_order == 0) directly.
For any other scenario
* uniform split targeting a large folio (new_order > 0)
* any non-uniform split
we must confirm that the file system supports large folios.
Note that we might still have THPs in such mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping does not actually support large folios properly.
Quoted 11 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3702
Quoted 8 lines
mm/huge_memory.c +1
-1VM_WARN_ONCE (warns,"Cannot split file folio to non-0 order" );return false; } } -if (new_order &&folio_test_swapcache (folio)) { +/* Only swapping a whole PMD-mapped folio is supported */ The same issue like the above one. Please rewrite this comment as well.
How about this one:
swapcache folio could only be split to order 0
For non-uniform split or uniform split targeting a large folio, return false.
Quoted 23 lines
Quoted 19 lines
mm/huge_memory.c +2
-5+if (need_check &&folio_test_swapcache (folio)) {VM_WARN_ONCE (warns,"Cannot split swapcache folio to non-0 order" );return false;@@ -3779,11 +3758,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (new_order >= old_order)return -EINVAL ; -if (uniform_split && !uniform_split_supported (folio, new_order, true)) -return -EINVAL ; - -if (!uniform_split && - !non_uniform_split_supported (folio, new_order, true)) +if (!folio_split_supported (folio, new_order, uniform_split,/* warn = */ true))return -EINVAL ; is_hzp =is_huge_zero_folio (folio);Signature · 1 line
2.34.1Best Regards,
Yan, Zi
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 60 lines · David Hildenbrand (Red Hat)
Quoted 50 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 before proceeding with further validation.This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +0
-0mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3676
Quoted 6 lines
mm/huge_memory.c +2
-2@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns)Likely a simple
Quoted 7 lines
enum
split_type{
SPLIT_TYPE_UNIFORM,SPLIT_TYPE_NON_UNIFORM, // orSPLIT_TYPE_BUDDY?
};Could make invocations easier to read.
Hmm... if so we may need to change the caller too.
Quoted 34 lines
Quoted 16 lines
mm/huge_memory.c +0
-15{ -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" );mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3679
Quoted 10 lines
mm/huge_memory.c +1
-9-return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true;(could be const)
Not really a great name for that variable (what needs a check?). Maybe simply ...
Quoted 17 lines
Quoted 4 lines
mm/huge_memory.c +0
-4-return true; -} - -/* See comments in non_uniform_split_supported() */ mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3686
Quoted 10 lines
mm/huge_memory.c +2
-4-bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {... change this to ("!uniform_split ||
new_order")
Looks simple, thanks.
Quoted 1 line
} else if (!uniform_split ||
new_order) {
Signature · 2 lines
Wei Yang Help you, Help me
Zi Yan
reviewerQuoted 11 lines · Wei Yang
Quoted 10 lines · Zi Yan
Quoted 5 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 beforePlease elaborate on what the check is for.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
proceeding with further validation.
How about this:
The only functional difference is that
uniform_split_supported()includes an additional check on the requested @new_order and split type to confirm support from file system or swap cache.
You are describing what the code does instead of its actual meaning. You need to describe:
1. what is the difference between uniform split and non-uniform split?
2. what order does what file systems support? Only order-0.
3. what order does swap cache support? Only order-0.
4. why can uniform split be used to split large folios from 2 or 3 to order-0?
5. why can non uniform split not be used to split large folios from 2 or 3 to order-0?
6. The logic similarity between uniform_split_supported() and non_uniform_split_supported() and they can be combined with detailed comment.
Quoted 111 lines
Quoted 101 lines
Quoted 101 lines
This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +10
-34@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns) { -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" ); -return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true; -return true; -} - -/* See comments in non_uniform_split_supported() */ -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !mapping_large_folio_support (folio->mapping)) { +/* +* No split if the file system does not support large +* folio. Note that we might still have THPs in such +* mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in +* that case, the mapping does not actually support Quoted 9 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3695
Quoted 2 lines
mm/huge_memory.c +2
-0+* large folios properly. +*/ Blindly copying the comment here causes fusion. The checks for uniform and non uniform look similar but this comment is specific for non uniform split. The “No split” only applies to non uniform split, but for uniform split as long as order is 0, the folio can be split.
Quoted 2 lines
Per my understanding, "no split" applies to both uniform/non uniform split when
new_orderis not 0.
Not exactly. For non uniform split, any new_order value is not allowed.
Quoted 7 lines
So the logic here is:
* uniform split && !new_order: no more check
* non uniform split: do the check regardless of thenew_orderBut I am lack of some background knowledge, if it is wrong, please correct me.
You are changing the code, please do your homework first. Or you can ask. After go through the above 6 bullet points, you should get the background knowledge.
Quoted 7 lines
Quoted 3 lines
Please rewrite this comment to clarify both uniform and non uniform cases.
Not sure this one would be better?
We can always split a folio down to a single page (
new_order== 0) directly.
Not always, the exceptions are listed below.
Quoted 9 lines
For any other scenario
* uniform split targeting a large folio (new_order> 0)
* any non-uniform split
we must confirm that the file system supports large folios.Note that we might still have THPs in such mappings due to
CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping does not actually support large folios properly.
These filesystems do not support large folios except THPs created from khugepaged when CONFIG_READ_ONLY_THP_FOR_FS is enabled.
Quoted 13 lines
Quoted 7 lines
Quoted 7 lines
mm/huge_memory.c +0
-0VM_WARN_ONCE (warns,"Cannot split file folio to non-0 order" );return false; } }Quoted 5 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3702
Quoted 2 lines
mm/huge_memory.c +1
-1-if (new_order &&folio_test_swapcache (folio)) { +/* Only swapping a whole PMD-mapped folio is supported */ The same issue like the above one. Please rewrite this comment as well.
Quoted 3 lines
How about this one:
swapcache folio could only be split to order 0
This looks good.
Quoted 3 lines
For non-uniform split or uniform split targeting a large folio, return false.
You are just describing the code.
non-uniform split creates after-split folios with orders from folio_order(folio) - 1 to new_order, making it not suitable for any swapcache folio split. Only uniform split to order-0 can be used here.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
mm/huge_memory.c +2
-5+if (need_check &&folio_test_swapcache (folio)) {VM_WARN_ONCE (warns,"Cannot split swapcache folio to non-0 order" );return false;@@ -3779,11 +3758,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (new_order >= old_order)return -EINVAL ; -if (uniform_split && !uniform_split_supported (folio, new_order, true)) -return -EINVAL ; - -if (!uniform_split && - !non_uniform_split_supported (folio, new_order, true)) +if (!folio_split_supported (folio, new_order, uniform_split,/* warn = */ true))return -EINVAL ;
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
mm/huge_memory.c +0
-0is_hzp =is_huge_zero_folio (folio);Signature · 1 line
2.34.1Best Regards,
Yan, ZiSignature · 2 lines
Wei Yang Help you, Help me
Best Regards,
Yan, Zi
Quoted 21 lines · Zi Yan
Quoted 11 lines · Wei Yang
Quoted 10 lines · Zi Yan
Quoted 5 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 beforePlease elaborate on what the check is for.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
proceeding with further validation.
How about this:
The only functional difference is that
uniform_split_supported()includes an additional check on the requested @new_order and split type to confirm support from file system or swap cache.
Quoted 13 lines
You are describing what the code does instead of its actual meaning. You need to describe:
1. what is the difference between uniform split and non-uniform split?
2. what order does what file systems support? Only order-0.
3. what order does swap cache support? Only order-0.
4. why can uniform split be used to split large folios from 2 or 3 to order-0?
5. why can non uniform split not be used to split large folios from 2 or 3 to order-0?
6. The logic similarity betweenuniform_split_supported()andnon_uniform_split_supported()and they can be combined with detailed comment.
Here is the updated version:
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.
Quoted 129 lines
Quoted 111 lines
Quoted 101 lines
Quoted 101 lines
This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +10
-34@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns) { -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" ); -return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true; -return true; -} - -/* See comments in non_uniform_split_supported() */ -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !mapping_large_folio_support (folio->mapping)) { +/* +* No split if the file system does not support large +* folio. Note that we might still have THPs in such +* mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in +* that case, the mapping does not actually support Quoted 9 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3695
Quoted 2 lines
mm/huge_memory.c +2
-0+* large folios properly. +*/ Blindly copying the comment here causes fusion. The checks for uniform and non uniform look similar but this comment is specific for non uniform split. The “No split” only applies to non uniform split, but for uniform split as long as order is 0, the folio can be split.
Quoted 2 lines
Per my understanding, "no split" applies to both uniform/non uniform split when
new_orderis not 0.Not exactly. For non uniform split, any
new_ordervalue is not allowed.Quoted 7 lines
So the logic here is:
* uniform split && !new_order: no more check
* non uniform split: do the check regardless of thenew_orderBut I am lack of some background knowledge, if it is wrong, please correct me.
You are changing the code, please do your homework first. Or you can ask. After go through the above 6 bullet points, you should get the background knowledge.
Quoted 1 line
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Please rewrite this comment to clarify both uniform and non uniform cases.
Not sure this one would be better?
We can always split a folio down to a single page (
new_order== 0) directly.Not always, the exceptions are listed below.
I mean uniform split to order-0, maybe above line misleading to non-uniform split?
Quoted 6 lines
Quoted 6 lines
For any other scenario
* uniform split targeting a large folio (new_order> 0)
* any non-uniform split
we must confirm that the file system supports large folios.
Quoted 6 lines
Quoted 3 lines
Note that we might still have THPs in such mappings due to
CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping does not actually support large folios properly.These filesystems do not support large folios except THPs created from khugepaged when
CONFIG_READ_ONLY_THP_FOR_FSis enabled.
Want to confirm to see whether I understand correctly.
We have two kinds of file system:
a) support large folio
b) not support large folio
For a), we can split large folio to min_order_for_split(), uniform or non-uniform.
For b), normally there is no large folio. The large folio is collapsed by khugepaged when CONFIG_READ_ONLY_THP_FOR_FS is enabled. So we can only split it to order-0 folio for this case.
Not sure this one would be better?
We can always split a folio down to a single page (new_order == 0) uniformly.
For any other scenario
* uniform split targeting a large folio (new_order > 0)
* 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.
Quoted 19 lines
Quoted 12 lines
Quoted 11 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3702
Quoted 8 lines
mm/huge_memory.c +1
-1VM_WARN_ONCE (warns,"Cannot split file folio to non-0 order" );return false; } } -if (new_order &&folio_test_swapcache (folio)) { +/* Only swapping a whole PMD-mapped folio is supported */ The same issue like the above one. Please rewrite this comment as well.
Quoted 3 lines
How about this one:
swapcache folio could only be split to order 0
This looks good.
Quoted 1 line
Quoted 9 lines
Quoted 2 lines
For non-uniform split or uniform split targeting a large folio, return false.
You are just describing the code.
non-uniform split creates after-split folios with orders from
folio_order(folio)- 1 tonew_order, making it not suitable for any swapcache folio split. Only uniform split to order-0 can be used here.
Below is the updated version:
swapcache folio could only be split to order 0
non-uniform split creates after-split folios with orders from folio_order(folio) - 1 to new_order, making it not suitable for any swapcache folio split. Only uniform split to order-0 can be used here.
Quoted 32 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
mm/huge_memory.c +2
-5+if (need_check &&folio_test_swapcache (folio)) {VM_WARN_ONCE (warns,"Cannot split swapcache folio to non-0 order" );return false;@@ -3779,11 +3758,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (new_order >= old_order)return -EINVAL ; -if (uniform_split && !uniform_split_supported (folio, new_order, true)) -return -EINVAL ; - -if (!uniform_split && - !non_uniform_split_supported (folio, new_order, true)) +if (!folio_split_supported (folio, new_order, uniform_split,/* warn = */ true))return -EINVAL ;Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
mm/huge_memory.c +0
-0is_hzp =is_huge_zero_folio (folio);Signature · 1 line
2.34.1Best Regards,
Yan, ZiSignature · 2 lines
Wei Yang Help you, Help meBest Regards,
Yan, Zi
Signature · 2 lines
Wei Yang Help you, Help me
David Hildenbrand (Red Hat)
maintainerQuoted 11 lines
Quoted 9 lines
Likely a simple
enum
split_type{
SPLIT_TYPE_UNIFORM,SPLIT_TYPE_NON_UNIFORM, // orSPLIT_TYPE_BUDDY?
};Could make invocations easier to read.
Hmm... if so we may need to change the caller too.
Probably worth a separate cleanup patch instead of doing it in this patch.
Signature · 3 lines
Cheers David
Quoted 7 lines · David Hildenbrand (Red Hat)
Quoted 7 lines
Quoted 7 lines
Likely a simple
enum
split_type{
SPLIT_TYPE_UNIFORM,SPLIT_TYPE_NON_UNIFORM, // orSPLIT_TYPE_BUDDY?
};
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Could make invocations easier to read.
Hmm... if so we may need to change the caller too.
Probably worth a separate cleanup patch instead of doing it in this patch.
Got it.
Quoted 4 lines
Signature · 3 lines
Cheers David
Signature · 2 lines
Wei Yang Help you, Help me
Zi Yan
reviewerQuoted 46 lines · Wei Yang
Quoted 21 lines · Zi Yan
Quoted 11 lines · Wei Yang
Quoted 10 lines · Zi Yan
Quoted 5 lines · Wei Yang
The functions
uniform_split_supported()andnon_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 beforePlease elaborate on what the check is for.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
proceeding with further validation.
How about this:
The only functional difference is that
uniform_split_supported()includes an additional check on the requested @new_order and split type to confirm support from file system or swap cache.Quoted 13 lines
You are describing what the code does instead of its actual meaning. You need to describe:
1. what is the difference between uniform split and non-uniform split?
2. what order does what file systems support? Only order-0.
3. what order does swap cache support? Only order-0.
4. why can uniform split be used to split large folios from 2 or 3 to order-0?
5. why can non uniform split not be used to split large folios from 2 or 3 to order-0?
6. The logic similarity betweenuniform_split_supported()andnon_uniform_split_supported()and they can be combined with detailed comment.Here is the updated version:
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
Quoted 9 lines
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 fromfolio_order(folio)- 1 tonew_order.This means for non-uniform split or !new_order split we should check the file system and swap cache respectively.
LGTM.
Quoted 134 lines
Quoted 134 lines
Quoted 111 lines
Quoted 101 lines
Quoted 101 lines
This commit unifies the logic by introducing a new variable, @need_check, which is conditionally set based on whether a uniform split is requested. This allows us to merge the two functions into a single, combined helper, removing redundant code and simplifying the split support checking mechanism.
Signed-off-by Wei Yang <[email protected]>Cc Zi Yan <[email protected]>--- include/linux/huge_mm.h | 8 +++--- mm/huge_memory.c | 55 +++++++++++------------------------------ 2 files changed, 18 insertions(+), 45 deletions(-)include/linux/huge_mm.h +3
-5@@ -369,10 +369,8 @@ int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list unsigned int new_order, bool unmapped);int min_order_for_split (struct folio *folio);int split_folio_to_list (struct folio *folio,struct list_head *list); -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns); +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns);int folio_split (struct folio *folio,unsigned int new_order,struct page *page,struct list_head *list);@@ -403,7 +401,7 @@ static inline int split_huge_page_to_order(struct page *page, unsigned int new_ostatic inline int try_folio_split_to_order (struct folio *folio,struct page *page,unsigned int new_order) { -if (!non_uniform_split_supported (folio, new_order,/* warns= */ false)) +if (!folio_split_supported (folio, new_order,/* uniform_split = */ false,/* warns= */ false))return split_huge_page_to_order (&folio->page, new_order);return folio_split (folio, new_order, page,NULL ); }mm/huge_memory.c +10
-34@@ -3673,55 +3673,34 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,return 0 ; } -bool non_uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) +bool folio_split_supported (struct folio *folio,unsigned int new_order, +bool uniform_split,bool warns) { -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" ); -return new_order !=1 ; - }else if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && - !mapping_large_folio_support (folio->mapping)) { -/* -* No split if the file system does not support large folio. -* Note that we might still have THPs in such mappings due to -* CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping -* does not actually support large folios properly. -*/ -VM_WARN_ONCE (warns, -"Cannot split file folio to non-0 order" ); -return false; - } - -/* Only swapping a whole PMD-mapped folio is supported */ -if (folio_test_swapcache (folio)) { -VM_WARN_ONCE (warns, -"Cannot split swapcache folio to non-0 order" ); -return false; - } +bool need_check = uniform_split ? new_order : true; -return true; -} - -/* See comments in non_uniform_split_supported() */ -bool uniform_split_supported (struct folio *folio,unsigned int new_order, -bool warns) -{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" );return new_order !=1 ; - }else if (new_order) { + }else if (need_check) {if (IS_ENABLED (CONFIG_READ_ONLY_THP_FOR_FS ) && !mapping_large_folio_support (folio->mapping)) { +/* +* No split if the file system does not support large +* folio. Note that we might still have THPs in such +* mappings due to CONFIG_READ_ONLY_THP_FOR_FS. But in +* that case, the mapping does not actually support Quoted 9 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3695
Quoted 2 lines
mm/huge_memory.c +2
-0+* large folios properly. +*/ Blindly copying the comment here causes fusion. The checks for uniform and non uniform look similar but this comment is specific for non uniform split. The “No split” only applies to non uniform split, but for uniform split as long as order is 0, the folio can be split.
Quoted 2 lines
Per my understanding, "no split" applies to both uniform/non uniform split when
new_orderis not 0.Not exactly. For non uniform split, any
new_ordervalue is not allowed.Quoted 7 lines
So the logic here is:
* uniform split && !new_order: no more check
* non uniform split: do the check regardless of thenew_orderBut I am lack of some background knowledge, if it is wrong, please correct me.
You are changing the code, please do your homework first. Or you can ask. After go through the above 6 bullet points, you should get the background knowledge.
Quoted 6 lines
Quoted 3 lines
Please rewrite this comment to clarify both uniform and non uniform cases.
Not sure this one would be better?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
We can always split a folio down to a single page (
new_order== 0) directly.Not always, the exceptions are listed below.
I mean uniform split to order-0, maybe above line misleading to non-uniform split?
Right. If you mean uniform split, then write uniform split instead.
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
For any other scenario
* uniform split targeting a large folio (new_order> 0)
* any non-uniform split
we must confirm that the file system supports large folios.Quoted 6 lines
Quoted 3 lines
Note that we might still have THPs in such mappings due to
CONFIG_READ_ONLY_THP_FOR_FS. But in that case, the mapping does not actually support large folios properly.These filesystems do not support large folios except THPs created from khugepaged when
CONFIG_READ_ONLY_THP_FOR_FSis enabled.Want to confirm to see whether I understand correctly.
We have two kinds of file system:
a) support large folio
b) not support large folio
Quoted 6 lines
For a), we can split large folio to
min_order_for_split(), uniform or non-uniform.For b), normally there is no large folio. The large folio is collapsed by khugepaged when
CONFIG_READ_ONLY_THP_FOR_FSis enabled. So we can only split it to order-0 folio for this case.
Exactly.
Quoted 6 lines
Not sure this one would be better?
We can always split a folio down to a single page (
new_order== 0) uniformly.
Quoted 8 lines
For any other scenario
* uniform split targeting a large folio (new_order> 0)
* 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_FSis enabled. But in that case, the mapping does not actually support large folios properly.
LGTM.
Quoted 31 lines
Quoted 21 lines
Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
mm/huge_memory.c +0
-0VM_WARN_ONCE (warns,"Cannot split file folio to non-0 order" );return false; } }Quoted 5 lines
mm/huge_memory.c static int __split_unmapped_folio(struct folio *folio, int new_order, · line 3702
Quoted 2 lines
mm/huge_memory.c +1
-1-if (new_order &&folio_test_swapcache (folio)) { +/* Only swapping a whole PMD-mapped folio is supported */ The same issue like the above one. Please rewrite this comment as well.
Quoted 3 lines
How about this one:
swapcache folio could only be split to order 0
This looks good.
Quoted 1 line
Quoted 9 lines
Quoted 2 lines
For non-uniform split or uniform split targeting a large folio, return false.
You are just describing the code.
non-uniform split creates after-split folios with orders from
folio_order(folio)- 1 tonew_order, making it not suitable for any swapcache folio split. Only uniform split to order-0 can be used here.
Quoted 7 lines
Below is the updated version:
swapcache folio could only be split to order 0
non-uniform split creates after-split folios with orders from
folio_order(folio)- 1 tonew_order, making it not suitable for any swapcache folio split. Only uniform split to order-0 can be used here.
LGTM.
Thank you for updating the comments. Looking forward to your updated patch.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 21 lines
mm/huge_memory.c +2
-5+if (need_check &&folio_test_swapcache (folio)) {VM_WARN_ONCE (warns,"Cannot split swapcache folio to non-0 order" );return false;@@ -3779,11 +3758,7 @@ static int __folio_split(struct folio *folio, unsigned int new_order,if (new_order >= old_order)return -EINVAL ; -if (uniform_split && !uniform_split_supported (folio, new_order, true)) -return -EINVAL ; - -if (!uniform_split && - !non_uniform_split_supported (folio, new_order, true)) +if (!folio_split_supported (folio, new_order, uniform_split,/* warn = */ true))return -EINVAL ; is_hzp =is_huge_zero_folio (folio);Signature · 1 line
2.34.1Best Regards,
Yan, Zi
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Signature · 2 lines
Wei Yang Help you, Help meBest Regards,
Yan, ZiSignature · 2 lines
Wei Yang Help you, Help me
Best Regards,
Yan, Zi
Quoted 1 line · Zi Yan
On 4 Nov 2025, at 2:53, Wei Yang wrote:
[...]
Quoted 23 lines
Quoted 23 lines
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
How about this one:
swapcache folio could only be split to order 0
This looks good.
Quoted 1 line
Quoted 9 lines
Quoted 2 lines
For non-uniform split or uniform split targeting a large folio, return false.
You are just describing the code.
non-uniform split creates after-split folios with orders from
folio_order(folio)- 1 tonew_order, making it not suitable for any swapcache folio split. Only uniform split to order-0 can be used here.Below is the updated version:
swapcache folio could only be split to order 0
Quoted 7 lines
Quoted 3 lines
non-uniform split creates after-split folios with orders from
folio_order(folio)- 1 tonew_order, making it not suitable for any swapcache folio split. Only uniform split to order-0 can be used here.LGTM.
Thank you for updating the comments. Looking forward to your updated patch.
Thanks for you time and patience, will prepare a new version.
Signature · 2 lines
Wei Yang Help you, Help me