Skip to content

Commit 323b285

Browse files
Kefeng Wangopsiff
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]> (cherry picked from commit b62b51d)
1 parent 8116253 commit 323b285

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
@@ -1703,7 +1703,7 @@ static int scan_movable_pages(unsigned long start, unsigned long end,
17031703
static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
17041704
{
17051705
unsigned long pfn;
1706-
struct page *page, *head;
1706+
struct page *page;
17071707
LIST_HEAD(source);
17081708
static DEFINE_RATELIMIT_STATE(migrate_rs, DEFAULT_RATELIMIT_INTERVAL,
17091709
DEFAULT_RATELIMIT_BURST);
@@ -1716,14 +1716,20 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
17161716
continue;
17171717
page = pfn_to_page(pfn);
17181718
folio = page_folio(page);
1719-
head = &folio->page;
17201719

1721-
if (PageHuge(page)) {
1722-
pfn = page_to_pfn(head) + compound_nr(head) - 1;
1723-
isolate_hugetlb(folio, &source);
1724-
continue;
1725-
} else if (PageTransHuge(page))
1726-
pfn = page_to_pfn(head) + thp_nr_pages(page) - 1;
1720+
/*
1721+
* No reference or lock is held on the folio, so it might
1722+
* be modified concurrently (e.g. split). As such,
1723+
* folio_nr_pages() may read garbage. This is fine as the outer
1724+
* loop will revisit the split folio later.
1725+
*/
1726+
if (folio_test_large(folio)) {
1727+
pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1;
1728+
if (folio_test_hugetlb(folio)) {
1729+
isolate_hugetlb(folio, &source);
1730+
continue;
1731+
}
1732+
}
17271733

17281734
/*
17291735
* HWPoison pages have elevated reference counts so the migration would

0 commit comments

Comments
 (0)