do_wp_page: cannot share file page
Subsystems (4)
PATCH 1/2 do_wp_page: cannot share file page
A small optimization to do_wp_page's check for whether to avoid copy by reusing the page already mapped. It can never share a cached file page, nor can it share a reserved page (often the empty zero page), so it's a waste of time to lock and unlock in those cases. Which nowadays can both be neatly excluded by a preliminary PageAnon test.
Christoph has reported that a preliminary page_count test proved valuable for scalability here, but PageAnon covers more common cases all at once.
---
mm/memory.c | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
@@ -1264,7 +1264,7 @@ static int do_wp_page(struct mm_struct * } old_page =pfn_to_page (pfn); -if (!TestSetPageLocked (old_page)) { +if (PageAnon (old_page) && !TestSetPageLocked (old_page)) {int reuse =can_share_swap_page (old_page);unlock_page (old_page);if (reuse) {
PATCH 2/2 can_share_swap_page: use page_mapcount
Remember that ironic get_user_pages race? when the raised page_count on a page swapped out led do_wp_page to decide that it had to copy on write, so substituted a different page into userspace. 2.6.7 onwards have Andrea's solution, where try_to_unmap_one backs out if it finds page_count raised.
Which works, but is unsatisfying (rmap.c has no other page_count heuristics), and was found a few months ago to hang an intensive page migration test. A year ago I was hesitant to engage page_mapcount, now it seems the right fix.
So remove the page_count hack from try_to_unmap_one; and use activate_page in unuse_mm when dropping lock, to replace its secondary effect of helping swapoff to make progress in that case.
Simplify can_share_swap_page (now called only on anonymous pages) to check page_mapcount + page_swapcount == 1: still needs the page lock to stabilize their (pessimistic) sum, but does not need swapper_space.tree_lock for that.
In do_swap_page, move swap_free and unlock_page below page_add_anon_rmap, to keep sum on the high side, and correct when can_share_swap_page called.
---
mm/memory.c | 10 +++++----- mm/rmap.c | 21 --------------------- mm/swapfile.c | 55 ++++++++++++++++--------------------------------------- 3 files changed, 21 insertions(+), 65 deletions(-)
mm/memory.c +5 -5
@@ -1711,10 +1711,6 @@ static int do_swap_page(struct mm_struct }/* The page isn't present yet, go ahead with the fault. */ - -swap_free (entry); -if (vm_swap_full ()) -remove_exclusive_swap_page (page);inc_mm_counter (mm, rss); pte =mk_pte (page, vma->vm_page_prot);
@@ -1722,12 +1718,16 @@ static int do_swap_page(struct mm_struct pte =maybe_mkwrite (pte_mkdirty (pte), vma); write_access =0 ; } -unlock_page (page);flush_icache_page (vma, page);set_pte_at (mm, address, page_table, pte);page_add_anon_rmap (page, vma, address); +swap_free (entry); +if (vm_swap_full ()) +remove_exclusive_swap_page (page); +unlock_page (page); +if (write_access) {if (do_wp_page (mm, vma, address, page_table, pmd, pte) ==VM_FAULT_OOM )
mm/rmap.c +0 -21
@@ -539,27 +539,6 @@ static int try_to_unmap_one(struct page goto out_unmap; } -/* -* Don't pull an anonymous page out from under get_user_pages. -* GUP carefully breaks COW and raises page count (while holding -* page_table_lock, as we have here) to make sure that the page -* cannot be freed. If we unmap that page here, a user write -* access to the virtual address will bring back the page, but -* its raised count will (ironically) be taken to mean it's not -* an exclusive swap page, do_wp_page will replace it by a copy -* page, and the user never get to see the data GUP was holding -* the original page for. -* -* This test is also useful for when swapoff (unuse_process) has -* to drop page lock: its reference to the page stops existing -* ptes from being unmapped, so swapoff can make progress. -*/ -if (PageSwapCache (page) && -page_count (page) !=page_mapcount (page) +2 ) { - ret =SWAP_FAIL ; - goto out_unmap; - } -/* Nuke the page table entry. */ flush_cache_page (vma, address,page_to_pfn (page)); pteval =ptep_clear_flush (vma, address, pte);
mm/swapfile.c +16 -39
86 lines not on this page · raw message