The patch titled Subject: mm/migration: return errno when isolate_huge_page failed has been added to the -mm tree. Its filename is mm-migration-return-errno-when-isolate_huge_page-failed.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/mm-migration-return-errno-when-isolate_huge_page-failed.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/mm-migration-return-errno-when-isolate_huge_page-failed.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Miaohe Lin <linmiaohe@xxxxxxxxxx> Subject: 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. So we should return -EBUSY in this case rather than always return 1 which could confuse the user. Also we make the prototype of isolate_huge_page consistent with isolate_lru_page to improve the readability. Link: https://lkml.kernel.org/r/20220425132723.34824-4-linmiaohe@xxxxxxxxxx Fixes: e8db67eb0ded ("mm: migrate: move_pages() supports thp migration") Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx> Suggested-by: Huang Ying <ying.huang@xxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: David Howells <dhowells@xxxxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: Muchun Song <songmuchun@xxxxxxxxxxxxx> Cc: Naoya Horiguchi <naoya.horiguchi@xxxxxxx> Cc: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/hugetlb.h | 6 +++--- mm/gup.c | 2 +- mm/hugetlb.c | 11 +++++------ mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 5 +++-- 6 files changed, 14 insertions(+), 14 deletions(-) --- a/include/linux/hugetlb.h~mm-migration-return-errno-when-isolate_huge_page-failed +++ a/include/linux/hugetlb.h @@ -170,7 +170,7 @@ bool hugetlb_reserve_pages(struct inode vm_flags_t vm_flags); long hugetlb_unreserve_pages(struct inode *inode, long start, long end, long freed); -bool isolate_huge_page(struct page *page, struct list_head *list); +int isolate_huge_page(struct page *page, struct list_head *list); int get_hwpoison_huge_page(struct page *page, bool *hugetlb); int get_huge_page_for_hwpoison(unsigned long pfn, int flags); void putback_active_hugepage(struct page *page); @@ -376,9 +376,9 @@ static inline pte_t *huge_pte_offset(str return NULL; } -static inline bool isolate_huge_page(struct page *page, struct list_head *list) +static inline int isolate_huge_page(struct page *page, struct list_head *list) { - return false; + return -EBUSY; } static inline int get_hwpoison_huge_page(struct page *page, bool *hugetlb) --- a/mm/gup.c~mm-migration-return-errno-when-isolate_huge_page-failed +++ a/mm/gup.c @@ -1869,7 +1869,7 @@ static long check_and_migrate_movable_pa * Try to move out any movable page before pinning the range. */ if (folio_test_hugetlb(folio)) { - if (!isolate_huge_page(&folio->page, + if (isolate_huge_page(&folio->page, &movable_page_list)) isolation_error_count++; continue; --- a/mm/hugetlb.c~mm-migration-return-errno-when-isolate_huge_page-failed +++ a/mm/hugetlb.c @@ -2765,8 +2765,7 @@ retry: * Fail with -EBUSY if not possible. */ spin_unlock_irq(&hugetlb_lock); - if (!isolate_huge_page(old_page, list)) - ret = -EBUSY; + ret = isolate_huge_page(old_page, list); spin_lock_irq(&hugetlb_lock); goto free_new; } else if (!HPageFreed(old_page)) { @@ -2842,7 +2841,7 @@ int isolate_or_dissolve_huge_page(struct if (hstate_is_gigantic(h)) return -ENOMEM; - if (page_count(head) && isolate_huge_page(head, list)) + if (page_count(head) && !isolate_huge_page(head, list)) ret = 0; else if (!page_count(head)) ret = alloc_and_dissolve_huge_page(h, head, list); @@ -6932,15 +6931,15 @@ follow_huge_pgd(struct mm_struct *mm, un return pte_page(*(pte_t *)pgd) + ((address & ~PGDIR_MASK) >> PAGE_SHIFT); } -bool isolate_huge_page(struct page *page, struct list_head *list) +int isolate_huge_page(struct page *page, struct list_head *list) { - bool ret = true; + int ret = 0; spin_lock_irq(&hugetlb_lock); if (!PageHeadHuge(page) || !HPageMigratable(page) || !get_page_unless_zero(page)) { - ret = false; + ret = -EBUSY; goto unlock; } ClearHPageMigratable(page); --- a/mm/memory-failure.c~mm-migration-return-errno-when-isolate_huge_page-failed +++ a/mm/memory-failure.c @@ -2203,7 +2203,7 @@ static bool isolate_page(struct page *pa bool lru = PageLRU(page); if (PageHuge(page)) { - isolated = isolate_huge_page(page, pagelist); + isolated = !isolate_huge_page(page, pagelist); } else { if (lru) isolated = !isolate_lru_page(page); --- a/mm/mempolicy.c~mm-migration-return-errno-when-isolate_huge_page-failed +++ a/mm/mempolicy.c @@ -602,7 +602,7 @@ static int queue_pages_hugetlb(pte_t *pt /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */ if (flags & (MPOL_MF_MOVE_ALL) || (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) { - if (!isolate_huge_page(page, qp->pagelist) && + if (isolate_huge_page(page, qp->pagelist) && (flags & MPOL_MF_STRICT)) /* * Failed to isolate page but allow migrating pages --- a/mm/migrate.c~mm-migration-return-errno-when-isolate_huge_page-failed +++ a/mm/migrate.c @@ -1628,8 +1628,9 @@ static int add_page_for_migration(struct if (PageHuge(page)) { if (PageHead(page)) { - isolate_huge_page(page, pagelist); - err = 1; + err = isolate_huge_page(page, pagelist); + if (!err) + err = 1; } } else { struct page *head; _ Patches currently in -mm which might be from linmiaohe@xxxxxxxxxx are mm-shmem-make-shmem_init-return-void.patch mm-memcg-remove-unneeded-nr_scanned.patch mm-mmapc-use-helper-mlock_future_check.patch mm-mremap-use-helper-mlock_future_check.patch mm-mremap-avoid-unneeded-do_munmap-call.patch mm-memory-failurec-minor-cleanup-for-hwpoisonhandlable.patch mm-memory-failurec-dissolve-truncated-hugetlb-page.patch mm-vmscan-remove-obsolete-comment-in-get_scan_count.patch mm-vmscan-fix-comment-for-current_may_throttle.patch mm-vmscan-fix-comment-for-isolate_lru_pages.patch mm-z3fold-declare-z3fold_mount-with-__init.patch mm-z3fold-remove-obsolete-comment-in-z3fold_alloc.patch mm-z3fold-minor-clean-up-for-z3fold_free.patch mm-z3fold-remove-unneeded-page_mapcount_reset-and-clearpageprivate.patch mm-z3fold-remove-confusing-local-variable-l-reassignment.patch mm-z3fold-move-decrement-of-pool-pages_nr-into-__release_z3fold_page.patch mm-z3fold-remove-redundant-list_del_init-of-zhdr-buddy-in-z3fold_free.patch mm-z3fold-remove-unneeded-page_headless-check-in-free_handle.patch mm-compaction-use-helper-isolation_suitable.patch drivers-base-nodec-fix-compaction-sysfs-file-leak.patch mm-mempolicy-clean-up-the-code-logic-in-queue_pages_pte_range.patch mm-migration-remove-unneeded-local-variable-mapping_locked.patch mm-migration-remove-unneeded-local-variable-page_lru.patch mm-migration-use-helper-function-vma_lookup-in-add_page_for_migration.patch mm-migration-use-helper-macro-min-in-do_pages_stat.patch mm-migration-avoid-unneeded-nodemask_t-initialization.patch mm-migration-remove-some-duplicated-codes-in-migrate_pages.patch mm-migration-fix-potential-page-refcounts-leak-in-migrate_pages.patch mm-migration-fix-potential-invalid-node-access-for-reclaim-based-migration.patch mm-migration-fix-possible-do_pages_stat_array-racing-with-memory-offline.patch mm-madvise-fix-potential-pte_unmap_unlock-pte-error.patch mm-madvise-free-hwpoison-and-swapin-error-entry-in-madvise_free_pte_range.patch mm-compaction-remove-unneeded-return-value-of-kcompactd_run.patch mm-compaction-remove-unneeded-pfn-update.patch mm-compaction-remove-unneeded-assignment-to-isolate_start_pfn.patch mm-compaction-clean-up-comment-for-sched-contention.patch mm-compaction-clean-up-comment-about-suitable-migration-target-recheck.patch mm-compaction-use-compact_cluster_max-in-compactionc.patch mm-compaction-use-helper-compound_nr-in-isolate_migratepages_block.patch mm-compaction-clean-up-comment-about-async-compaction-in-isolate_migratepages.patch mm-compaction-avoid-possible-null-pointer-dereference-in-kcompactd_cpu_online.patch mm-compaction-make-compaction_zonelist_suitable-return-false-when-compact_success.patch mm-compaction-simplify-the-code-in-__compact_finished.patch mm-compaction-make-sure-highest-is-above-the-min_pfn.patch mm-swapfile-unuse_pte-can-map-random-data-if-swap-read-fails.patch mm-swapfile-fix-lost-swap-bits-in-unuse_pte.patch mm-migration-reduce-the-rcu-lock-duration.patch mm-migration-remove-unneeded-lock-page-and-pagemovable-check.patch mm-migration-return-errno-when-isolate_huge_page-failed.patch mm-migration-fix-potential-pte_unmap-on-an-not-mapped-pte.patch