mm/rmap: Convert try_to_unmap() to take a folio
Change all three callers and the worker function try_to_unmap_one(). Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
This commit is contained in:
parent
af28a988b3
commit
869f7ee6f6
@ -194,7 +194,7 @@ int folio_referenced(struct folio *, int is_locked,
|
|||||||
struct mem_cgroup *memcg, unsigned long *vm_flags);
|
struct mem_cgroup *memcg, unsigned long *vm_flags);
|
||||||
|
|
||||||
void try_to_migrate(struct page *page, enum ttu_flags flags);
|
void try_to_migrate(struct page *page, enum ttu_flags flags);
|
||||||
void try_to_unmap(struct page *, enum ttu_flags flags);
|
void try_to_unmap(struct folio *, enum ttu_flags flags);
|
||||||
|
|
||||||
int make_device_exclusive_range(struct mm_struct *mm, unsigned long start,
|
int make_device_exclusive_range(struct mm_struct *mm, unsigned long start,
|
||||||
unsigned long end, struct page **pages,
|
unsigned long end, struct page **pages,
|
||||||
@ -309,7 +309,7 @@ static inline int folio_referenced(struct folio *folio, int is_locked,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void try_to_unmap(struct page *page, enum ttu_flags flags)
|
static inline void try_to_unmap(struct folio *folio, enum ttu_flags flags)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2251,6 +2251,7 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma,
|
|||||||
|
|
||||||
static void unmap_page(struct page *page)
|
static void unmap_page(struct page *page)
|
||||||
{
|
{
|
||||||
|
struct folio *folio = page_folio(page);
|
||||||
enum ttu_flags ttu_flags = TTU_RMAP_LOCKED | TTU_SPLIT_HUGE_PMD |
|
enum ttu_flags ttu_flags = TTU_RMAP_LOCKED | TTU_SPLIT_HUGE_PMD |
|
||||||
TTU_SYNC;
|
TTU_SYNC;
|
||||||
|
|
||||||
@ -2264,7 +2265,7 @@ static void unmap_page(struct page *page)
|
|||||||
if (PageAnon(page))
|
if (PageAnon(page))
|
||||||
try_to_migrate(page, ttu_flags);
|
try_to_migrate(page, ttu_flags);
|
||||||
else
|
else
|
||||||
try_to_unmap(page, ttu_flags | TTU_IGNORE_MLOCK);
|
try_to_unmap(folio, ttu_flags | TTU_IGNORE_MLOCK);
|
||||||
|
|
||||||
VM_WARN_ON_ONCE_PAGE(page_mapped(page), page);
|
VM_WARN_ON_ONCE_PAGE(page_mapped(page), page);
|
||||||
}
|
}
|
||||||
|
@ -1834,7 +1834,8 @@ static void collapse_file(struct mm_struct *mm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (page_mapped(page))
|
if (page_mapped(page))
|
||||||
try_to_unmap(page, TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH);
|
try_to_unmap(page_folio(page),
|
||||||
|
TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH);
|
||||||
|
|
||||||
xas_lock_irq(&xas);
|
xas_lock_irq(&xas);
|
||||||
xas_set(&xas, index);
|
xas_set(&xas, index);
|
||||||
|
@ -1347,6 +1347,7 @@ static int get_hwpoison_page(struct page *p, unsigned long flags)
|
|||||||
static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
|
static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
|
||||||
int flags, struct page *hpage)
|
int flags, struct page *hpage)
|
||||||
{
|
{
|
||||||
|
struct folio *folio = page_folio(hpage);
|
||||||
enum ttu_flags ttu = TTU_IGNORE_MLOCK | TTU_SYNC;
|
enum ttu_flags ttu = TTU_IGNORE_MLOCK | TTU_SYNC;
|
||||||
struct address_space *mapping;
|
struct address_space *mapping;
|
||||||
LIST_HEAD(tokill);
|
LIST_HEAD(tokill);
|
||||||
@ -1412,7 +1413,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
|
|||||||
collect_procs(hpage, &tokill, flags & MF_ACTION_REQUIRED);
|
collect_procs(hpage, &tokill, flags & MF_ACTION_REQUIRED);
|
||||||
|
|
||||||
if (!PageHuge(hpage)) {
|
if (!PageHuge(hpage)) {
|
||||||
try_to_unmap(hpage, ttu);
|
try_to_unmap(folio, ttu);
|
||||||
} else {
|
} else {
|
||||||
if (!PageAnon(hpage)) {
|
if (!PageAnon(hpage)) {
|
||||||
/*
|
/*
|
||||||
@ -1424,12 +1425,12 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn,
|
|||||||
*/
|
*/
|
||||||
mapping = hugetlb_page_mapping_lock_write(hpage);
|
mapping = hugetlb_page_mapping_lock_write(hpage);
|
||||||
if (mapping) {
|
if (mapping) {
|
||||||
try_to_unmap(hpage, ttu|TTU_RMAP_LOCKED);
|
try_to_unmap(folio, ttu|TTU_RMAP_LOCKED);
|
||||||
i_mmap_unlock_write(mapping);
|
i_mmap_unlock_write(mapping);
|
||||||
} else
|
} else
|
||||||
pr_info("Memory failure: %#lx: could not lock mapping for mapped huge page\n", pfn);
|
pr_info("Memory failure: %#lx: could not lock mapping for mapped huge page\n", pfn);
|
||||||
} else {
|
} else {
|
||||||
try_to_unmap(hpage, ttu);
|
try_to_unmap(folio, ttu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1690,10 +1690,13 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
|
|||||||
DEFAULT_RATELIMIT_BURST);
|
DEFAULT_RATELIMIT_BURST);
|
||||||
|
|
||||||
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
|
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
|
||||||
|
struct folio *folio;
|
||||||
|
|
||||||
if (!pfn_valid(pfn))
|
if (!pfn_valid(pfn))
|
||||||
continue;
|
continue;
|
||||||
page = pfn_to_page(pfn);
|
page = pfn_to_page(pfn);
|
||||||
head = compound_head(page);
|
folio = page_folio(page);
|
||||||
|
head = &folio->page;
|
||||||
|
|
||||||
if (PageHuge(page)) {
|
if (PageHuge(page)) {
|
||||||
pfn = page_to_pfn(head) + compound_nr(head) - 1;
|
pfn = page_to_pfn(head) + compound_nr(head) - 1;
|
||||||
@ -1710,10 +1713,10 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
|
|||||||
* the unmap as the catch all safety net).
|
* the unmap as the catch all safety net).
|
||||||
*/
|
*/
|
||||||
if (PageHWPoison(page)) {
|
if (PageHWPoison(page)) {
|
||||||
if (WARN_ON(PageLRU(page)))
|
if (WARN_ON(folio_test_lru(folio)))
|
||||||
isolate_lru_page(page);
|
folio_isolate_lru(folio);
|
||||||
if (page_mapped(page))
|
if (folio_mapped(folio))
|
||||||
try_to_unmap(page, TTU_IGNORE_MLOCK);
|
try_to_unmap(folio, TTU_IGNORE_MLOCK);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
83
mm/rmap.c
83
mm/rmap.c
@ -1412,7 +1412,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
{
|
{
|
||||||
struct folio *folio = page_folio(page);
|
struct folio *folio = page_folio(page);
|
||||||
struct mm_struct *mm = vma->vm_mm;
|
struct mm_struct *mm = vma->vm_mm;
|
||||||
DEFINE_PAGE_VMA_WALK(pvmw, page, vma, address, 0);
|
DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0);
|
||||||
pte_t pteval;
|
pte_t pteval;
|
||||||
struct page *subpage;
|
struct page *subpage;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
@ -1436,13 +1436,13 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
* For hugetlb, it could be much worse if we need to do pud
|
* For hugetlb, it could be much worse if we need to do pud
|
||||||
* invalidation in the case of pmd sharing.
|
* invalidation in the case of pmd sharing.
|
||||||
*
|
*
|
||||||
* Note that the page can not be free in this function as call of
|
* Note that the folio can not be freed in this function as call of
|
||||||
* try_to_unmap() must hold a reference on the page.
|
* try_to_unmap() must hold a reference on the folio.
|
||||||
*/
|
*/
|
||||||
range.end = vma_address_end(&pvmw);
|
range.end = vma_address_end(&pvmw);
|
||||||
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm,
|
mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm,
|
||||||
address, range.end);
|
address, range.end);
|
||||||
if (PageHuge(page)) {
|
if (folio_test_hugetlb(folio)) {
|
||||||
/*
|
/*
|
||||||
* If sharing is possible, start and end will be adjusted
|
* If sharing is possible, start and end will be adjusted
|
||||||
* accordingly.
|
* accordingly.
|
||||||
@ -1454,24 +1454,25 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
|
|
||||||
while (page_vma_mapped_walk(&pvmw)) {
|
while (page_vma_mapped_walk(&pvmw)) {
|
||||||
/* Unexpected PMD-mapped THP? */
|
/* Unexpected PMD-mapped THP? */
|
||||||
VM_BUG_ON_PAGE(!pvmw.pte, page);
|
VM_BUG_ON_FOLIO(!pvmw.pte, folio);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the page is in an mlock()d vma, we must not swap it out.
|
* If the folio is in an mlock()d vma, we must not swap it out.
|
||||||
*/
|
*/
|
||||||
if (!(flags & TTU_IGNORE_MLOCK) &&
|
if (!(flags & TTU_IGNORE_MLOCK) &&
|
||||||
(vma->vm_flags & VM_LOCKED)) {
|
(vma->vm_flags & VM_LOCKED)) {
|
||||||
/* Restore the mlock which got missed */
|
/* Restore the mlock which got missed */
|
||||||
mlock_vma_page(page, vma, false);
|
mlock_vma_folio(folio, vma, false);
|
||||||
page_vma_mapped_walk_done(&pvmw);
|
page_vma_mapped_walk_done(&pvmw);
|
||||||
ret = false;
|
ret = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
subpage = page - page_to_pfn(page) + pte_pfn(*pvmw.pte);
|
subpage = folio_page(folio,
|
||||||
|
pte_pfn(*pvmw.pte) - folio_pfn(folio));
|
||||||
address = pvmw.address;
|
address = pvmw.address;
|
||||||
|
|
||||||
if (PageHuge(page) && !PageAnon(page)) {
|
if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) {
|
||||||
/*
|
/*
|
||||||
* To call huge_pmd_unshare, i_mmap_rwsem must be
|
* To call huge_pmd_unshare, i_mmap_rwsem must be
|
||||||
* held in write mode. Caller needs to explicitly
|
* held in write mode. Caller needs to explicitly
|
||||||
@ -1510,7 +1511,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
if (should_defer_flush(mm, flags)) {
|
if (should_defer_flush(mm, flags)) {
|
||||||
/*
|
/*
|
||||||
* We clear the PTE but do not flush so potentially
|
* We clear the PTE but do not flush so potentially
|
||||||
* a remote CPU could still be writing to the page.
|
* a remote CPU could still be writing to the folio.
|
||||||
* If the entry was previously clean then the
|
* If the entry was previously clean then the
|
||||||
* architecture must guarantee that a clear->dirty
|
* architecture must guarantee that a clear->dirty
|
||||||
* transition on a cached TLB entry is written through
|
* transition on a cached TLB entry is written through
|
||||||
@ -1523,22 +1524,22 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
pteval = ptep_clear_flush(vma, address, pvmw.pte);
|
pteval = ptep_clear_flush(vma, address, pvmw.pte);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the dirty bit to the page. Now the pte is gone. */
|
/* Set the dirty flag on the folio now the pte is gone. */
|
||||||
if (pte_dirty(pteval))
|
if (pte_dirty(pteval))
|
||||||
set_page_dirty(page);
|
folio_mark_dirty(folio);
|
||||||
|
|
||||||
/* Update high watermark before we lower rss */
|
/* Update high watermark before we lower rss */
|
||||||
update_hiwater_rss(mm);
|
update_hiwater_rss(mm);
|
||||||
|
|
||||||
if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
|
if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) {
|
||||||
pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
|
pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
|
||||||
if (PageHuge(page)) {
|
if (folio_test_hugetlb(folio)) {
|
||||||
hugetlb_count_sub(compound_nr(page), mm);
|
hugetlb_count_sub(folio_nr_pages(folio), mm);
|
||||||
set_huge_swap_pte_at(mm, address,
|
set_huge_swap_pte_at(mm, address,
|
||||||
pvmw.pte, pteval,
|
pvmw.pte, pteval,
|
||||||
vma_mmu_pagesize(vma));
|
vma_mmu_pagesize(vma));
|
||||||
} else {
|
} else {
|
||||||
dec_mm_counter(mm, mm_counter(page));
|
dec_mm_counter(mm, mm_counter(&folio->page));
|
||||||
set_pte_at(mm, address, pvmw.pte, pteval);
|
set_pte_at(mm, address, pvmw.pte, pteval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1553,18 +1554,19 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
* migration) will not expect userfaults on already
|
* migration) will not expect userfaults on already
|
||||||
* copied pages.
|
* copied pages.
|
||||||
*/
|
*/
|
||||||
dec_mm_counter(mm, mm_counter(page));
|
dec_mm_counter(mm, mm_counter(&folio->page));
|
||||||
/* We have to invalidate as we cleared the pte */
|
/* We have to invalidate as we cleared the pte */
|
||||||
mmu_notifier_invalidate_range(mm, address,
|
mmu_notifier_invalidate_range(mm, address,
|
||||||
address + PAGE_SIZE);
|
address + PAGE_SIZE);
|
||||||
} else if (PageAnon(page)) {
|
} else if (folio_test_anon(folio)) {
|
||||||
swp_entry_t entry = { .val = page_private(subpage) };
|
swp_entry_t entry = { .val = page_private(subpage) };
|
||||||
pte_t swp_pte;
|
pte_t swp_pte;
|
||||||
/*
|
/*
|
||||||
* Store the swap location in the pte.
|
* Store the swap location in the pte.
|
||||||
* See handle_pte_fault() ...
|
* See handle_pte_fault() ...
|
||||||
*/
|
*/
|
||||||
if (unlikely(PageSwapBacked(page) != PageSwapCache(page))) {
|
if (unlikely(folio_test_swapbacked(folio) !=
|
||||||
|
folio_test_swapcache(folio))) {
|
||||||
WARN_ON_ONCE(1);
|
WARN_ON_ONCE(1);
|
||||||
ret = false;
|
ret = false;
|
||||||
/* We have to invalidate as we cleared the pte */
|
/* We have to invalidate as we cleared the pte */
|
||||||
@ -1575,8 +1577,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* MADV_FREE page check */
|
/* MADV_FREE page check */
|
||||||
if (!PageSwapBacked(page)) {
|
if (!folio_test_swapbacked(folio)) {
|
||||||
if (!PageDirty(page)) {
|
if (!folio_test_dirty(folio)) {
|
||||||
/* Invalidate as we cleared the pte */
|
/* Invalidate as we cleared the pte */
|
||||||
mmu_notifier_invalidate_range(mm,
|
mmu_notifier_invalidate_range(mm,
|
||||||
address, address + PAGE_SIZE);
|
address, address + PAGE_SIZE);
|
||||||
@ -1585,11 +1587,11 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the page was redirtied, it cannot be
|
* If the folio was redirtied, it cannot be
|
||||||
* discarded. Remap the page to page table.
|
* discarded. Remap the page to page table.
|
||||||
*/
|
*/
|
||||||
set_pte_at(mm, address, pvmw.pte, pteval);
|
set_pte_at(mm, address, pvmw.pte, pteval);
|
||||||
SetPageSwapBacked(page);
|
folio_set_swapbacked(folio);
|
||||||
ret = false;
|
ret = false;
|
||||||
page_vma_mapped_walk_done(&pvmw);
|
page_vma_mapped_walk_done(&pvmw);
|
||||||
break;
|
break;
|
||||||
@ -1626,16 +1628,17 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
|
|||||||
address + PAGE_SIZE);
|
address + PAGE_SIZE);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* This is a locked file-backed page, thus it cannot
|
* This is a locked file-backed folio,
|
||||||
* be removed from the page cache and replaced by a new
|
* so it cannot be removed from the page
|
||||||
* page before mmu_notifier_invalidate_range_end, so no
|
* cache and replaced by a new folio before
|
||||||
* concurrent thread might update its page table to
|
* mmu_notifier_invalidate_range_end, so no
|
||||||
* point at new page while a device still is using this
|
* concurrent thread might update its page table
|
||||||
* page.
|
* to point at a new folio while a device is
|
||||||
|
* still using this folio.
|
||||||
*
|
*
|
||||||
* See Documentation/vm/mmu_notifier.rst
|
* See Documentation/vm/mmu_notifier.rst
|
||||||
*/
|
*/
|
||||||
dec_mm_counter(mm, mm_counter_file(page));
|
dec_mm_counter(mm, mm_counter_file(&folio->page));
|
||||||
}
|
}
|
||||||
discard:
|
discard:
|
||||||
/*
|
/*
|
||||||
@ -1645,10 +1648,10 @@ discard:
|
|||||||
*
|
*
|
||||||
* See Documentation/vm/mmu_notifier.rst
|
* See Documentation/vm/mmu_notifier.rst
|
||||||
*/
|
*/
|
||||||
page_remove_rmap(subpage, vma, PageHuge(page));
|
page_remove_rmap(subpage, vma, folio_test_hugetlb(folio));
|
||||||
if (vma->vm_flags & VM_LOCKED)
|
if (vma->vm_flags & VM_LOCKED)
|
||||||
mlock_page_drain(smp_processor_id());
|
mlock_page_drain(smp_processor_id());
|
||||||
put_page(page);
|
folio_put(folio);
|
||||||
}
|
}
|
||||||
|
|
||||||
mmu_notifier_invalidate_range_end(&range);
|
mmu_notifier_invalidate_range_end(&range);
|
||||||
@ -1667,17 +1670,17 @@ static int page_not_mapped(struct page *page)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try_to_unmap - try to remove all page table mappings to a page
|
* try_to_unmap - Try to remove all page table mappings to a folio.
|
||||||
* @page: the page to get unmapped
|
* @folio: The folio to unmap.
|
||||||
* @flags: action and flags
|
* @flags: action and flags
|
||||||
*
|
*
|
||||||
* Tries to remove all the page table entries which are mapping this
|
* Tries to remove all the page table entries which are mapping this
|
||||||
* page, used in the pageout path. Caller must hold the page lock.
|
* folio. It is the caller's responsibility to check if the folio is
|
||||||
|
* still mapped if needed (use TTU_SYNC to prevent accounting races).
|
||||||
*
|
*
|
||||||
* It is the caller's responsibility to check if the page is still
|
* Context: Caller must hold the folio lock.
|
||||||
* mapped when needed (use TTU_SYNC to prevent accounting races).
|
|
||||||
*/
|
*/
|
||||||
void try_to_unmap(struct page *page, enum ttu_flags flags)
|
void try_to_unmap(struct folio *folio, enum ttu_flags flags)
|
||||||
{
|
{
|
||||||
struct rmap_walk_control rwc = {
|
struct rmap_walk_control rwc = {
|
||||||
.rmap_one = try_to_unmap_one,
|
.rmap_one = try_to_unmap_one,
|
||||||
@ -1687,9 +1690,9 @@ void try_to_unmap(struct page *page, enum ttu_flags flags)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (flags & TTU_RMAP_LOCKED)
|
if (flags & TTU_RMAP_LOCKED)
|
||||||
rmap_walk_locked(page, &rwc);
|
rmap_walk_locked(&folio->page, &rwc);
|
||||||
else
|
else
|
||||||
rmap_walk(page, &rwc);
|
rmap_walk(&folio->page, &rwc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1768,7 +1768,7 @@ retry:
|
|||||||
if (unlikely(PageTransHuge(page)))
|
if (unlikely(PageTransHuge(page)))
|
||||||
flags |= TTU_SPLIT_HUGE_PMD;
|
flags |= TTU_SPLIT_HUGE_PMD;
|
||||||
|
|
||||||
try_to_unmap(page, flags);
|
try_to_unmap(folio, flags);
|
||||||
if (page_mapped(page)) {
|
if (page_mapped(page)) {
|
||||||
stat->nr_unmap_fail += nr_pages;
|
stat->nr_unmap_fail += nr_pages;
|
||||||
if (!was_swapbacked && PageSwapBacked(page))
|
if (!was_swapbacked && PageSwapBacked(page))
|
||||||
|
Loading…
Reference in New Issue
Block a user