Skip to content

Commit f52d627

Browse files
committed
mm: memory-hotplug: check folio ref count first in do_migrate_range
commit 773b9a6 Author: Ma Wupeng <[email protected]> Date: Mon Feb 17 09:43:28 2025 +0800 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]> JIRA: https://issues.redhat.com/browse/RHEL-77742 Signed-off-by: Nico Pache <[email protected]>
1 parent 5e417d4 commit f52d627

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
@@ -1795,27 +1795,21 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
17951795
if (folio_test_large(folio))
17961796
pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1;
17971797

1798-
/*
1799-
* HWPoison pages have elevated reference counts so the migration would
1800-
* fail on them. It also doesn't make any sense to migrate them in the
1801-
* first place. Still try to unmap such a page in case it is still mapped
1802-
* (keep the unmap as the catch all safety net).
1803-
*/
1798+
if (!folio_try_get(folio))
1799+
continue;
1800+
1801+
if (unlikely(page_folio(page) != folio))
1802+
goto put_folio;
1803+
18041804
if (folio_test_hwpoison(folio) ||
18051805
(folio_test_large(folio) && folio_test_has_hwpoisoned(folio))) {
18061806
if (WARN_ON(folio_test_lru(folio)))
18071807
folio_isolate_lru(folio);
18081808
if (folio_mapped(folio))
18091809
unmap_poisoned_folio(folio, pfn, false);
18101810

1811-
continue;
1812-
}
1813-
1814-
if (!folio_try_get(folio))
1815-
continue;
1816-
1817-
if (unlikely(page_folio(page) != folio))
18181811
goto put_folio;
1812+
}
18191813

18201814
if (!isolate_folio_to_list(folio, &source)) {
18211815
if (__ratelimit(&migrate_rs)) {

0 commit comments

Comments
 (0)