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)) {
                        /*