* [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync()
@ 2025-05-13 8:05 Huacai Chen
2025-05-13 8:07 ` kernel test robot
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Huacai Chen @ 2025-05-13 8:05 UTC (permalink / raw)
To: Greg Kroah-Hartman, Sasha Levin, Huacai Chen
Cc: Xuerui Wang, stable, Andrew Morton, linux-mm, loongarch, Zi Yan,
Huang Ying, Baolin Wang, David Hildenbrand, Matthew Wilcox,
Huacai Chen
From: Zi Yan <ziy@nvidia.com>
nr_failed was missing the large folio splits from migrate_pages_batch()
and can cause a mismatch between migrate_pages() return value and the
number of not migrated pages, i.e., when the return value of
migrate_pages() is 0, there are still pages left in the from page list.
It will happen when a non-PMD THP large folio fails to migrate due to
-ENOMEM and is split successfully but not all the split pages are not
migrated, migrate_pages_batch() would return non-zero, but
astats.nr_thp_split = 0. nr_failed would be 0 and returned to the caller
of migrate_pages(), but the not migrated pages are left in the from page
list without being added back to LRU lists.
Fix it by adding a new nr_split counter for large folio splits and adding
it to nr_failed in migrate_page_sync() after migrate_pages_batch() is
done.
Link: https://lkml.kernel.org/r/20231017163129.2025214-1-zi.yan@sent.com
Fixes: 2ef7dbb26990 ("migrate_pages: try migrate in batch asynchronously firstly")
Signed-off-by: Zi Yan <ziy@nvidia.com>
Acked-by: Huang Ying <ying.huang@intel.com>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
This patch has a Fixes tag and should be backported to 6.6, I don't know
why hasn't bakported.
mm/migrate.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 1004b1def1c2..4ed470885217 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1504,6 +1504,7 @@ struct migrate_pages_stats {
int nr_thp_succeeded; /* THP migrated successfully */
int nr_thp_failed; /* THP failed to be migrated */
int nr_thp_split; /* THP split before migrating */
+ int nr_split; /* Large folio (include THP) split before migrating */
};
/*
@@ -1623,6 +1624,7 @@ static int migrate_pages_batch(struct list_head *from,
int nr_retry_pages = 0;
int pass = 0;
bool is_thp = false;
+ bool is_large = false;
struct folio *folio, *folio2, *dst = NULL, *dst2;
int rc, rc_saved = 0, nr_pages;
LIST_HEAD(unmap_folios);
@@ -1638,7 +1640,8 @@ static int migrate_pages_batch(struct list_head *from,
nr_retry_pages = 0;
list_for_each_entry_safe(folio, folio2, from, lru) {
- is_thp = folio_test_large(folio) && folio_test_pmd_mappable(folio);
+ is_large = folio_test_large(folio);
+ is_thp = is_large && folio_test_pmd_mappable(folio);
nr_pages = folio_nr_pages(folio);
cond_resched();
@@ -1658,6 +1661,7 @@ static int migrate_pages_batch(struct list_head *from,
stats->nr_thp_failed++;
if (!try_split_folio(folio, split_folios)) {
stats->nr_thp_split++;
+ stats->nr_split++;
continue;
}
stats->nr_failed_pages += nr_pages;
@@ -1686,11 +1690,12 @@ static int migrate_pages_batch(struct list_head *from,
nr_failed++;
stats->nr_thp_failed += is_thp;
/* Large folio NUMA faulting doesn't split to retry. */
- if (folio_test_large(folio) && !nosplit) {
+ if (is_large && !nosplit) {
int ret = try_split_folio(folio, split_folios);
if (!ret) {
stats->nr_thp_split += is_thp;
+ stats->nr_split += is_large;
break;
} else if (reason == MR_LONGTERM_PIN &&
ret == -EAGAIN) {
@@ -1836,6 +1841,7 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio,
stats->nr_succeeded += astats.nr_succeeded;
stats->nr_thp_succeeded += astats.nr_thp_succeeded;
stats->nr_thp_split += astats.nr_thp_split;
+ stats->nr_split += astats.nr_split;
if (rc < 0) {
stats->nr_failed_pages += astats.nr_failed_pages;
stats->nr_thp_failed += astats.nr_thp_failed;
@@ -1843,7 +1849,11 @@ static int migrate_pages_sync(struct list_head *from, new_folio_t get_new_folio,
return rc;
}
stats->nr_thp_failed += astats.nr_thp_split;
- nr_failed += astats.nr_thp_split;
+ /*
+ * Do not count rc, as pages will be retried below.
+ * Count nr_split only, since it includes nr_thp_split.
+ */
+ nr_failed += astats.nr_split;
/*
* Fall back to migrate all failed folios one by one synchronously. All
* failed folios except split THPs will be retried, so their failure
--
2.47.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync()
2025-05-13 8:05 [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync() Huacai Chen
@ 2025-05-13 8:07 ` kernel test robot
2025-05-13 8:11 ` Greg Kroah-Hartman
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-05-13 8:07 UTC (permalink / raw)
To: Huacai Chen; +Cc: stable, oe-kbuild-all
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-3
Rule: The upstream commit ID must be specified with a separate line above the commit text.
Subject: [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync()
Link: https://lore.kernel.org/stable/20250513080521.252543-1-chenhuacai%40loongson.cn
Please ignore this mail if the patch is not relevant for upstream.
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync()
2025-05-13 8:05 [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync() Huacai Chen
2025-05-13 8:07 ` kernel test robot
@ 2025-05-13 8:11 ` Greg Kroah-Hartman
2025-05-13 8:12 ` Greg Kroah-Hartman
2025-05-13 18:49 ` Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2025-05-13 8:11 UTC (permalink / raw)
To: Huacai Chen
Cc: Sasha Levin, Huacai Chen, Xuerui Wang, stable, Andrew Morton,
linux-mm, loongarch, Zi Yan, Huang Ying, Baolin Wang,
David Hildenbrand, Matthew Wilcox
On Tue, May 13, 2025 at 04:05:21PM +0800, Huacai Chen wrote:
> From: Zi Yan <ziy@nvidia.com>
>
> nr_failed was missing the large folio splits from migrate_pages_batch()
> and can cause a mismatch between migrate_pages() return value and the
> number of not migrated pages, i.e., when the return value of
> migrate_pages() is 0, there are still pages left in the from page list.
> It will happen when a non-PMD THP large folio fails to migrate due to
> -ENOMEM and is split successfully but not all the split pages are not
> migrated, migrate_pages_batch() would return non-zero, but
> astats.nr_thp_split = 0. nr_failed would be 0 and returned to the caller
> of migrate_pages(), but the not migrated pages are left in the from page
> list without being added back to LRU lists.
>
> Fix it by adding a new nr_split counter for large folio splits and adding
> it to nr_failed in migrate_page_sync() after migrate_pages_batch() is
> done.
>
> Link: https://lkml.kernel.org/r/20231017163129.2025214-1-zi.yan@sent.com
> Fixes: 2ef7dbb26990 ("migrate_pages: try migrate in batch asynchronously firstly")
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Acked-by: Huang Ying <ying.huang@intel.com>
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> This patch has a Fixes tag and should be backported to 6.6, I don't know
> why hasn't bakported.
Because "Fixes:" never means that it will be backported. Please read
the stable documentation for what needs to be added to ensure that.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync()
2025-05-13 8:05 [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync() Huacai Chen
2025-05-13 8:07 ` kernel test robot
2025-05-13 8:11 ` Greg Kroah-Hartman
@ 2025-05-13 8:12 ` Greg Kroah-Hartman
2025-05-13 18:49 ` Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2025-05-13 8:12 UTC (permalink / raw)
To: Huacai Chen
Cc: Sasha Levin, Huacai Chen, Xuerui Wang, stable, Andrew Morton,
linux-mm, loongarch, Zi Yan, Huang Ying, Baolin Wang,
David Hildenbrand, Matthew Wilcox
On Tue, May 13, 2025 at 04:05:21PM +0800, Huacai Chen wrote:
> From: Zi Yan <ziy@nvidia.com>
>
> nr_failed was missing the large folio splits from migrate_pages_batch()
> and can cause a mismatch between migrate_pages() return value and the
> number of not migrated pages, i.e., when the return value of
> migrate_pages() is 0, there are still pages left in the from page list.
> It will happen when a non-PMD THP large folio fails to migrate due to
> -ENOMEM and is split successfully but not all the split pages are not
> migrated, migrate_pages_batch() would return non-zero, but
> astats.nr_thp_split = 0. nr_failed would be 0 and returned to the caller
> of migrate_pages(), but the not migrated pages are left in the from page
> list without being added back to LRU lists.
>
> Fix it by adding a new nr_split counter for large folio splits and adding
> it to nr_failed in migrate_page_sync() after migrate_pages_batch() is
> done.
>
> Link: https://lkml.kernel.org/r/20231017163129.2025214-1-zi.yan@sent.com
> Fixes: 2ef7dbb26990 ("migrate_pages: try migrate in batch asynchronously firstly")
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Acked-by: Huang Ying <ying.huang@intel.com>
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> This patch has a Fixes tag and should be backported to 6.6, I don't know
> why hasn't bakported.
>
What is the upstream git id for this commit?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync()
2025-05-13 8:05 [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync() Huacai Chen
` (2 preceding siblings ...)
2025-05-13 8:12 ` Greg Kroah-Hartman
@ 2025-05-13 18:49 ` Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2025-05-13 18:49 UTC (permalink / raw)
To: stable, chenhuacai; +Cc: Sasha Levin
[ Sasha's backport helper bot ]
Hi,
Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it
Found matching upstream commit: a259945efe6ada94087ef666e9b38f8e34ea34ba
WARNING: Author mismatch between patch and found commit:
Backport author: Huacai Chen<chenhuacai@loongson.cn>
Commit author: Zi Yan<ziy@nvidia.com>
Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
Note: The patch differs from the upstream commit:
---
1: a259945efe6ad ! 1: 90d3b4a4b9916 mm/migrate: correct nr_failed in migrate_pages_sync()
@@ Commit message
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+ Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
## mm/migrate.c ##
@@ mm/migrate.c: struct migrate_pages_stats {
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.6.y | Success | Success |
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-13 18:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-13 8:05 [PATCH for 6.6] mm/migrate: correct nr_failed in migrate_pages_sync() Huacai Chen
2025-05-13 8:07 ` kernel test robot
2025-05-13 8:11 ` Greg Kroah-Hartman
2025-05-13 8:12 ` Greg Kroah-Hartman
2025-05-13 18:49 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox