Skip to content

Commit d64cfcc

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: migrate: use a folio in add_page_for_migration()
Use a folio in add_page_for_migration() to save compound_head() calls. Link: https://lkml.kernel.org/r/20230913095131.2426871-7-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: Zi Yan <ziy@nvidia.com> Cc: David Hildenbrand <david@redhat.com> Cc: "Huang, Ying" <ying.huang@intel.com> Cc: Hugh Dickins <hughd@google.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Mike Kravetz <mike.kravetz@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 7e2a5e5 commit d64cfcc

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

mm/migrate.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,7 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p,
20602060
struct vm_area_struct *vma;
20612061
unsigned long addr;
20622062
struct page *page;
2063+
struct folio *folio;
20632064
int err;
20642065
bool isolated;
20652066

@@ -2082,45 +2083,42 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p,
20822083
if (!page)
20832084
goto out;
20842085

2085-
if (is_zone_device_page(page))
2086-
goto out_putpage;
2086+
folio = page_folio(page);
2087+
if (folio_is_zone_device(folio))
2088+
goto out_putfolio;
20872089

20882090
err = 0;
2089-
if (page_to_nid(page) == node)
2090-
goto out_putpage;
2091+
if (folio_nid(folio) == node)
2092+
goto out_putfolio;
20912093

20922094
err = -EACCES;
20932095
if (page_mapcount(page) > 1 && !migrate_all)
2094-
goto out_putpage;
2096+
goto out_putfolio;
20952097

2096-
if (PageHuge(page)) {
2098+
if (folio_test_hugetlb(folio)) {
20972099
if (PageHead(page)) {
2098-
isolated = isolate_hugetlb(page_folio(page), pagelist);
2100+
isolated = isolate_hugetlb(folio, pagelist);
20992101
err = isolated ? 1 : -EBUSY;
21002102
}
21012103
} else {
2102-
struct page *head;
2103-
2104-
head = compound_head(page);
2105-
isolated = isolate_lru_page(head);
2104+
isolated = folio_isolate_lru(folio);
21062105
if (!isolated) {
21072106
err = -EBUSY;
2108-
goto out_putpage;
2107+
goto out_putfolio;
21092108
}
21102109

21112110
err = 1;
2112-
list_add_tail(&head->lru, pagelist);
2113-
mod_node_page_state(page_pgdat(head),
2114-
NR_ISOLATED_ANON + page_is_file_lru(head),
2115-
thp_nr_pages(head));
2111+
list_add_tail(&folio->lru, pagelist);
2112+
node_stat_mod_folio(folio,
2113+
NR_ISOLATED_ANON + folio_is_file_lru(folio),
2114+
folio_nr_pages(folio));
21162115
}
2117-
out_putpage:
2116+
out_putfolio:
21182117
/*
2119-
* Either remove the duplicate refcount from
2120-
* isolate_lru_page() or drop the page ref if it was
2121-
* not isolated.
2118+
* Either remove the duplicate refcount from folio_isolate_lru()
2119+
* or drop the folio ref if it was not isolated.
21222120
*/
2123-
put_page(page);
2121+
folio_put(folio);
21242122
out:
21252123
mmap_read_unlock(mm);
21262124
return err;

0 commit comments

Comments
 (0)