linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
To: maple-tree@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@google.com>, Song Liu <songliubraving@fb.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Jerome Glisse <jglisse@redhat.com>,
	David Rientjes <rientjes@google.com>,
	Axel Rasmussen <axelrasmussen@google.com>,
	Suren Baghdasaryan <surenb@google.com>,
	Vlastimil Babka <vbabka@suse.cz>, Rik van Riel <riel@surriel.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH v2 11/70] kernel/fork: Convert dup_mmap to use maple tree
Date: Tue, 12 Jan 2021 11:11:41 -0500	[thread overview]
Message-ID: <20210112161240.2024684-12-Liam.Howlett@Oracle.com> (raw)
In-Reply-To: <20210112161240.2024684-1-Liam.Howlett@Oracle.com>

Use the maple tree iterator to duplicate the mm_struct trees.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 include/linux/sched/mm.h |  3 +++
 kernel/fork.c            | 22 +++++++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index d5ece7a9a403f..919e2e44b764e 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -8,6 +8,7 @@
 #include <linux/mm_types.h>
 #include <linux/gfp.h>
 #include <linux/sync_core.h>
+#include <linux/maple_tree.h>
 
 /*
  * Routines for handling mm_structs
@@ -67,11 +68,13 @@ static inline void mmdrop(struct mm_struct *mm)
  */
 static inline void mmget(struct mm_struct *mm)
 {
+	mt_set_in_rcu(&mm->mm_mt);
 	atomic_inc(&mm->mm_users);
 }
 
 static inline bool mmget_not_zero(struct mm_struct *mm)
 {
+	mt_set_in_rcu(&mm->mm_mt);
 	return atomic_inc_not_zero(&mm->mm_users);
 }
 
diff --git a/kernel/fork.c b/kernel/fork.c
index 8c7273b0d4b77..8fcbd970666c3 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -472,7 +472,9 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
 	struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
 	struct rb_node **rb_link, *rb_parent;
 	int retval;
-	unsigned long charge;
+	unsigned long charge = 0;
+	MA_STATE(old_mas, &oldmm->mm_mt, 0, 0);
+	MA_STATE(mas, &mm->mm_mt, 0, 0);
 	LIST_HEAD(uf);
 
 	uprobe_start_dup_mmap();
@@ -506,7 +508,12 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
 		goto out;
 
 	prev = NULL;
