From df263d9a7dffee94ca5391120ee3b0587efa07f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mika=20Penttil=C3=A4?= Date: Wed, 7 Jun 2023 20:29:44 +0300 Subject: [PATCH] mm/migrate_device: try to handle swapcache pages MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Migrating file pages and swapcache pages into device memory is not supported. Try to get rid of the swap cache, and if successful, go ahead as with other anonymous pages. Link: https://lkml.kernel.org/r/20230607172944.11713-1-mpenttil@redhat.com Signed-off-by: Mika Penttilä Reviewed-by: "Huang, Ying" Reviewed-by: Alistair Popple Cc: John Hubbard Cc: Ralph Campbell Signed-off-by: Andrew Morton --- mm/migrate_device.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 8365158460ed1..e29626e1329e9 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -727,13 +727,22 @@ static void __migrate_device_pages(unsigned long *src_pfns, if (is_device_private_page(newpage) || is_device_coherent_page(newpage)) { - /* - * For now only support anonymous memory migrating to - * device private or coherent memory. - */ if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; - continue; + struct folio *folio; + + folio = page_folio(page); + + /* + * For now only support anonymous memory migrating to + * device private or coherent memory. + * + * Try to get rid of swap cache if possible. + */ + if (!folio_test_anon(folio) || + !folio_free_swap(folio)) { + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; + continue; + } } } else if (is_zone_device_page(newpage)) { /* -- 2.30.2