Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2617539pxb; Thu, 3 Feb 2022 10:14:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUK9ScBonUTZGxX5D/vzy0BJqHh6oHAGk9ZEOWZ++7TQHv22FeuFOvj1HbshFb+w0geQeL X-Received: by 2002:a17:906:1d14:: with SMTP id n20mr30430669ejh.714.1643912078120; Thu, 03 Feb 2022 10:14:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643912078; cv=none; d=google.com; s=arc-20160816; b=WETmf0O8zuWJVhkxfpi5vQ4W1LpMUx79Zrn/8ZOnMLuWhxd82z4DV0KHHGS/whV2/a UIVVxNeFtpfhteDy7N1RyPKrmaS24XeEvON6L1n6GKtMEKiUQ59ige9P74XvNzmTnYd7 WMOrLWqxqe1i+QOTvtpRAVU0Z5L1yx5Euxdsi1qrI3j6Kn9d939ketF+qd0AeihoLLYj CadbNP0e9P1XbzWN5/yWp7lelVyL1q95tIc/Xq+PvtehWyvdA+XSNo0XELFy/3t/ZKMl B0ho3vWdl1xQUKdKitex2DBHkEC/omkA8G6rVJ+W0Bw8CQ1i6ItzB5qHvSRtBIoekGdj xKUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WadOTv4fHD97vmRjgv+dPh0onajRQzxP4bZOYDKu81U=; b=0ClXputINi1s3P5SGyIDxVXtmygAqGqcTNyUehB8xjWxiTe1lnaCi/7EWjYovL4E/W RzGAnfbkarsVI0oq1z3hROL/49N7v8mD8TogzOLhwD0nSTBGtWfmAUavAqUXZTnNaXFh epMVp+UoqjjGEdbMPqbGS/oxtmxHQbs/mUI3IIVR1ogy4n7yOkzrMkjO+6F8NRlCpiEt 79kMDU5KQ3Bv20BksRY8H3eGesepLeBm2h85qcKjfD4Sp2YXY62XTVe1sMqAN51d+vWS dxZ1kKgjzvP/AKmj+NeVfUag43MkUyRs+GAJqyYEFXPH+kr9HOQAcndNmHJMzWkUr5S2 /ZVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=jGNpQiap; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 5si12141418ejd.877.2022.02.03.10.14.12; Thu, 03 Feb 2022 10:14:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b=jGNpQiap; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350343AbiBCMAJ (ORCPT + 99 others); Thu, 3 Feb 2022 07:00:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbiBCMAH (ORCPT ); Thu, 3 Feb 2022 07:00:07 -0500 Received: from mail-ua1-x936.google.com (mail-ua1-x936.google.com [IPv6:2607:f8b0:4864:20::936]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8E64C061714 for ; Thu, 3 Feb 2022 04:00:07 -0800 (PST) Received: by mail-ua1-x936.google.com with SMTP id r8so4850334uaj.0 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=2aKC7xfjNZWSVVa0eJ3EZBjt9GWaEsQrJufVZiWlAS6StryQlvhA/pdGcKEtYzCBKJ I2pLQ9pF0GCJxO71+qxu0ytShGqRnY5+PNk2G2STfmcVBB124Qc1VJAHjSep90sTTHAG VC6Dyua7WoXIzT9JmAMEuKDBM6BBGFnJN1HU/WLkOXe2diTjmDpL7dZHNl/fxOt6KlqT 8cbiLregop2u/dFs9bUY9Gep0fyQd8hfPu/OcJe6Odtkf6AGTh9jh7xQGlXgM/fIG4LC 0BQ9nDvxtCPdjDKQF05FjJDTgt6TIGVV2zrBaXjGNoGcxcLwuD9uZRszwJbF9zni5u4r hsDw== X-Gm-Message-State: AOAM530Da9PYDbjurjQY5p2/RUzpOFkwnqzfFG55/Q6/CEYyzxhER9Jb Y7iZirjcRH3HdoBzSJgkD4lqD9f0PZuzcSkOxnKCNZwiOpI= 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" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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