mm/huge_memory: move writeback and truncation checks early
Subsystems (2)
PATCH 1/1 mm/huge_memory: move writeback and truncation checks early
We should check as early as possible if we should bail due to writeback or truncation. This will allow us to add further sanity checks earlier as well.
This introduces no functional changes.
--- mm/huge_memory.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
While working on min order support for LBS this came up as an improvement as we can check for the min order early earlier, so this sets the stage up for that.
mm/huge_memory.c +11 -12
@@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,if (new_order >=folio_order (folio))return -EINVAL ; -/* Cannot split anonymous THP to order-1 */ -if (new_order ==1 &&folio_test_anon (folio)) { +if (folio_test_writeback (folio)) +return -EBUSY ; + +if (!folio_test_anon (folio)) { +/* Truncated ? */ +if (!folio->mapping) { + ret = -EBUSY ; + goto out; + } + }else if (new_order ==1 ) { +/* Cannot split anonymous THP to order-1 */ VM_WARN_ONCE (1 ,"Cannot split to order-1 folio" );return -EINVAL ; }
@@ -3079,16 +3088,12 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, } } - is_hzp =is_huge_zero_page (&folio->page);if (is_hzp) {pr_warn_ratelimited ("Called split_huge_page for huge zero page\n" );return -EBUSY ; } -if (folio_test_writeback (folio)) -return -EBUSY ; -if (folio_test_anon (folio)) {/* * The caller does not necessarily hold an mmap_lock that would
@@ -3111,12 +3116,6 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, mapping = folio->mapping; -/* Truncated ? */ -if (!mapping) { - ret = -EBUSY ; - goto out; - } -/* * Do not split if mapping has minimum folio order * requirement.
Signature · 1 line
2.43.0
Zi Yan
reviewerQuoted 71 lines · Luis Chamberlain
We should check as early as possible if we should bail due to writeback or truncation. This will allow us to add further sanity checks earlier as well.
This introduces no functional changes.
Signed-off-by Luis Chamberlain <[email protected]>--- mm/huge_memory.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)While working on min order support for LBS this came up as an improvement as we can check for the min order early earlier, so this sets the stage up for that.
mm/huge_memory.c +11
-12@@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,if (new_order >=folio_order (folio))return -EINVAL ; -/* Cannot split anonymous THP to order-1 */ -if (new_order ==1 &&folio_test_anon (folio)) { +if (folio_test_writeback (folio)) +return -EBUSY ; + +if (!folio_test_anon (folio)) { +/* Truncated ? */ +if (!folio->mapping) { + ret = -EBUSY ; + goto out; + } + }else if (new_order ==1 ) { +/* Cannot split anonymous THP to order-1 */ VM_WARN_ONCE (1 ,"Cannot split to order-1 folio" );return -EINVAL ; }@@ -3079,16 +3088,12 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, } } - is_hzp =is_huge_zero_page (&folio->page);if (is_hzp) {pr_warn_ratelimited ("Called split_huge_page for huge zero page\n" );return -EBUSY ; } -if (folio_test_writeback (folio)) -return -EBUSY ; -if (folio_test_anon (folio)) {/* * The caller does not necessarily hold an mmap_lock that would @@ -3111,12 +3116,6 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, mapping = folio->mapping; -/* Truncated ? */ -if (!mapping) { - ret = -EBUSY ; - goto out; - } -/* * Do not split if mapping has minimum folio order * requirement. Signature · 1 line
2.43.0
LGTM. Reviewed-by: Zi Yan <[email protected]>
--
Best Regards,
Yan, Zi
Quoted 20 lines · Luis Chamberlain
We should check as early as possible if we should bail due to writeback or truncation. This will allow us to add further sanity checks earlier as well.
This introduces no functional changes.
Signed-off-by Luis Chamberlain <[email protected]>--- mm/huge_memory.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)While working on min order support for LBS this came up as an improvement as we can check for the min order early earlier, so this sets the stage up for that.
mm/huge_memory.c +0
-0
mm/huge_memory.c int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, · line 3060
Quoted 8 lines
mm/huge_memory.c +3
-2@@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,if (new_order >=folio_order (folio))return -EINVAL ; -/* Cannot split anonymous THP to order-1 */ -if (new_order ==1 &&folio_test_anon (folio)) { +if (folio_test_writeback (folio)) +return -EBUSY ; +
Why earlier than basic input parameter checks (new_order?
Sorry, but I don't see the reason for that change. It's all happening extremely early, what are we concerned about?
It's likely better to send that patch with the actual patch "to add further sanity checks earlier as well", and why they have to be that early.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 31 lines · David Hildenbrand
Quoted 20 lines · Luis Chamberlain
We should check as early as possible if we should bail due to writeback or truncation. This will allow us to add further sanity checks earlier as well.
This introduces no functional changes.
Signed-off-by Luis Chamberlain <[email protected]>--- mm/huge_memory.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)While working on min order support for LBS this came up as an improvement as we can check for the min order early earlier, so this sets the stage up for that.
mm/huge_memory.c +0
-0mm/huge_memory.c int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, · line 3059
Quoted 7 lines
mm/huge_memory.c +3
-2@@ -3055,8 +3055,17 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,if (new_order >=folio_order (folio))return -EINVAL ; -/* Cannot split anonymous THP to order-1 */ -if (new_order ==1 &&folio_test_anon (folio)) { +if (folio_test_writeback (folio)) +return -EBUSY ; +Why earlier than basic input parameter checks (
new_order?
Quoted 5 lines
Sorry, but I don't see the reason for that change. It's all happening extremely early, what are we concerned about?
It's likely better to send that patch with the actual patch "to add further sanity checks earlier as well", and why they have to be that early.
It's a clear eye-sore when we add min order, I'll leave the eyesores for others. It can wait.
Luis