From: Baolin Wang baolin.wang@linux.alibaba.com
mainline inclusion from mainline-v6.12-rc1 commit dfa98f56d932fca3eaadaed8c17393fdfa00574d category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IAXCD2
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
Iterate each subpage in the large folio to copy, as preparation for supporting shmem mTHP collapse.
Link: https://lkml.kernel.org/r/222d615b7c837eabb47a238126c5fdeff8aa5283.172414060... Signed-off-by: Baolin Wang baolin.wang@linux.alibaba.com Cc: Barry Song 21cnbao@gmail.com Cc: David Hildenbrand david@redhat.com Cc: Hugh Dickins hughd@google.com Cc: Matthew Wilcox willy@infradead.org Cc: Ryan Roberts ryan.roberts@arm.com Cc: Yang Shi shy828301@gmail.com Cc: Zi Yan ziy@nvidia.com Signed-off-by: Andrew Morton akpm@linux-foundation.org Conflicts: mm/khugepaged.c [return val conflict for copy_mc_highpage, which is introduced by commit 681be0689526 ("mm/hwpoison: return -EFAULT when copy fail in copy_mc_[user]_highpage()")] Signed-off-by: Nanyong Sun sunnanyong@huawei.com --- mm/khugepaged.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b757299dfdc8..3337b79f51ae 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2070,17 +2070,22 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, index = start; dst = folio_page(new_folio, 0); list_for_each_entry(folio, &pagelist, lru) { + int i, nr_pages = folio_nr_pages(folio); + while (index < folio->index) { clear_highpage(dst); index++; dst++; } - if (copy_mc_highpage(dst, folio_page(folio, 0))) { - result = SCAN_COPY_MC; - goto rollback; + + for (i = 0; i < nr_pages; i++) { + if (copy_mc_highpage(dst, folio_page(folio, i))) { + result = SCAN_COPY_MC; + goto rollback; + } + index++; + dst++; } - index++; - dst++; } while (index < end) { clear_highpage(dst);