mm/rmap: try_to_unmap_one() do not call mmu_notifier under ptl
Subsystems (2)
PATCH 1/1 mm/rmap: try_to_unmap_one() do not call mmu_notifier under ptl
From: JA(C)rA'me Glisse <[email protected]>
MMU notifiers can sleep, but in try_to_unmap_one() we call mmu_notifier_invalidate_page() under page table lock.
Let's instead use mmu_notifier_invalidate_range() outside page_vma_mapped_walk() loop.
--- mm/rmap.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
mm/rmap.c +21 -15
@@ -1329,7 +1329,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, };pte_t pteval;struct page *subpage; -bool ret = true; +bool ret = true, invalidation_needed = false; +unsigned long end = address +PAGE_SIZE ;enum ttu_flags flags = (enum ttu_flags )arg;/* munlock has nothing to gain from examining un-locked vmas */
@@ -1386,7 +1387,6 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,VM_BUG_ON_PAGE (!pvmw.pte, page); subpage = page -page_to_pfn (page) +pte_pfn (*pvmw.pte); - address = pvmw.address; if (IS_ENABLED(CONFIG_MIGRATION) && (flags & TTU_MIGRATION) &&
@@ -1394,7 +1394,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,swp_entry_t entry;pte_t swp_pte; - pteval =ptep_get_and_clear (mm, address, pvmw.pte); + pteval =ptep_get_and_clear (mm, pvmw.address, + pvmw.pte);/* * Store the pfn of the page in a special migration
@@ -1405,12 +1406,12 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, swp_pte =swp_entry_to_pte (entry);if (pte_soft_dirty (pteval)) swp_pte =pte_swp_mksoft_dirty (swp_pte); -set_pte_at (mm, address, pvmw.pte, 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, +if (ptep_clear_flush_young_notify (vma, pvmw.address, pvmw.pte)) { ret = false;page_vma_mapped_walk_done (&pvmw);
@@ -1419,7 +1420,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, }/* Nuke the page table entry. */ -flush_cache_page (vma, address,pte_pfn (*pvmw.pte)); +flush_cache_page (vma, pvmw.address,pte_pfn (*pvmw.pte));if (should_defer_flush (mm, flags)) {/* * We clear the PTE but do not flush so potentially
@@ -1429,11 +1430,12 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,* transition on a cached TLB entry is written through * and traps if the PTE is unmapped. */ - pteval =ptep_get_and_clear (mm, address, pvmw.pte); + pteval =ptep_get_and_clear (mm, pvmw.address, + pvmw.pte);set_tlb_ubc_flush_pending (mm,pte_dirty (pteval)); }else { - pteval =ptep_clear_flush (vma, address, pvmw.pte); + pteval =ptep_clear_flush (vma, pvmw.address, pvmw.pte); }/* Move the dirty bit to the page. Now the pte is gone. */
@@ -1448,12 +1450,12 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,if (PageHuge (page)) {int nr =1 <<compound_order (page);hugetlb_count_sub (nr, mm); -set_huge_swap_pte_at (mm, address, +set_huge_swap_pte_at (mm, pvmw.address, pvmw.pte, pteval,vma_mmu_pagesize (vma)); }else {dec_mm_counter (mm,mm_counter (page)); -set_pte_at (mm, address, pvmw.pte, pteval); +set_pte_at (mm, pvmw.address, pvmw.pte, pteval); } }else if (pte_unused (pteval)) {
@@ -1477,7 +1479,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, swp_pte =swp_entry_to_pte (entry);if (pte_soft_dirty (pteval)) swp_pte =pte_swp_mksoft_dirty (swp_pte); -set_pte_at (mm, address, pvmw.pte, swp_pte); +set_pte_at (mm, pvmw.address, pvmw.pte, swp_pte); }else if (PageAnon (page)) {swp_entry_t entry = { .val =page_private (subpage) };pte_t swp_pte;
@@ -1503,7 +1505,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,* If the page was redirtied, it cannot be * discarded. Remap the page to page table. */ -set_pte_at (mm, address, pvmw.pte, pteval); +set_pte_at (mm, pvmw.address, pvmw.pte, pteval);SetPageSwapBacked (page); ret = false;page_vma_mapped_walk_done (&pvmw);
@@ -1511,7 +1513,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, }if (swap_duplicate (entry) <0 ) { -set_pte_at (mm, address, pvmw.pte, pteval); +set_pte_at (mm, pvmw.address, pvmw.pte, pteval); ret = false;page_vma_mapped_walk_done (&pvmw);break ;
@@ -1527,14 +1529,18 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, swp_pte =swp_entry_to_pte (entry);if (pte_soft_dirty (pteval)) swp_pte =pte_swp_mksoft_dirty (swp_pte); -set_pte_at (mm, address, pvmw.pte, swp_pte); +set_pte_at (mm, pvmw.address, pvmw.pte, swp_pte); }else dec_mm_counter (mm,mm_counter_file (page)); discard:page_remove_rmap (subpage,PageHuge (page));put_page (page); -mmu_notifier_invalidate_page (mm, address); + end = pvmw.address +PAGE_SIZE ; + invalidation_needed = true; } + +if (invalidation_needed) +mmu_notifier_invalidate_range (mm, address, end);return ret; }
Signature · 7 lines
2.13.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 21 lines · On Wed, Aug 09, 2017 at 12:17:09PM -0400, [email protected] wrote:
From: Jérôme Glisse <[email protected]>
MMU notifiers can sleep, but in
try_to_unmap_one()we callmmu_notifier_invalidate_page()under page table lock.Let's instead use
mmu_notifier_invalidate_range()outsidepage_vma_mapped_walk()loop.Signed-off-by Jérôme Glisse <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Andrew Morton <[email protected]>Fixes c7ab0d2fdc84 ("mm: convert try_to_unmap_one() to use page_vma_mapped_walk()")--- mm/rmap.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)mm/rmap.c +0
-0
mm/rmap.c static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, · line 1333
Quoted 6 lines
mm/rmap.c +2
-1@@ -1329,7 +1329,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, };pte_t pteval;struct page *subpage; -bool ret = true; +bool ret = true, invalidation_needed = false; +unsigned long end = address +PAGE_SIZE ;
I think it should be 'address + (1UL << compound_order(page))'.
Signature · 1 line
Kirill A. Shutemov
Quoted 18 lines · On Wed, Aug 09, 2017 at 12:17:09PM -0400, [email protected] wrote:
Quoted 17 lines
From: Jérôme Glisse <[email protected]>
MMU notifiers can sleep, but in
try_to_unmap_one()we callmmu_notifier_invalidate_page()under page table lock.Let's instead use
mmu_notifier_invalidate_range()outsidepage_vma_mapped_walk()loop.Signed-off-by Jérôme Glisse <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Andrew Morton <[email protected]>Fixes c7ab0d2fdc84 ("mm: convert try_to_unmap_one() to use
page_vma_mapped_walk()")--- mm/rmap.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
Quoted 14 lines
mm/rmap.c static bool try_to_unmap_one(struct page *page, · line 1334
Quoted 12 lines
mm/rmap.c +2
-1@@ -1329,7 +1329,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, };pte_t pteval;struct page *subpage; -bool ret = true; +bool ret = true, invalidation_needed = false; +unsigned long end = address +PAGE_SIZE ;I think it should be 'address + (1UL <<
compound_order(page))'.
Can't address point to something else than first page in huge page ? Also i did use end as an optimization ie maybe not all the pte in the range are valid and thus they not all need to be invalidated hence by tracking the last one that needs invalidation i am limiting the range.
But it is a small optimization so i am not attach to it.
Jérôme
Andrew Morton
maintainerQuoted 33 lines · On Wed, 9 Aug 2017 12:52:46 -0400 (EDT) Jerome Glisse <[email protected]>…
Quoted 18 lines · On Wed, Aug 09, 2017 at 12:17:09PM -0400, [email protected] wrote:
Quoted 17 lines
From:
J__r__meGlisse <[email protected]>MMU notifiers can sleep, but in
try_to_unmap_one()we callmmu_notifier_invalidate_page()under page table lock.Let's instead use
mmu_notifier_invalidate_range()outsidepage_vma_mapped_walk()loop.Signed-off-by J__r__me Glisse <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Andrew Morton <[email protected]>Fixes c7ab0d2fdc84 ("mm: convert try_to_unmap_one() to use
page_vma_mapped_walk()")--- mm/rmap.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)Quoted 14 lines
mm/rmap.c static bool try_to_unmap_one(struct page *page, · line 1334
Quoted 12 lines
mm/rmap.c +2
-1@@ -1329,7 +1329,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, };pte_t pteval;struct page *subpage; -bool ret = true; +bool ret = true, invalidation_needed = false; +unsigned long end = address +PAGE_SIZE ;I think it should be 'address + (1UL <<
compound_order(page))'.
Quoted 7 lines
Can't address point to something else than first page in huge page ? Also i did use end as an optimization ie maybe not all the pte in the range are valid and thus they not all need to be invalidated hence by tracking the last one that needs invalidation i am limiting the range.
But it is a small optimization so i am not attach to it.
So we need this patch in addition to Kirrill's "rmap: do not call mmu_notifier_invalidate_page() under ptl".
Jerome, I'm seeing a bunch of rejects applying this patch to current mainline. It's unclear which kernel you're patching but we'll need something which can go into Linus soon and which is backportable (with mimimal fixups) into -stable kernels, please.
Quoted 40 lines · Andrew Morton
Quoted 38 lines · On Wed, 9 Aug 2017 12:52:46 -0400 (EDT) Jerome Glisse <[email protected]>…
Quoted 18 lines · On Wed, Aug 09, 2017 at 12:17:09PM -0400, [email protected] wrote:
Quoted 17 lines
From:
J__r__meGlisse <[email protected]>MMU notifiers can sleep, but in
try_to_unmap_one()we callmmu_notifier_invalidate_page()under page table lock.Let's instead use
mmu_notifier_invalidate_range()outsidepage_vma_mapped_walk()loop.Signed-off-by J__r__me Glisse <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Andrew Morton <[email protected]>Fixes c7ab0d2fdc84 ("mm: convert try_to_unmap_one() to use
page_vma_mapped_walk()")--- mm/rmap.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)Quoted 14 lines
mm/rmap.c static bool try_to_unmap_one(struct page *page, · line 1334
Quoted 12 lines
mm/rmap.c +2
-1@@ -1329,7 +1329,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, };pte_t pteval;struct page *subpage; -bool ret = true; +bool ret = true, invalidation_needed = false; +unsigned long end = address +PAGE_SIZE ;I think it should be 'address + (1UL <<
compound_order(page))'.Can't address point to something else than first page in huge page ? Also i did use end as an optimization ie maybe not all the pte in the range are valid and thus they not all need to be invalidated hence by tracking the last one that needs invalidation i am limiting the range.
Quoted 5 lines
Quoted 2 lines
But it is a small optimization so i am not attach to it.
So we need this patch in addition to Kirrill's "rmap: do not call
mmu_notifier_invalidate_page()under ptl".
Yes we need both to restore mmu_notifier.
Quoted 6 lines
Jerome, I'm seeing a bunch of rejects applying this patch to current mainline. It's unclear which kernel you're patching but we'll need something which can go into Linus soon and which is backportable (with mimimal fixups) into -stable kernels, please.
Sorry this was on top of one of my HMM branches. I am reposting with Kirill end address computation as it is not a big optimization if pte are already invalid then invalidating them once more should not trigger any more work.
Jerome
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>