From patchwork Mon Feb 27 17:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA749C7EE23 for ; Mon, 27 Feb 2023 17:36:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 863E26B0085; Mon, 27 Feb 2023 12:36:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 814566B0087; Mon, 27 Feb 2023 12:36:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B40B6B0088; Mon, 27 Feb 2023 12:36:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5D0F06B0085 for ; Mon, 27 Feb 2023 12:36:59 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1FC711209C0 for ; Mon, 27 Feb 2023 17:36:59 +0000 (UTC) X-FDA: 80513777358.28.B7E2D6D Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf25.hostedemail.com (Postfix) with ESMTP id 3EB0BA000D for ; Mon, 27 Feb 2023 17:36:57 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="D/TbQt2c"; spf=pass (imf25.hostedemail.com: domain of 3OOr8YwYKCCcVXUHQEJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3OOr8YwYKCCcVXUHQEJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677519417; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9aVmQ+gMlQiQzO0BzppdTJNpvPFfXe9SF4GFtX+8IdI=; b=mdKqik5ZEgYW1tSqFMeWzb0SolM/XuFY3hTZ5HRRN1PR617tM5otambJ+2SMv4fzf3sFg7 7ryz/j5ZJNHRpc+Eh5CpyCMeSttFTYhXawejAUMTg7gmT3SNGUa1n8Mr+ihOzcbrSTpJqh 2MUctLExCivjcho6sWXYw6jMMuM9gfE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="D/TbQt2c"; spf=pass (imf25.hostedemail.com: domain of 3OOr8YwYKCCcVXUHQEJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3OOr8YwYKCCcVXUHQEJRRJOH.FRPOLQXa-PPNYDFN.RUJ@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519417; a=rsa-sha256; cv=none; b=VJdEiEEl6h31pdajF9wPxMvd0JQA9TvKNYnHfM6DPciSYVxsGMfyInKecFRXgO+7Ml2W9y UalfSqVcbJocw4Zs7n6BAEHVvC1mukxI6wFC/BKgZ0XhzDIp3sjzyk09d0w/qDn1qdlX4I 7OUZ/VD/MJ9zGOp5JDEY/aNL+ruZup4= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-536e8d6d9ceso153557647b3.12 for ; Mon, 27 Feb 2023 09:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9aVmQ+gMlQiQzO0BzppdTJNpvPFfXe9SF4GFtX+8IdI=; b=D/TbQt2c2awJMi6HOd9NzTPN8Wh6HIDVRf22VcVpKnoo2iG9BW3cveeUmkm8PKhRJw e8yR0ZbMCGkBSW5fis3LsBzhCw5i+IpUgPXTff0+yi++DCnoiZhErYzM/F+7mHgcikXH QOit+1nZssfs8RFlG5fSiSPYICEv1yz50+pHU8s0ps/vZirUhJuz0Ulrl1hrsOJOpcE3 znNNgdhtvb5jKMhdVyGD/B9paUJjeax2LqQ02QvRkavKjrbvwoC4jih7/m+HHIs6ILLw YfzP5gfYx0HByoaWOc2LKVichxZvwcYhuSo6etH4BNZtHefRK1x1pNfZ+dtw2h02k/FS yoOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9aVmQ+gMlQiQzO0BzppdTJNpvPFfXe9SF4GFtX+8IdI=; b=hksm+TKOXQEuoEkOpiaFZYbdksZy0IDU5q+VmBAiWlZ48MhrqIDm1ID0bPAuSZazkm IZznVwjVyYXfdGiTeFuR2p+71S1VCR5/Gh7pGeldCgxWxy/7gHKTit40b/KRQ5lQeWBo FvneRS+D2PJrlWuIe6o+4Wz42fuVhVugiPW0kYV0Qb1hMUvYRT+RzasJu9oEMCrg8TBl 2qAFCT/dOFyRlXKJv3ufmTP71qcpTOaVtt0+v1xLv4xmYbPIOlqd7qwCUJCWK1G3QDfR hWzm8joHjjWoCFrW4f7i3ullENedLB7E7GT9TFgn5jxPFduqjpINhx7RAJ0ZTwcZefy3 vZew== X-Gm-Message-State: AO0yUKUJuYAbKWe4Mw/gtf/GCHGC8dYU8k+EODOZsirKh6aPLEkvYI8h hcREFPolQ2hAjMNdbODAQ6PdKxg06BU= X-Google-Smtp-Source: AK7set8Y6D5rMaDNffZrErpNBudkJshlslCM/7lUMkyK7fj0ZkdAWXrQW4GsW7RGl7OL0nGeq+RMkIj/EqM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a05:6902:1205:b0:a09:314f:9f09 with SMTP id s5-20020a056902120500b00a09314f9f09mr214802ybu.6.1677519416349; Mon, 27 Feb 2023 09:36:56 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:07 -0800 In-Reply-To: <20230227173632.3292573-1-surenb@google.com> Mime-Version: 1.0 References: <20230227173632.3292573-1-surenb@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230227173632.3292573-9-surenb@google.com> Subject: [PATCH v4 08/33] mm: Enable maple tree RCU mode by default. From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, "Liam R. Howlett" ,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CyyzdoETkqf16P0Wxiu1JI74ztmVdnkH4We8 wqomBlFC Lt+HLuTBtGpl0eLKSsXWn2SGRBnnGO2XBJHTkEX8aFYVP+m/HDKqusQl2SwLBd70Hdz2lGIiiojHcEIVCnlA3YneTwuPb4QlhWXka0HC572pdGaVuMF957+bZpFMGqBScJ2uGb7unv6fMgn+uIexs8ZTsBEClbLIzkJ4ziZA/wwQxOb3DfgIy0d8XAfIrtqqBYAu0Dhivf+ZpOvrQNhblpJTUY7NWhJHA4CJ5c+jhgpmt5f7+Hc0h2q2yokM774UyuZpwPhKswDLkyjo8W8TWpzX1cO+oEftNv6tURSSLahDypfFbrt+g96eSUd72GPLF2wcePAK2jZsCc6btxhRxo9B2V/RQSx9DNAbWzMuWuaSpSlu4sk88XYzns3jD/EbiEnJ7H20Ni7/4GU34UpQcqrzZgvwXLx45/wBYtrt0vlY8jeQGyJQ658FoQXAog5YIyOkgPd32/sdKYWmvLL3QdeoP+9eWJD0BXtXZL9uq2gnI3aVxYZRHzp+RPNz0tMKFlstDW2Z13F8HnX57wNHfMKlGDGV+YJjsfsMBeO12yvVBUwZtP8EY/P4ZKQGol+RgWfXHOqoVp1F7jSWKFq95A/N8Kl4h1YVKmAW9S5yfx5uWuE6PIyOv28QzK/ppm0RuTufNABKhBC9uzy/lvQJbYF4Xtw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Liam R. Howlett" Use the maple tree in RCU mode for VMA tracking. This is necessary for the use of per-VMA locking. RCU mode is enabled by default but disabled when exiting an mm and for the new tree during a fork. Also enable RCU for the tree used in munmap operations to ensure the nodes remain valid for readers. Signed-off-by: Liam R. Howlett Signed-off-by: Suren Baghdasaryan --- include/linux/mm_types.h | 3 ++- kernel/fork.c | 3 +++ mm/mmap.c | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 417d25c6a262..22b2ac82bffd 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -779,7 +779,8 @@ struct mm_struct { unsigned long cpu_bitmap[]; }; -#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN) +#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \ + MT_FLAGS_USE_RCU) extern struct mm_struct init_mm; /* Pointer magic because the dynamic array size confuses some compilers. */ diff --git a/kernel/fork.c b/kernel/fork.c index 0cbfdc4b509e..abfcf95734c7 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -617,6 +617,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, if (retval) goto out; + mt_clear_in_rcu(vmi.mas.tree); for_each_vma(old_vmi, mpnt) { struct file *file; @@ -700,6 +701,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, retval = arch_dup_mmap(oldmm, mm); loop_out: vma_iter_free(&vmi); + if (!retval) + mt_set_in_rcu(vmi.mas.tree); out: mmap_write_unlock(mm); flush_tlb_mm(oldmm); diff --git a/mm/mmap.c b/mm/mmap.c index 740b54be3ed4..c234443ee24c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2277,7 +2277,8 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, int count = 0; int error = -ENOMEM; MA_STATE(mas_detach, &mt_detach, 0, 0); - mt_init_flags(&mt_detach, MT_FLAGS_LOCK_EXTERN); + mt_init_flags(&mt_detach, vmi->mas.tree->ma_flags & + (MT_FLAGS_LOCK_MASK | MT_FLAGS_USE_RCU)); mt_set_external_lock(&mt_detach, &mm->mmap_lock); /* @@ -3042,6 +3043,7 @@ void exit_mmap(struct mm_struct *mm) */ set_bit(MMF_OOM_SKIP, &mm->flags); mmap_write_lock(mm); + mt_clear_in_rcu(&mm->mm_mt); free_pgtables(&tlb, &mm->mm_mt, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); tlb_finish_mmu(&tlb);