All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas()
@ 2021-01-27  8:39 Li Xinhai
  2021-01-27  8:39 ` [PATCH v2 2/2] mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP success Li Xinhai
  0 siblings, 1 reply; 2+ messages in thread
From: Li Xinhai @ 2021-01-27  8:39 UTC (permalink / raw)
  To: linux-mm; +Cc: akpm

In case the vma will continue to be used after unlink its relevant
anon_vma, we need to reset the vma->anon_vma pointer to NULL. So,
later when fault happen within this vma again, a new anon_vma will be
prepared.

By this way, the vma will only be checked for reverse mapping of pages
which been fault in after the unlink_anon_vmas call.

Currently, the mremap with MREMAP_DONTUNMAP scenario will continue use
the vma after moved its page table entries to a new vma. For other
scenarios, the vma itself will be freed after call unlink_anon_vmas.

Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
---
v1->v2:
No chnages.

 mm/rmap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/rmap.c b/mm/rmap.c
index 08c56aaf72eb..31ef76180c53 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -413,8 +413,15 @@ void unlink_anon_vmas(struct vm_area_struct *vma)
 		list_del(&avc->same_vma);
 		anon_vma_chain_free(avc);
 	}
-	if (vma->anon_vma)
+	if (vma->anon_vma) {
 		vma->anon_vma->degree--;
+
+		/*
+		 * vma would still be needed after unlink, and anon_vma will be prepared
+		 * when handle fault.
+		 */
+		vma->anon_vma = NULL;
+	}
 	unlock_anon_vma_root(root);
 
 	/*
-- 
2.18.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2 2/2] mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP success
  2021-01-27  8:39 [PATCH v2 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas() Li Xinhai
@ 2021-01-27  8:39 ` Li Xinhai
  0 siblings, 0 replies; 2+ messages in thread
From: Li Xinhai @ 2021-01-27  8:39 UTC (permalink / raw)
  To: linux-mm
  Cc: akpm, Brian Geffon, Lokesh Gidra, Minchan Kim,
	Kirill A . Shutemov, Vlastimil Babka, Andrea Arcangeli

mremap with MREMAP_DONTUNMAP can move all page table entries to new vma,
which means all pages allocated for the old vma are not relevant to it
anymore, and the relevant anon_vma links needs to be unlinked, in nature
the old vma is much like been freshly created and have no pages been
fault in.

But we should not do unlink, if the new vma has effectively merged with
the old one.

Cc: Brian Geffon <bgeffon@google.com>
Cc: Lokesh Gidra <lokeshgidra@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
---
v1->v2:
Need to consider the old vma just been partially moved, if so we must
keep the anon_vma links for remaining mapped pages in old vma.

 mm/mremap.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/mremap.c b/mm/mremap.c
index f554320281cc..ec6c63e3ea66 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -595,6 +595,14 @@ static unsigned long move_vma(struct vm_area_struct *vma,
 		/* We always clear VM_LOCKED[ONFAULT] on the old vma */
 		vma->vm_flags &= VM_LOCKED_CLEAR_MASK;
 
+		/*
+		 * anon_vma links of the old vma is no longer needed after its page
+		 * table has been moved.
+		 */
+		if (new_vma != vma && vma->vm_start == old_addr &&
+			vma->vm_end == (old_addr + old_len))
+			unlink_anon_vmas(vma);
+
 		/* Because we won't unmap we don't need to touch locked_vm */
 		return new_addr;
 	}
-- 
2.18.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-27  8:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27  8:39 [PATCH v2 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas() Li Xinhai
2021-01-27  8:39 ` [PATCH v2 2/2] mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP success Li Xinhai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.