From nobody Wed Feb 5 20:43:05 2025 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24EC823F28F for ; Wed, 15 Jan 2025 10:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.125.252.92 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736937263; cv=none; b=Omu/CtlCZOr9e4LQcwFw9/7kunqMkDbiXqhVHEa2OrKOh3ydav+4M+84d9TLixisUWHbiIMbuNs+U94Gj9BzmBKbFBw9LG3CDHASl6g2Od90LEo8ENXskqNgwfSHzlh2qKQ82npmrxUD+6v7iMYwxAr/1ETdi5KvniNSzs8WNqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736937263; c=relaxed/simple; bh=9kDDwNDSmC6AJlHVGr/RnlWuIK9RJoldWKtTV41GIVY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=ZgK6Nq6TU0/kHot6m+YymhAlpL3Mk++mmu0qv2TToJgT3qFCQsVEhVy84cyzhIRTRMENgsGEItUC0pE7Hk4wEFLHspKWi2n3vBgtLfgozl/9mWIxZu397qwqsQQxP79Co99oEJvxXVdXc1TzXI7pPK+1kaoY3atEGowTZOFS5p8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com; spf=pass smtp.mailfrom=sk.com; arc=none smtp.client-ip=166.125.252.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sk.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sk.com X-AuditID: a67dfc5b-3c9ff7000001d7ae-1c-67878f262393 From: Byungchul Park To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: kernel_team@skhynix.com, akpm@linux-foundation.org, ziy@nvidia.com, shivankg@amd.com Subject: [PATCH v2] mm: separate move/undo parts from migrate_pages_batch() Date: Wed, 15 Jan 2025 19:34:03 +0900 Message-Id: <20250115103403.11882-1-byungchul@sk.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250115095343.46390-1-byungchul@sk.com> References: <20250115095343.46390-1-byungchul@sk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmluLIzCtJLcpLzFFi42LhesuzUFetvz3d4OUGHos569ewWVzeNYfN 4t6a/6wW59Z8ZreYffQeuwOrR+ulv2wemz5NYvc4MeM3i0dv8zs2j8+b5AJYo7hsUlJzMstS i/TtErgyFs//xFZwWq/i+oOTTA2MG1W7GDk5JARMJPbM+s0GY3+fsIgFxGYTUJe4ceMnM4gt ImAmcbD1D3sXIzsHs0CcRHMhSFRYwFti8oPDjCA2i4CqxKvdp8A6eQVMJZYf/McEMVFeYvWG A2BTOIGmXDk0lx3EFgKq6Xl2jgWi5imrxIa7nBC2pMTBFTdYJjDyLmBkWMUolJlXlpuYmWOi l1GZl1mhl5yfu4kRGDTLav9E72D8dCH4EKMAB6MSD++F+LZ0IdbEsuLK3EOMEhzMSiK8S9ha 04V4UxIrq1KL8uOLSnNSiw8xSnOwKInzGn0rTxESSE8sSc1OTS1ILYLJMnFwSjUwGk6bavVf I/rnr1+CH1yDrVQr9u7Z52n89saHTXcsH2X9D5jquFtg3dpjbOrcB7MDV4U3ytm+sdbiTUot EZHpdLpvZ/c16ciZjyfMnqroye+wW2L256r71N8n/FkVfR8tW3ePQaR62jSB39eFVysvcg5J sJnyVPyz0hnJmZsfqVfcWd+8Z23qRCWW4oxEQy3mouJEAD6FKtMWAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNJMWRmVeSWpSXmKPExsXC5WfdrKvW355uMPsQk8Wc9WvYLA7PPclq cXnXHDaLe2v+s1qcW/OZ3WL20XvsDmwerZf+snls+jSJ3ePEjN8sHr3N79g8Fr/4wOTxeZNc AFsUl01Kak5mWWqRvl0CV8bi+Z/YCk7rVVx/cJKpgXGjahcjJ4eEgInE9wmLWEBsNgF1iRs3 fjKD2CICZhIHW/+wdzGyczALxEk0F4JEhQW8JSY/OMwIYrMIqEq82n0KrJNXwFRi+cF/TBAT 5SVWbzgANoUTaMqVQ3PZQWwhoJqeZ+dYJjByLWBkWMUokplXlpuYmWOqV5ydUZmXWaGXnJ+7 iREYBMtq/0zcwfjlsvshRgEORiUe3hMRbelCrIllxZW5hxglOJiVRHiXsLWmC/GmJFZWpRbl xxeV5qQWH2KU5mBREuf1Ck9NEBJITyxJzU5NLUgtgskycXBKNTDumvf6uvfhHpevYm+d8r7J OfqZG5prT9z6QatrWsuljJ7f4UvZIv77qRw0Eu58kpFZcpG/cXlHyxppieapv7b2RMkZHfuj oFHXHD5X4ehXw8k769vjD7iFuPq9You6bVdfqmZ7Lf+lkcPK2ZW6y1Ij70yY/HHt10hL6WUN X8/dsdTXVI8O4VJiKc5INNRiLipOBACuNPPx/gEAAA== X-CFilter-Loop: Reflected Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Changes from v1 - Fix a wrong coding style =09 Reviewed-by: Shivank Garg --->8--- From a65a6e4975962707bf87171e317f005c6276887e Mon Sep 17 00:00:00 2001 From: Byungchul Park Date: Thu, 8 Aug 2024 15:53:58 +0900 Subject: [PATCH v2] mm: separate move/undo parts from migrate_pages_batch() Functionally, no change. This is a preparation for luf mechanism that requires to use separated folio lists for its own handling during migration. Refactored migrate_pages_batch() so as to separate move/undo parts from migrate_pages_batch(). Signed-off-by: Byungchul Park Reviewed-by: Shivank Garg --- mm/migrate.c | 134 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index dfb5eba3c5223..c8f25434b9973 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1695,6 +1695,81 @@ static int migrate_hugetlbs(struct list_head *from, = new_folio_t get_new_folio, return nr_failed; } =20 +static void migrate_folios_move(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + enum migrate_mode mode, int reason, + struct list_head *ret_folios, + struct migrate_pages_stats *stats, + int *retry, int *thp_retry, int *nr_failed, + int *nr_retry_pages) +{ + struct folio *folio, *folio2, *dst, *dst2; + bool is_thp; + int nr_pages; + int rc; + + dst =3D list_first_entry(dst_folios, struct folio, lru); + dst2 =3D list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + is_thp =3D folio_test_large(folio) && folio_test_pmd_mappable(folio); + nr_pages =3D folio_nr_pages(folio); + + cond_resched(); + + rc =3D migrate_folio_move(put_new_folio, private, + folio, dst, mode, + reason, ret_folios); + /* + * The rules are: + * Success: folio will be freed + * -EAGAIN: stay on the unmap_folios list + * Other errno: put on ret_folios list + */ + switch (rc) { + case -EAGAIN: + *retry +=3D 1; + *thp_retry +=3D is_thp; + *nr_retry_pages +=3D nr_pages; + break; + case MIGRATEPAGE_SUCCESS: + stats->nr_succeeded +=3D nr_pages; + stats->nr_thp_succeeded +=3D is_thp; + break; + default: + *nr_failed +=3D 1; + stats->nr_thp_failed +=3D is_thp; + stats->nr_failed_pages +=3D nr_pages; + break; + } + dst =3D dst2; + dst2 =3D list_next_entry(dst, lru); + } +} + +static void migrate_folios_undo(struct list_head *src_folios, + struct list_head *dst_folios, + free_folio_t put_new_folio, unsigned long private, + struct list_head *ret_folios) +{ + struct folio *folio, *folio2, *dst, *dst2; + + dst =3D list_first_entry(dst_folios, struct folio, lru); + dst2 =3D list_next_entry(dst, lru); + list_for_each_entry_safe(folio, folio2, src_folios, lru) { + int old_page_state =3D 0; + struct anon_vma *anon_vma =3D NULL; + + __migrate_folio_extract(dst, &old_page_state, &anon_vma); + migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, + anon_vma, true, ret_folios); + list_del(&dst->lru); + migrate_folio_undo_dst(dst, true, put_new_folio, private); + dst =3D dst2; + dst2 =3D list_next_entry(dst, lru); + } +} + /* * migrate_pages_batch() first unmaps folios in the from list as many as * possible, then move the unmapped folios. @@ -1717,7 +1792,7 @@ static int migrate_pages_batch(struct list_head *from, int pass =3D 0; bool is_thp =3D false; bool is_large =3D false; - struct folio *folio, *folio2, *dst =3D NULL, *dst2; + struct folio *folio, *folio2, *dst =3D NULL; int rc, rc_saved =3D 0, nr_pages; LIST_HEAD(unmap_folios); LIST_HEAD(dst_folios); @@ -1888,42 +1963,11 @@ static int migrate_pages_batch(struct list_head *fr= om, thp_retry =3D 0; nr_retry_pages =3D 0; =20 - dst =3D list_first_entry(&dst_folios, struct folio, lru); - dst2 =3D list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - is_thp =3D folio_test_large(folio) && folio_test_pmd_mappable(folio); - nr_pages =3D folio_nr_pages(folio); - - cond_resched(); - - rc =3D migrate_folio_move(put_new_folio, private, - folio, dst, mode, - reason, ret_folios); - /* - * The rules are: - * Success: folio will be freed - * -EAGAIN: stay on the unmap_folios list - * Other errno: put on ret_folios list - */ - switch(rc) { - case -EAGAIN: - retry++; - thp_retry +=3D is_thp; - nr_retry_pages +=3D nr_pages; - break; - case MIGRATEPAGE_SUCCESS: - stats->nr_succeeded +=3D nr_pages; - stats->nr_thp_succeeded +=3D is_thp; - break; - default: - nr_failed++; - stats->nr_thp_failed +=3D is_thp; - stats->nr_failed_pages +=3D nr_pages; - break; - } - dst =3D dst2; - dst2 =3D list_next_entry(dst, lru); - } + /* Move the unmapped folios */ + migrate_folios_move(&unmap_folios, &dst_folios, + put_new_folio, private, mode, reason, + ret_folios, stats, &retry, &thp_retry, + &nr_failed, &nr_retry_pages); } nr_failed +=3D retry; stats->nr_thp_failed +=3D thp_retry; @@ -1932,20 +1976,8 @@ static int migrate_pages_batch(struct list_head *fro= m, rc =3D rc_saved ? : nr_failed; out: /* Cleanup remaining folios */ - dst =3D list_first_entry(&dst_folios, struct folio, lru); - dst2 =3D list_next_entry(dst, lru); - list_for_each_entry_safe(folio, folio2, &unmap_folios, lru) { - int old_page_state =3D 0; - struct anon_vma *anon_vma =3D NULL; - - __migrate_folio_extract(dst, &old_page_state, &anon_vma); - migrate_folio_undo_src(folio, old_page_state & PAGE_WAS_MAPPED, - anon_vma, true, ret_folios); - list_del(&dst->lru); - migrate_folio_undo_dst(dst, true, put_new_folio, private); - dst =3D dst2; - dst2 =3D list_next_entry(dst, lru); - } + migrate_folios_undo(&unmap_folios, &dst_folios, + put_new_folio, private, ret_folios); =20 return rc; } --=20 2.17.1