Skip to content

Commit 7ce82f4

Browse files
MiaoheLinakpm00
authored andcommitted
mm/migration: return errno when isolate_huge_page failed
We might fail to isolate huge page due to e.g. the page is under migration which cleared HPageMigratable. We should return errno in this case rather than always return 1 which could confuse the user, i.e. the caller might think all of the memory is migrated while the hugetlb page is left behind. We make the prototype of isolate_huge_page consistent with isolate_lru_page as suggested by Huang Ying and rename isolate_huge_page to isolate_hugetlb as suggested by Muchun to improve the readability. Link: https://lkml.kernel.org/r/20220530113016.16663-4-linmiaohe@huawei.com Fixes: e8db67e ("mm: migrate: move_pages() supports thp migration") Signed-off-by: Miaohe Lin <linmiaohe@huawei.com> Suggested-by: Huang Ying <ying.huang@intel.com> Reported-by: kernel test robot <lkp@intel.com> (build error) Cc: Alistair Popple <apopple@nvidia.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Christoph Lameter <cl@linux.com> Cc: David Hildenbrand <david@redhat.com> Cc: David Howells <dhowells@redhat.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Muchun Song <songmuchun@bytedance.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Peter Xu <peterx@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 160088b commit 7ce82f4

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

include/linux/hugetlb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
170170
vm_flags_t vm_flags);
171171
long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
172172
long freed);
173-
bool isolate_huge_page(struct page *page, struct list_head *list);
173+
int isolate_hugetlb(struct page *page, struct list_head *list);
174174
int get_hwpoison_huge_page(struct page *page, bool *hugetlb);
175175
int get_huge_page_for_hwpoison(unsigned long pfn, int flags);
176176
void putback_active_hugepage(struct page *page);
@@ -376,9 +376,9 @@ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
376376
return NULL;
377377
}
378378

379-
static inline bool isolate_huge_page(struct page *page, struct list_head *list)
379+
static inline int isolate_hugetlb(struct page *page, struct list_head *list)
380380
{
381-
return false;
381+
return -EBUSY;
382382
}
383383

384384
static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb)

mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
19301930
* Try to move out any movable page before pinning the range.
19311931
*/
19321932
if (folio_test_hugetlb(folio)) {
1933-
if (!isolate_huge_page(&folio->page,
1933+
if (isolate_hugetlb(&folio->page,
19341934
&movable_page_list))
19351935
isolation_error_count++;
19361936
continue;

mm/hugetlb.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,8 +2766,7 @@ static int alloc_and_dissolve_huge_page(struct hstate *h, struct page *old_page,
27662766
* Fail with -EBUSY if not possible.
27672767
*/
27682768
spin_unlock_irq(&hugetlb_lock);
2769-
if (!isolate_huge_page(old_page, list))
2770-
ret = -EBUSY;
2769+
ret = isolate_hugetlb(old_page, list);
27712770
spin_lock_irq(&hugetlb_lock);
27722771
goto free_new;
27732772
} else if (!HPageFreed(old_page)) {
@@ -2843,7 +2842,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list)
28432842
if (hstate_is_gigantic(h))
28442843
return -ENOMEM;
28452844

2846-
if (page_count(head) && isolate_huge_page(head, list))
2845+
if (page_count(head) && !isolate_hugetlb(head, list))
28472846
ret = 0;
28482847
else if (!page_count(head))
28492848
ret = alloc_and_dissolve_huge_page(h, head, list);
@@ -6960,15 +6959,15 @@ follow_huge_pgd(struct mm_struct *mm, unsigned long address, pgd_t *pgd, int fla
69606959
return pte_page(*(pte_t *)pgd) + ((address & ~PGDIR_MASK) >> PAGE_SHIFT);
69616960
}
69626961

6963-
bool isolate_huge_page(struct page *page, struct list_head *list)
6962+
int isolate_hugetlb(struct page *page, struct list_head *list)
69646963
{
6965-
bool ret = true;
6964+
int ret = 0;
69666965

69676966
spin_lock_irq(&hugetlb_lock);
69686967
if (!PageHeadHuge(page) ||
69696968
!HPageMigratable(page) ||
69706969
!get_page_unless_zero(page)) {
6971-
ret = false;
6970+
ret = -EBUSY;
69726971
goto unlock;
69736972
}
69746973
ClearHPageMigratable(page);

mm/memory-failure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)
21782178
bool lru = PageLRU(page);
21792179

21802180
if (PageHuge(page)) {
2181-
isolated = isolate_huge_page(page, pagelist);
2181+
isolated = !isolate_hugetlb(page, pagelist);
21822182
} else {
21832183
if (lru)
21842184
isolated = !isolate_lru_page(page);

mm/memory_hotplug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
16411641

16421642
if (PageHuge(page)) {
16431643
pfn = page_to_pfn(head) + compound_nr(head) - 1;
1644-
isolate_huge_page(head, &source);
1644+
isolate_hugetlb(head, &source);
16451645
continue;
16461646
} else if (PageTransHuge(page))
16471647
pfn = page_to_pfn(head) + thp_nr_pages(page) - 1;

mm/mempolicy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ static int queue_pages_hugetlb(pte_t *pte, unsigned long hmask,
602602
/* With MPOL_MF_MOVE, we migrate only unshared hugepage. */
603603
if (flags & (MPOL_MF_MOVE_ALL) ||
604604
(flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) {
605-
if (!isolate_huge_page(page, qp->pagelist) &&
605+
if (isolate_hugetlb(page, qp->pagelist) &&
606606
(flags & MPOL_MF_STRICT))
607607
/*
608608
* Failed to isolate page but allow migrating pages

mm/migrate.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void putback_movable_page(struct page *page)
133133
*
134134
* This function shall be used whenever the isolated pageset has been
135135
* built from lru, balloon, hugetlbfs page. See isolate_migratepages_range()
136-
* and isolate_huge_page().
136+
* and isolate_hugetlb().
137137
*/
138138
void putback_movable_pages(struct list_head *l)
139139
{
@@ -1628,8 +1628,9 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
16281628

16291629
if (PageHuge(page)) {
16301630
if (PageHead(page)) {
1631-
isolate_huge_page(page, pagelist);
1632-
err = 1;
1631+
err = isolate_hugetlb(page, pagelist);
1632+
if (!err)
1633+
err = 1;
16331634
}
16341635
} else {
16351636
struct page *head;

0 commit comments

Comments
 (0)