diff mbox series

[3/5] mm: khugepaged: support shmem mTHP copy

Message ID 938e8cc5a15f841fdd343d324d8a6dd989cd52e0.1724054125.git.baolin.wang@linux.alibaba.com (mailing list archive)
State New
Headers show
Series support shmem mTHP collapse | expand

Commit Message

Baolin Wang Aug. 19, 2024, 8:14 a.m. UTC
Iterate each subpage in the large folio to copy, as preparation for supporting
shmem mTHP collapse.

Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
 mm/khugepaged.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 60d95f08610c..91ee672db202 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2060,17 +2060,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)) > 0) {
-			result = SCAN_COPY_MC;
-			goto rollback;
+
+		for (i = 0; i < nr_pages; i++) {
+			if (copy_mc_highpage(dst, folio_page(folio, i)) > 0) {
+				result = SCAN_COPY_MC;
+				goto rollback;
+			}
+			index++;
+			dst++;
 		}
-		index++;
-		dst++;
 	}
 	while (index < end) {
 		clear_highpage(dst);