mm/migrate: support un-addressable ZONE_DEVICE page in migration
Subsystems (3)
[email protected]
maintainerPATCH 26/126 mm/migrate: support un-addressable ZONE_DEVICE page in migration
From: Jérôme Glisse <[email protected]>
Subject: mm/migrate: support un-addressable ZONE_DEVICE page in migration
Allow to unmap and restore special swap entry of un-addressable ZONE_DEVICE memory.
Signed-off-by Jérôme Glisse <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Aneesh Kumar <[email protected]>
Cc Balbir Singh <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Dan Williams <[email protected]>
Cc David Nellans <[email protected]>
Cc Evgeny Baskakov <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc John Hubbard <[email protected]>
Cc Mark Hairgrove <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Paul E. McKenney <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Sherry Cheung <[email protected]>
Cc Subhash Gutti <[email protected]>
Cc Vladimir Davydov <[email protected]>
Cc Bob Liu <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
include/linux/migrate.h | 10 ++ mm/migrate.c | 149 ++++++++++++++++++++++++++++++-------- mm/page_vma_mapped.c | 10 ++ mm/rmap.c | 26 ++++++ 4 files changed, 165 insertions(+), 30 deletions(-)
include/linux/migrate.h renamed from include/linux/migrate.h~mm-migrate-support-un-addressable-zone_device-page-in-migration-v3 +8 -2
@@ -159,12 +159,18 @@ static inline int migrate_misplaced_tran#ifdef CONFIG_MIGRATION +/* +* Watch out for PAE architecture, which has an unsigned long, and might not +* have enough bits to store all physical address and flags. So far we have +* enough room for all our flags. +*/ #define MIGRATE_PFN_VALID (1UL << 0)#define MIGRATE_PFN_MIGRATE (1UL << 1)#define MIGRATE_PFN_LOCKED (1UL << 2)#define MIGRATE_PFN_WRITE (1UL << 3) -#define MIGRATE_PFN_ERROR (1UL << 4) -#define MIGRATE_PFN_SHIFT 5 +#define MIGRATE_PFN_DEVICE (1UL << 4) +#define MIGRATE_PFN_ERROR (1UL << 5) +#define MIGRATE_PFN_SHIFT 6static inline struct page *migrate_pfn_to_page (unsigned long mpfn) {
mm/migrate.c renamed from mm/migrate.c~mm-migrate-support-un-addressable-zone_device-page-in-migration-v3 +121 -28
237 lines not on this page · raw message
mm/page_vma_mapped.c renamed from mm/page_vma_mapped.c~mm-migrate-support-un-addressable-zone_device-page-in-migration-v3 +10 -0
@@ -48,6 +48,7 @@ static bool check_pte(struct page_vma_maif (!is_swap_pte (*pvmw->pte))return false; entry =pte_to_swp_entry (*pvmw->pte); +if (!is_migration_entry (entry))return false; if (migration_entry_to_page(entry) - pvmw->page >=
@@ -60,6 +61,15 @@ static bool check_pte(struct page_vma_maWARN_ON_ONCE (1 );#endif }else { +if (is_swap_pte (*pvmw->pte)) { +swp_entry_t entry; + + entry =pte_to_swp_entry (*pvmw->pte); +if (is_device_private_entry (entry) && +device_private_entry_to_page (entry) == pvmw->page) +return true; + } +if (!pte_present (*pvmw->pte))return false;
mm/rmap.c renamed from mm/rmap.c~mm-migrate-support-un-addressable-zone_device-page-in-migration-v3 +26 -0
@@ -63,6 +63,7 @@#include <linux/hugetlb.h> #include <linux/backing-dev.h> #include <linux/page_idle.h> +#include <linux/memremap.h> #include <asm/tlbflush.h>
@@ -1346,6 +1347,10 @@ static bool try_to_unmap_one(struct pageif ((flags &TTU_MUNLOCK ) && !(vma->vm_flags &VM_LOCKED ))return true; +if (IS_ENABLED (CONFIG_MIGRATION ) && (flags &TTU_MIGRATION ) && +is_zone_device_page (page) && !is_device_private_page (page)) +return true; +if (flags &TTU_SPLIT_HUGE_PMD ) {split_huge_pmd_address (vma, address, flags &TTU_SPLIT_FREEZE , page);
@@ -1403,6 +1408,27 @@ static bool try_to_unmap_one(struct page address = pvmw.address; +if (IS_ENABLED (CONFIG_MIGRATION ) && + (flags &TTU_MIGRATION ) && +is_zone_device_page (page)) { +swp_entry_t entry; +pte_t swp_pte; + + pteval =ptep_get_and_clear (mm, pvmw.address, pvmw.pte); + +/* +* Store the pfn of the page in a special migration +* pte. do_swap_page() will wait until the migration +* pte is removed and then restart fault handling. +*/ + entry =make_migration_entry (page,0 ); + swp_pte =swp_entry_to_pte (entry); +if (pte_soft_dirty (pteval)) + swp_pte =pte_swp_mksoft_dirty (swp_pte); +set_pte_at (mm, pvmw.address, pvmw.pte, swp_pte); + goto discard; + } +if (!(flags &TTU_IGNORE_ACCESS )) {if (ptep_clear_flush_young_notify (vma, address, pvmw.pte)) {
_