-	for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
+
+	retval = mas_entry_count(&mas, oldmm->map_count);
+	if (retval)
+		goto fail_nomem;
+
+	mas_for_each(&old_mas, mpnt, ULONG_MAX) {
 		struct file *file;
 
 		if (mpnt->vm_flags & VM_DONTCOPY) {
@@ -520,7 +527,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
 		 */
 		if (fatal_signal_pending(current)) {
 			retval = -EINTR;
-			goto out;
+			goto loop_out;
 		}
 		if (mpnt->vm_flags & VM_ACCOUNT) {
 			unsigned long len = vma_pages(mpnt);
@@ -589,7 +596,9 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
 		rb_parent = &tmp->vm_rb;
 
 		/* Link the vma into the MT */
-		vma_store(mm, tmp);
+		mas.index = tmp->vm_start;
+		mas.last = tmp->vm_end - 1;
+		mas_store(&mas, tmp);
 
 		mm->map_count++;
 		if (!(tmp->vm_flags & VM_WIPEONFORK))
@@ -599,14 +608,16 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
 			tmp->vm_ops->open(tmp);
 
 		if (retval)
-			goto out;
+			goto loop_out;
 	}
 	/* a new mm has just been created */
 	retval = arch_dup_mmap(oldmm, mm);
+loop_out:
 out:
 	mmap_write_unlock(mm);
 	flush_tlb_mm(oldmm);
 	mmap_write_unlock(oldmm);
+	mas_destroy(&mas);
 	dup_userfaultfd_complete(&uf);
 fail_uprobe_end:
 	uprobe_end_dup_mmap();
@@ -1076,6 +1087,7 @@ static inline void __mmput(struct mm_struct *mm)
 {
 	VM_BUG_ON(atomic_read(&mm->mm_users));
 
+	mt_clear_in_rcu(&mm->mm_mt);
 	uprobe_clear_state(mm);
 	exit_aio(mm);
 	ksm_exit(mm);
-- 
2.28.0



  parent reply	other threads:[~2021-01-12 16:13 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-12 16:11 [PATCH v2 00/70] RFC mm: Introducing the Maple Tree Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 01/70] radix tree test suite: Enhancements for " Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 02/70] radix tree test suite: Add support for fallthrough attribute Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 03/70] radix tree test suite: Add support for kmem_cache_free_bulk Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 04/70] radix tree test suite: Add keme_cache_alloc_bulk() support Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 05/70] Maple Tree: Add new data structure Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 06/70] mm: Start tracking VMAs with maple tree Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 07/70] mm/mmap: Introduce unlock_range() for code cleanup Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 08/70] mm/mmap: Change find_vma() to use the maple tree Liam R. Howlett
2021-01-12 21:01   ` Randy Dunlap
2021-01-12 16:11 ` [PATCH v2 09/70] mm/mmap: Change find_vma_prev() to use " Liam R. Howlett
2021-01-12 21:03   ` Randy Dunlap
2021-01-12 16:11 ` [PATCH v2 10/70] mm/mmap: Change unmapped_area and unmapped_area_topdown " Liam R. Howlett
2021-01-12 21:05   ` Randy Dunlap
2021-01-12 16:11 ` Liam R. Howlett [this message]
2021-01-12 16:11 ` [PATCH v2 12/70] mm: Remove rb tree Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 13/70] mm/gup: Add mm_populate_vma() for use when the vma is known Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 14/70] mm/mmap: Change do_brk_flags() to expand existing VMA and add do_brk_munmap() Liam R. Howlett
2021-01-12 21:15   ` Randy Dunlap
2021-01-13 14:20     ` Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 15/70] mm/mmap: Change vm_brk_flags() to use mm_populate_vma() Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 16/70] mm: Move find_vma_intersection to mmap.c and change implementation to maple tree Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 17/70] mm/mmap: Change mmap_region to use maple tree state Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 18/70] mm/mmap: Drop munmap_vma_range() Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 19/70] mm: Remove vmacache Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 20/70] mm/mmap: Change __do_munmap() to avoid unnecessary lookups Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 21/70] mm/mmap: Move mmap_region() below do_munmap() Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 22/70] mm/mmap: Add do_mas_munmap() and wraper for __do_munmap() Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 23/70] mmap: Use find_vma_intersection in do_mmap() for overlap Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 24/70] mmap: Remove __do_munmap() in favour of do_mas_munmap() Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 25/70] mm/mmap: Change do_brk_munmap() to use do_mas_align_munmap() Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 26/70] mmap: make remove_vma_list() inline Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 27/70] mm: Introduce vma_next() and vma_prev() Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 28/70] arch/arm64: Remove mmap linked list from vdso Liam R. Howlett
2021-01-12 16:11 ` [PATCH v2 29/70] arch/parsic: Remove mmap linked list from kernel/cache Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 30/70] arch/powerpc: Remove mmap linked list from mm/book2s32/tlb Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 31/70] arch/powerpc: Remove mmap linked list from mm/book2s32/subpage_prot Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 32/70] arch/powerpc: Optimize cell spu task sync Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 33/70] arch/s390: Use maple tree iterators instead of linked list Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 34/70] arch/um: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 35/70] arch/x86: Use maple tree iterators for vdso/vma Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 36/70] arch/xtensa: Use maple tree iterators for unmapped area Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 37/70] drivers/misc/cxl: Use maple tree iterators for cxl_prefault_vma() Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 38/70] drivers/oprofile: Lookup address in tree instead of linked list Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 39/70] drivers/tee/optee: Use maple tree iterators for __check_mem_type() Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 40/70] fs/binfmt_elf: Use maple tree iterators for fill_files_note() Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 41/70] fs/coredump: Use maple tree iterators in place of linked list Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 42/70] fs/exec: Use vma_next() instead " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 43/70] fs/proc/base: Use maple tree iterators in place " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 44/70] fs/proc/task_mmu: Stop using linked list and highest_vm_end Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 45/70] fs/userfaultfd: Stop using vma linked list Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 46/70] ipc/shm: Stop using the " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 47/70] kernel/acct: Use maple tree iterators instead of " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 48/70] kernel/events/core: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 49/70] kernel/events/uprobes: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 50/70] kernel/sched/fair: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 51/70] kernel/sys: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 52/70] mm/gup: Use maple tree navigation " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 53/70] mm/huge_memory: Use vma_next() instead of vma " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 54/70] mm/khugepaged: Use maple tree iterators " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 55/70] mm/ksm: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 56/70] mm/madvise: Use vma_next " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 57/70] mm/memcontrol: Stop using mm->highest_vm_end Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 58/70] mm/mempolicy: Use maple tree iterators instead of vma linked list Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 59/70] mm/mlock: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 60/70] mm/mprotect: Use maple tree navigation " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 61/70] mm/mremap: Use vma_next() " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 62/70] mm/msync: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 63/70] mm/nommu: Use maple tree iterators " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 64/70] mm/oom_kill: " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 65/70] mm/pagewalk: Use vma_next() " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 66/70] mm/swapfile: Use maple tree iterator " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 67/70] mm/nommu: Stop inserting into the " Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 68/70] mm/util: Remove __vma_link_list() and __vma_unlink_list() Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 69/70] mm: Remove vma linked list Liam R. Howlett
2021-01-12 16:12 ` [PATCH v2 70/70] mm/mmap: Convert __insert_vm_struct to use mas, convert vma_link to use vma_mas_link() Liam R. Howlett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210112161240.2024684-12-Liam.Howlett@Oracle.com \
    --to=liam.howlett@oracle.com \
    --cc=akpm@google.com \
    --cc=axelrasmussen@google.com \
    --cc=dave@stgolabs.net \
    --cc=jglisse@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=maple-tree@lists.infradead.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=rientjes@google.com \
    --cc=songliubraving@fb.com \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).