mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
madvise: convert madvise_free_pte_range() to use a folio
Saves a lot of calls to compound_head(). Link: https://lkml.kernel.org/r/20220902194653.1739778-44-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
2fad3d14b9
commit
98b211d641
49
mm/madvise.c
49
mm/madvise.c
@ -601,6 +601,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
|
|||||||
struct vm_area_struct *vma = walk->vma;
|
struct vm_area_struct *vma = walk->vma;
|
||||||
spinlock_t *ptl;
|
spinlock_t *ptl;
|
||||||
pte_t *orig_pte, *pte, ptent;
|
pte_t *orig_pte, *pte, ptent;
|
||||||
|
struct folio *folio;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
int nr_swap = 0;
|
int nr_swap = 0;
|
||||||
unsigned long next;
|
unsigned long next;
|
||||||
@ -645,56 +646,56 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
|
|||||||
page = vm_normal_page(vma, addr, ptent);
|
page = vm_normal_page(vma, addr, ptent);
|
||||||
if (!page || is_zone_device_page(page))
|
if (!page || is_zone_device_page(page))
|
||||||
continue;
|
continue;
|
||||||
|
folio = page_folio(page);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If pmd isn't transhuge but the page is THP and
|
* If pmd isn't transhuge but the folio is large and
|
||||||
* is owned by only this process, split it and
|
* is owned by only this process, split it and
|
||||||
* deactivate all pages.
|
* deactivate all pages.
|
||||||
*/
|
*/
|
||||||
if (PageTransCompound(page)) {
|
if (folio_test_large(folio)) {
|
||||||
if (page_mapcount(page) != 1)
|
if (folio_mapcount(folio) != 1)
|
||||||
goto out;
|
goto out;
|
||||||
get_page(page);
|
folio_get(folio);
|
||||||
if (!trylock_page(page)) {
|
if (!folio_trylock(folio)) {
|
||||||
put_page(page);
|
folio_put(folio);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
pte_unmap_unlock(orig_pte, ptl);
|
pte_unmap_unlock(orig_pte, ptl);
|
||||||
if (split_huge_page(page)) {
|
if (split_folio(folio)) {
|
||||||
unlock_page(page);
|
folio_unlock(folio);
|
||||||
put_page(page);
|
folio_put(folio);
|
||||||
orig_pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
|
orig_pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
unlock_page(page);
|
folio_unlock(folio);
|
||||||
put_page(page);
|
folio_put(folio);
|
||||||
orig_pte = pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
|
orig_pte = pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
|
||||||
pte--;
|
pte--;
|
||||||
addr -= PAGE_SIZE;
|
addr -= PAGE_SIZE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
VM_BUG_ON_PAGE(PageTransCompound(page), page);
|
if (folio_test_swapcache(folio) || folio_test_dirty(folio)) {
|
||||||
|
if (!folio_trylock(folio))
|
||||||
if (PageSwapCache(page) || PageDirty(page)) {
|
|
||||||
if (!trylock_page(page))
|
|
||||||
continue;
|
continue;
|
||||||
/*
|
/*
|
||||||
* If page is shared with others, we couldn't clear
|
* If folio is shared with others, we mustn't clear
|
||||||
* PG_dirty of the page.
|
* the folio's dirty flag.
|
||||||
*/
|
*/
|
||||||
if (page_mapcount(page) != 1) {
|
if (folio_mapcount(folio) != 1) {
|
||||||
unlock_page(page);
|
folio_unlock(folio);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PageSwapCache(page) && !try_to_free_swap(page)) {
|
if (folio_test_swapcache(folio) &&
|
||||||
unlock_page(page);
|
!folio_free_swap(folio)) {
|
||||||
|
folio_unlock(folio);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearPageDirty(page);
|
folio_clear_dirty(folio);
|
||||||
unlock_page(page);
|
folio_unlock(folio);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pte_young(ptent) || pte_dirty(ptent)) {
|
if (pte_young(ptent) || pte_dirty(ptent)) {
|
||||||
@ -712,7 +713,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
|
|||||||
set_pte_at(mm, addr, pte, ptent);
|
set_pte_at(mm, addr, pte, ptent);
|
||||||
tlb_remove_tlb_entry(tlb, pte, addr);
|
tlb_remove_tlb_entry(tlb, pte, addr);
|
||||||
}
|
}
|
||||||
mark_page_lazyfree(page);
|
mark_page_lazyfree(&folio->page);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
if (nr_swap) {
|
if (nr_swap) {
|
||||||
|
Loading…
Reference in New Issue
Block a user