linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas()
@ 2021-01-19  7:51 Li Xinhai
  2021-01-19  7:51 ` [PATCH 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-19  7:51 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>
---
 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 2/2] mm: mremap: unlink anon_vmas when mremap with MREMAP_DONTUNMAP success
  2021-01-19  7:51 [PATCH 1/2] mm: rmap: explicitly reset vma->anon_vma in unlink_anon_vmas() Li Xinhai
@ 2021-01-19  7:51 ` Li Xinhai
  0 siblings, 0 replies; 2+ messages in thread
From: Li Xinhai @ 2021-01-19  7:51 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 will 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>
---
 mm/mremap.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mm/mremap.c b/mm/mremap.c
index f554320281cc..7745b672e1a6 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -595,6 +595,13 @@ 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)
+			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-19  7:51 UTC | newest]

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).