Skip to content

Commit b62b51d

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: memory_hotplug: remove head variable in do_migrate_range()
Patch series "mm: memory_hotplug: improve do_migrate_range()", v3. Unify hwpoisoned page handling and isolation of HugeTLB/LRU/non-LRU movable page, also convert to use folios in do_migrate_range(). This patch (of 5): Directly use a folio for HugeTLB and THP when calculate the next pfn, then remove unused head variable. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kefeng Wang <[email protected]> Reviewed-by: Miaohe Lin <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Dan Carpenter <[email protected]> Cc: Jonathan Cameron <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Oscar Salvador <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f66ac83 commit b62b51d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

mm/memory_hotplug.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ static int scan_movable_pages(unsigned long start, unsigned long end,
17731773
static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
17741774
{
17751775
unsigned long pfn;
1776-
struct page *page, *head;
1776+
struct page *page;
17771777
LIST_HEAD(source);
17781778
static DEFINE_RATELIMIT_STATE(migrate_rs, DEFAULT_RATELIMIT_INTERVAL,
17791779
DEFAULT_RATELIMIT_BURST);
@@ -1786,14 +1786,20 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
17861786
continue;
17871787
page = pfn_to_page(pfn);
17881788
folio = page_folio(page);
1789-
head = &folio->page;
17901789

1791-
if (PageHuge(page)) {
1792-
pfn = page_to_pfn(head) + compound_nr(head) - 1;
1793-
isolate_hugetlb(folio, &source);
1794-
continue;
1795-
} else if (PageTransHuge(page))
1796-
pfn = page_to_pfn(head) + thp_nr_pages(page) - 1;
1790+
/*
1791+
* No reference or lock is held on the folio, so it might
1792+
* be modified concurrently (e.g. split). As such,
1793+
* folio_nr_pages() may read garbage. This is fine as the outer
1794+
* loop will revisit the split folio later.
1795+
*/
1796+
if (folio_test_large(folio)) {
1797+
pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1;
1798+
if (folio_test_hugetlb(folio)) {
1799+
isolate_hugetlb(folio, &source);
1800+
continue;
1801+
}
1802+
}
17971803

17981804
/*
17991805
* HWPoison pages have elevated reference counts so the migration would

0 commit comments

Comments
 (0)