mm: migrate_device: use more folio in migrate_device_finalize()

Saves a couple of calls to compound_head() and remove last two callers of
putback_lru_page().

Link: https://lkml.kernel.org/r/20240826065814.1336616-5-wangkefeng.wang@huawei.com
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Kefeng Wang 2024-08-26 14:58:12 +08:00 committed by Andrew Morton
parent 39e618d986
commit 58bf8c2bf4

View File

@ -815,42 +815,45 @@ void migrate_device_finalize(unsigned long *src_pfns,
unsigned long i; unsigned long i;
for (i = 0; i < npages; i++) { for (i = 0; i < npages; i++) {
struct folio *dst, *src; struct folio *dst = NULL, *src = NULL;
struct page *newpage = migrate_pfn_to_page(dst_pfns[i]); struct page *newpage = migrate_pfn_to_page(dst_pfns[i]);
struct page *page = migrate_pfn_to_page(src_pfns[i]); struct page *page = migrate_pfn_to_page(src_pfns[i]);
if (newpage)
dst = page_folio(newpage);
if (!page) { if (!page) {
if (newpage) { if (dst) {
unlock_page(newpage); folio_unlock(dst);
put_page(newpage); folio_put(dst);
} }
continue; continue;
} }
if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !newpage) { src = page_folio(page);
if (newpage) {
unlock_page(newpage); if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !dst) {
put_page(newpage); if (dst) {
folio_unlock(dst);
folio_put(dst);
} }
newpage = page; dst = src;
} }
src = page_folio(page);
dst = page_folio(newpage);
remove_migration_ptes(src, dst, false); remove_migration_ptes(src, dst, false);
folio_unlock(src); folio_unlock(src);
if (is_zone_device_page(page)) if (folio_is_zone_device(src))
put_page(page); folio_put(src);
else else
putback_lru_page(page); folio_putback_lru(src);
if (newpage != page) { if (dst != src) {
unlock_page(newpage); folio_unlock(dst);
if (is_zone_device_page(newpage)) if (folio_is_zone_device(dst))
put_page(newpage); folio_put(dst);
else else
putback_lru_page(newpage); folio_putback_lru(dst);
} }
} }
} }