rmap 11 mremap moves
Subsystems (5)
PATCH 12/57 rmap 11 mremap moves
From: Hugh Dickins <[email protected]>
A weakness of the anonmm scheme is its difficulty in tracking pages shared between two or more mms (one being an ancestor of the other), when mremap has been used to move a range of pages in one of those mms. mremap move is not very common anyway, and it's more often used on a page range exclusive to the mm; but uncommon though it may be, we must not allow unlocked pages to become unswappable.
This patch follows Linus' suggestion, simply to take a private copy of the page in such a case: early C-O-W. My previous implementation was daft with respect to pages currently on swap: it insisted on swapping them in to copy them. No need for that: just take the copy when a page is brought in from swap, and its intended address is found to clash with what rmap has already noted.
If do_swap_page has to make this copy in the mremap moved case (simply a call to do_wp_page), might as well do so also in the case when it's a write access but the page not exclusive, it's always seemed a little odd that swapin needed a second fault for that. A bug even: get_user_pages force imagines that a single call to handle_mm_fault must break C-O-W. Another bugfix: swapoff's unuse_process didn't check is_vm_hugetlb_page.
Andrea's anon_vma has no such problem with mremap moved pages, handling them with elegant use of vm_pgoff - though at some cost to vma merging. How important is it to handle them efficiently? For now there's a msg printk(KERN_WARNING "%s: mremap moved %d cows\n", current->comm, cows);
---
25-akpm/include/linux/rmap.h | 46 +++++++++++++++++++++++++++++++++ 25-akpm/mm/memory.c | 11 +++++++- 25-akpm/mm/mremap.c | 59 +++++++++++++++++++++++++++++-------------- 25-akpm/mm/rmap.c | 32 +++++++++++++++++++++++ 25-akpm/mm/swapfile.c | 42 +++++++++++++++++++++--------- 5 files changed, 157 insertions(+), 33 deletions(-)
include/linux/rmap.h renamed from include/linux/rmap.h~rmap-11-mremap-moves +46 -0
@@ -34,6 +34,52 @@ static inline void page_dup_rmap(structpage_map_unlock (page); } +int fastcall mremap_move_anon_rmap(struct page *page, unsigned long addr); + +/** +* mremap_moved_anon_rmap - does new address clash with that noted? +* @page: the page just brought back in from swap +* @addr: the user virtual address at which it is mapped +* +* Returns boolean, true if addr clashes with address already in page. +* +* For do_swap_page and unuse_pte: anonmm rmap cannot find the page if +* it's at different addresses in different mms, so caller must take a +* copy of the page to avoid that: not very clever, but too rare a case +* to merit cleverness. +*/ +static inline int mremap_moved_anon_rmap (struct page *page,unsigned long addr) +{ +return page->index != (addr &PAGE_MASK ); +} + +/** +* make_page_exclusive - try to make page exclusive to one mm +* @vma the vm_area_struct covering this address +* @addr the user virtual address of the page in question +* +* Assumes that the page at this address is anonymous (COWable), +* and that the caller holds mmap_sem for reading or for writing. +* +* For mremap's move_page_tables and for swapoff's unuse_process: +* not a general purpose routine, and in general may not succeed. +* But move_page_tables loops until it succeeds, and unuse_process +* holds the original page locked, which protects against races. +*/ +static inline int make_page_exclusive (struct vm_area_struct *vma, +unsigned long addr) +{ +switch (handle_mm_fault (vma->vm_mm, vma, addr,1 )) { +case VM_FAULT_MINOR : +case VM_FAULT_MAJOR : +return 0 ; +case VM_FAULT_OOM : +return -ENOMEM ; +default : +return -EFAULT ; + } +} +/* * Called from kernel/fork.c to manage anonymous memory */
mm/memory.c renamed from mm/memory.c~rmap-11-mremap-moves +10 -1
@@ -1326,14 +1326,23 @@ static int do_swap_page(struct mm_struct mm->rss++; pte =mk_pte (page, vma->vm_page_prot); -if (write_access &&can_share_swap_page (page)) +if (write_access &&can_share_swap_page (page)) { pte =maybe_mkwrite (pte_mkdirty (pte), vma); + write_access =0 ; + }unlock_page (page);flush_icache_page (vma, page);set_pte (page_table, pte);page_add_anon_rmap (page, mm, address); +if (write_access ||mremap_moved_anon_rmap (page, address)) { +if (do_wp_page (mm, vma, address, + page_table, pmd, pte) ==VM_FAULT_OOM ) + ret =VM_FAULT_OOM ; + goto out; + } +/* No need to invalidate - it was non-present before */ update_mmu_cache (vma, address, pte);pte_unmap (page_table);
mm/mremap.c renamed from mm/mremap.c~rmap-11-mremap-moves +40 -19
113 lines not on this page · raw message
mm/rmap.c renamed from mm/rmap.c~rmap-11-mremap-moves +32 -0
@@ -263,6 +263,12 @@ static inline int page_referenced_anon(s } } +/* +* The warning below may appear if page_referenced catches the +* page in between page_add_rmap and its replacement demanded +* by mremap_moved_anon_page: so remove the warning once we're +* convinced that anonmm rmap really is finding its pages. +*/ WARN_ON (!failed); out:spin_unlock (&anonhd->lock);
@@ -451,6 +457,32 @@ void fastcall page_remove_rmap(struct pa }/** +* mremap_move_anon_rmap - try to note new address of anonymous page +* @page: page about to be moved +* @address: user virtual address at which it is going to be mapped +* +* Returns boolean, true if page is not shared, so address updated. +* +* For mremap's can_move_one_page: to update address when vma is moved, +* provided that anon page is not shared with a parent or child mm. +* If it is shared, then caller must take a copy of the page instead: +* not very clever, but too rare a case to merit cleverness. +*/ +int fastcall mremap_move_anon_rmap(struct page *page, unsigned long address) +{ +int move =0 ; +if (page->mapcount ==1 ) { +page_map_lock (page); +if (page->mapcount ==1 ) { + page->index = address &PAGE_MASK ; + move =1 ; + } +page_map_unlock (page); + } +return move; +} + +/** ** Subfunctions of try_to_unmap: try_to_unmap_one called ** repeatedly from either try_to_unmap_anon or try_to_unmap_file. **/
mm/swapfile.c renamed from mm/swapfile.c~rmap-11-mremap-moves +29 -13
104 lines not on this page · raw message
_
--
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>