Skip to content

Commit 026885d

Browse files
author
Rafael Aquini
committed
mm: migrate_device: convert to migrate_device_coherent_folio()
JIRA: https://issues.redhat.com/browse/RHEL-84184 JIRA: https://issues.redhat.com/browse/RHEL-83249 This patch is a backport of the following upstream commit: commit 5c8525a Author: Kefeng Wang <wangkefeng.wang@huawei.com> Date: Mon Aug 26 14:58:09 2024 +0800 mm: migrate_device: convert to migrate_device_coherent_folio() Patch series "mm: finish isolate/putback_lru_page()". Convert to use more folios in migrate_device.c, then we could remove isolate_lru_page() and putback_lru_page(). This patch (of 6): Save a few calls to compound_head() and use folio throughout. Link: https://lkml.kernel.org/r/20240826065814.1336616-1-wangkefeng.wang@huawei.com Link: https://lkml.kernel.org/r/20240826065814.1336616-2-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Acked-by: David Hildenbrand <david@redhat.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: 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> Signed-off-by: Rafael Aquini <raquini@redhat.com>
1 parent f2b7303 commit 026885d

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,7 @@ static int migrate_longterm_unpinnable_pages(
20442044
folio_get(folio);
20452045
gup_put_folio(folio, 1, FOLL_PIN);
20462046

2047-
if (migrate_device_coherent_page(&folio->page)) {
2047+
if (migrate_device_coherent_folio(folio)) {
20482048
ret = -EBUSY;
20492049
goto err;
20502050
}

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ int numa_migrate_prep(struct folio *folio, struct vm_area_struct *vma,
10061006
int __must_check try_grab_folio(struct folio *folio, int refs,
10071007
unsigned int flags);
10081008
void free_zone_device_page(struct page *page);
1009-
int migrate_device_coherent_page(struct page *page);
1009+
int migrate_device_coherent_folio(struct folio *folio);
10101010

10111011
/*
10121012
* mm/huge_memory.c

mm/migrate_device.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static void __migrate_device_pages(unsigned long *src_pfns,
703703

704704
/*
705705
* The only time there is no vma is when called from
706-
* migrate_device_coherent_page(). However this isn't
706+
* migrate_device_coherent_folio(). However this isn't
707707
* called if the page could not be unmapped.
708708
*/
709709
VM_BUG_ON(!migrate);
@@ -918,38 +918,38 @@ int migrate_device_range(unsigned long *src_pfns, unsigned long start,
918918
EXPORT_SYMBOL(migrate_device_range);
919919

920920
/*
921-
* Migrate a device coherent page back to normal memory. The caller should have
922-
* a reference on page which will be copied to the new page if migration is
921+
* Migrate a device coherent folio back to normal memory. The caller should have
922+
* a reference on folio which will be copied to the new folio if migration is
923923
* successful or dropped on failure.
924924
*/
925-
int migrate_device_coherent_page(struct page *page)
925+
int migrate_device_coherent_folio(struct folio *folio)
926926
{
927927
unsigned long src_pfn, dst_pfn = 0;
928-
struct page *dpage;
928+
struct folio *dfolio;
929929

930-
WARN_ON_ONCE(PageCompound(page));
930+
WARN_ON_ONCE(folio_test_large(folio));
931931

932-
lock_page(page);
933-
src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE;
932+
folio_lock(folio);
933+
src_pfn = migrate_pfn(folio_pfn(folio)) | MIGRATE_PFN_MIGRATE;
934934

935935
/*
936936
* We don't have a VMA and don't need to walk the page tables to find
937-
* the source page. So call migrate_vma_unmap() directly to unmap the
938-
* page as migrate_vma_setup() will fail if args.vma == NULL.
937+
* the source folio. So call migrate_vma_unmap() directly to unmap the
938+
* folio as migrate_vma_setup() will fail if args.vma == NULL.
939939
*/
940940
migrate_device_unmap(&src_pfn, 1, NULL);
941941
if (!(src_pfn & MIGRATE_PFN_MIGRATE))
942942
return -EBUSY;
943943

944-
dpage = alloc_page(GFP_USER | __GFP_NOWARN);
945-
if (dpage) {
946-
lock_page(dpage);
947-
dst_pfn = migrate_pfn(page_to_pfn(dpage));
944+
dfolio = folio_alloc(GFP_USER | __GFP_NOWARN, 0);
945+
if (dfolio) {
946+
folio_lock(dfolio);
947+
dst_pfn = migrate_pfn(folio_pfn(dfolio));
948948
}
949949

950950
migrate_device_pages(&src_pfn, &dst_pfn, 1);
951951
if (src_pfn & MIGRATE_PFN_MIGRATE)
952-
copy_highpage(dpage, page);
952+
folio_copy(dfolio, folio);
953953
migrate_device_finalize(&src_pfn, &dst_pfn, 1);
954954

955955
if (src_pfn & MIGRATE_PFN_MIGRATE)

0 commit comments

Comments
 (0)