Skip to content

Commit 773b9a6

Browse files
Ma Wupengakpm00
authored andcommitted
mm: memory-hotplug: check folio ref count first in do_migrate_range
If a folio has an increased reference count, folio_try_get() will acquire it, perform necessary operations, and then release it. In the case of a poisoned folio without an elevated reference count (which is unlikely for memory-failure), folio_try_get() will simply bypass it. Therefore, relocate the folio_try_get() function, responsible for checking and acquiring this reference count at first. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ma Wupeng <[email protected]> Acked-by: David Hildenbrand <[email protected]> Acked-by: Miaohe Lin <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b81679b commit 773b9a6

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

mm/memory_hotplug.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,27 +1822,21 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
18221822
if (folio_test_large(folio))
18231823
pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1;
18241824

1825-
/*
1826-
* HWPoison pages have elevated reference counts so the migration would
1827-
* fail on them. It also doesn't make any sense to migrate them in the
1828-
* first place. Still try to unmap such a page in case it is still mapped
1829-
* (keep the unmap as the catch all safety net).
1830-
*/
1825+
if (!folio_try_get(folio))
1826+
continue;
1827+
1828+
if (unlikely(page_folio(page) != folio))
1829+
goto put_folio;
1830+
18311831
if (folio_test_hwpoison(folio) ||
18321832
(folio_test_large(folio) && folio_test_has_hwpoisoned(folio))) {
18331833
if (WARN_ON(folio_test_lru(folio)))
18341834
folio_isolate_lru(folio);
18351835
if (folio_mapped(folio))
18361836
unmap_poisoned_folio(folio, pfn, false);
18371837

1838-
continue;
1839-
}
1840-
1841-
if (!folio_try_get(folio))
1842-
continue;
1843-
1844-
if (unlikely(page_folio(page) != folio))
18451838
goto put_folio;
1839+
}
18461840

18471841
if (!isolate_folio_to_list(folio, &source)) {
18481842
if (__ratelimit(&migrate_rs)) {

0 commit comments

Comments
 (0)