From mboxrd@z Thu Jan 1 00:00:00 1970 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 3538CC433F5 for ; Thu, 3 Feb 2022 12:00:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81B458D0144; Thu, 3 Feb 2022 07:00:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A3C68D0124; Thu, 3 Feb 2022 07:00:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61DB88D0144; Thu, 3 Feb 2022 07:00:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 4FB508D0124 for ; Thu, 3 Feb 2022 07:00:08 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CFF2282DB2 for ; Thu, 3 Feb 2022 12:00:07 +0000 (UTC) X-FDA: 79101325254.05.5B062FB Received: from mail-ua1-f45.google.com (mail-ua1-f45.google.com [209.85.222.45]) by imf31.hostedemail.com (Postfix) with ESMTP id 810C220002 for ; Thu, 3 Feb 2022 12:00:07 +0000 (UTC) Received: by mail-ua1-f45.google.com with SMTP id e17so4672550uad.9 for ; Thu, 03 Feb 2022 04:00:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WadOTv4fHD97vmRjgv+dPh0onajRQzxP4bZOYDKu81U=; b=jGNpQiapVrDLV2n99CgnSbZHZLbQI+3QZntc8nXorg1ZCMJHXzZ094DZYOciZDDdgU zQKyxkSrWJi4aTReB8HO8pMpGpT4ehnMD8eT7EkIN7v7C31qE4vqebthlxj3Hu3kNcAY xd/hj5Mu54sArNmb5DxZ4w0f0XXYPuqsOD3sgdu6Y1rbHZ8XIemR+7E3JNUVWiyxzuIA NUQoR2Kp701TNkbI9/X4cOg9w/ZaEmo/8umouCQkXt8bX+459o4qFmPC5wy1/nmhiFEt CiG4MYFpQFT0VIaWOFF6oEBDuXL0TjDNPve7MY1ixb8YPNh706B7+PU36YNJgmuaWCJL PxDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WadOTv4fHD97vmRjgv+dPh0onajRQzxP4bZOYDKu81U=; b=4MpJ4DtIm9aWDRGVcrWS8KL/Wj7Gl9WmPoPpfcU+AdwLXlV8LNghxPrXs586+nllZY PZjEnBOJWgLykZ1x1jEjIv4aschhH5SODBGV+MxE3krQFXE2UGraABAQEmQ2p1CIhH1q dUa35HhdNodENRchayAo/7lBD6IMWYFyiHxWdWhC1MH/+SqsDAhqURGSNFJ0KA4j2hnp 6EMzItcgOHTmr2MX7vOXlN6fV0NwI1ltXzQOstZ9MrcBFe4HewPUix3pk8aP1mch36wE Cic4g9wPJnVkqT9/Vjd5DYIiHY90NU+dJ53NAyGb0jzd6HCkiaBjR59jEc0rP4BQuzWQ Fr+Q== X-Gm-Message-State: AOAM531vVL1kAo1sIPilYU9eZo5LnSnXpMyVEALhqpkottCQ6u4SEqrM p8aQk0GN/jtt/mn3IU2UeCjeT74zlNv/UZ9z7So= X-Google-Smtp-Source: ABdhPJz4E7U8ZVySsxa2gqBXDIJGQIBwyT7Lr6pkjggNJbLInIIWkKQlgfxQP8Jw8BG7LPr0DBHqYE73+qyobJnmaXk= X-Received: by 2002:a67:b00e:: with SMTP id z14mr13142826vse.57.1643889606736; Thu, 03 Feb 2022 04:00:06 -0800 (PST) MIME-Version: 1.0 References: <20220202024137.2516438-1-Liam.Howlett@oracle.com> <20220202024137.2516438-16-Liam.Howlett@oracle.com> In-Reply-To: <20220202024137.2516438-16-Liam.Howlett@oracle.com> From: Mark Hemment Date: Thu, 3 Feb 2022 11:59:54 +0000 Message-ID: Subject: Re: [PATCH v5 15/70] kernel/fork: Use maple tree for dup_mmap() during forking To: Liam Howlett Cc: "maple-tree@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 810C220002 X-Stat-Signature: 61ic88gsyqrawyz6m7m8suzbb96ymhhx X-Rspam-User: nil Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=googlemail.com header.s=20210112 header.b=jGNpQiap; spf=pass (imf31.hostedemail.com: domain of markhemm@googlemail.com designates 209.85.222.45 as permitted sender) smtp.mailfrom=markhemm@googlemail.com; dmarc=pass (policy=quarantine) header.from=googlemail.com X-HE-Tag: 1643889607-278783 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: On Wed, 2 Feb 2022 at 03:23, Liam Howlett wrote: > > From: "Liam R. Howlett" > > The maple tree was already tracking VMAs in this function by an earlier > commit, but the rbtree iterator was being used to iterate the list. > Change the iterator to use a maple tree native iterator and switch to > the maple tree advanced API to avoid multiple walks of the tree during > insert operations. Unexport the now-unused vma_store() function. > > We track whether we need to free the VMAs and tree nodes through RCU > (ie whether there have been multiple threads that can see the mm_struct > simultaneously; by pthread(), ptrace() or looking at /proc/$pid/maps). > This setting is sticky because it's too tricky to decide when it's safe > to exit RCU mode. > > For performance reasons we bulk allocate the maple tree nodes. The node > calculations are done internally to the tree and use the VMA count and > assume the worst-case node requirements. The VM_DONT_COPY flag does > not allow for the most efficient copy method of the tree and so a bulk > loading algorithm is used. > > Signed-off-by: Matthew Wilcox (Oracle) > Signed-off-by: Liam R. Howlett > Acked-by: Vlastimil Babka > --- > include/linux/mm.h | 2 -- > include/linux/sched/mm.h | 13 +++++++++++++ > kernel/fork.c | 35 +++++++++++++++++++++++++++++------ > 3 files changed, 42 insertions(+), 8 deletions(-) .... > diff --git a/kernel/fork.c b/kernel/fork.c > index 51a7971651ef..8ea683fcefcd 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -377,6 +377,16 @@ void vm_area_free(struct vm_area_struct *vma) > kmem_cache_free(vm_area_cachep, vma); > } > > +void mm_set_in_rcu(struct mm_struct *mm) > +{ > + if (!mt_in_rcu(&mm->mm_mt)) > + return; > + mmap_write_lock(mm); > + mm->mm_mt.ma_flags |= MT_FLAGS_USE_RCU; > + mmap_write_unlock(mm); > +} > +EXPORT_SYMBOL(mm_set_in_rcu); The mt_in_rcu() test looks wrong (inverted). mt_in_rcu() returns true only when MT_FLAGS_USE_RCU is set, so this flag will never set here. All callers of mm_set_in_rcu() check mt_in_rcu() so the test here could be removed. Cheers, Mark