[PATCH v2 3/5] hugetlb: only set HPageMigratable for migratable hstates
From: Mike Kravetz <hidden>
Date: 2021-01-20 02:05:58
Also in:
lkml
Subsystem:
filesystems (vfs and infrastructure), hugetlb subsystem, memory management, memory management - memory policy and migration, the rest · Maintainers:
Alexander Viro, Christian Brauner, Muchun Song, Oscar Salvador, Andrew Morton, David Hildenbrand, Linus Torvalds
The HP_Migratable flag indicates a page is a candidate for migration. Only set the flag if the page's hstate supports migration. This allows the migration paths to detect non-migratable pages earlier. If migration is not supported for the hstate, HP_Migratable will not be set, the page will not be isolated and no attempt will be made to migrate. We should never get to unmap_and_move_huge_page for a page where migration is not supported, so throw a warning if we do. Signed-off-by: Mike Kravetz <redacted> --- fs/hugetlbfs/inode.c | 2 +- include/linux/hugetlb.h | 9 +++++++++ mm/hugetlb.c | 8 ++++---- mm/migrate.c | 9 ++++----- 4 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index ec9f03aa2738..8b8acdafd0be 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c@@ -735,7 +735,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, mutex_unlock(&hugetlb_fault_mutex_table[hash]); - SetHPageMigratable(page); + SetHPageMigratableIfSupported(page); /* * unlock_page because locked by add_to_page_cache() * put_page() due to reference from alloc_huge_page()
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index ce3d03da0133..1e17529c8b81 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h@@ -744,6 +744,15 @@ static inline bool hugepage_migration_supported(struct hstate *h) return arch_hugetlb_migration_supported(h); } +/* + * Only set HPageMigratable if migration supported for page + */ +static inline void SetHPageMigratableIfSupported(struct page *page) +{ + if (hugepage_migration_supported(page_hstate(page))) + SetHPageMigratable(page); +} + /* * Movability check is different as compared to migration check. * It determines whether or not a huge page should be placed on
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index c24da40626d3..6e32751489e8 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c@@ -4196,7 +4196,7 @@ static vm_fault_t hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma, make_huge_pte(vma, new_page, 1)); page_remove_rmap(old_page, true); hugepage_add_new_anon_rmap(new_page, vma, haddr); - SetHPageMigratable(new_page); + SetHPageMigratableIfSupported(new_page); /* Make the old page be freed below */ new_page = old_page; }
@@ -4438,7 +4438,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, * been isolated for migration. */ if (new_page) - SetHPageMigratable(page); + SetHPageMigratableIfSupported(page); unlock_page(page); out:
@@ -4749,7 +4749,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, update_mmu_cache(dst_vma, dst_addr, dst_pte); spin_unlock(ptl); - SetHPageMigratable(page); + SetHPageMigratableIfSupported(page); if (vm_shared) unlock_page(page); ret = 0;
@@ -5584,7 +5584,7 @@ void putback_active_hugepage(struct page *page) { VM_BUG_ON_PAGE(!PageHead(page), page); spin_lock(&hugetlb_lock); - SetHPageMigratable(page); + SetHPageMigratableIfSupported(page); list_move_tail(&page->lru, &(page_hstate(page))->hugepage_activelist); spin_unlock(&hugetlb_lock); put_page(page);
diff --git a/mm/migrate.c b/mm/migrate.c
index 0339f3874d7c..943391cd1a7c 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c@@ -1273,13 +1273,12 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, struct address_space *mapping = NULL; /* - * Migratability of hugepages depends on architectures and their size. - * This check is necessary because some callers of hugepage migration - * like soft offline and memory hotremove don't walk through page - * tables or check whether the hugepage is pmd-based or not before - * kicking migration. + * Support for migration should be checked at isolation time. + * Therefore, we should never get here if migration is not supported + * for the page. */ if (!hugepage_migration_supported(page_hstate(hpage))) { + VM_WARN_ON(1); list_move_tail(&hpage->lru, ret); return -ENOSYS; }
--
2.29.2