Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4583499rwb; Tue, 6 Sep 2022 09:27:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR5IdCSoNJCdq3Yk0Ov5r2O3ZU04BOAFC0qWcH/igq3Jkmc+g+d321rmWIhyGutwEjx9q9Ww X-Received: by 2002:a17:90b:4d8e:b0:200:73b4:4da2 with SMTP id oj14-20020a17090b4d8e00b0020073b44da2mr10255426pjb.197.1662481643629; Tue, 06 Sep 2022 09:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662481643; cv=none; d=google.com; s=arc-20160816; b=Ls5heA9V0r2v28LPL1YUrDoR+78EQz05Kzv3y3e8tYenvkmdNp6zEi15RoWrDt2EmH AlI2kzz9LeQcK8QRUPnCvcSAHzdmj7IGimrcLYzZWvnc8qbbxYGeDE+uXnkva+vAARNS SF4kGntAqNaJpVTiNGcQwQB91cbdhFaFSDrnkPqauIjhlFcLAiIWwGv3jJYRNfaCJWpY N13IuMLitQPZZKepiI9dPCgOLr5srMuyvuAfQFUgzL0Teuq9CEohgPCTjPchyDedcjZJ exyGtHqWzHJDVL5UvxCf34jjeNjfkuY7h4aeH/+3OUxEJxdoZSWdqXKCtr1CYB2663f2 ywgA== 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=01CsnEEQfLK1uOpVQ+HH6686vEI9WQZhnhn7tltGMc4=; b=O+WAUpH/FUVaOh/pxkKEL6bDXUTjhhHUNwcyFfaN+7WWqQC4vdjbqIxMod9cAw1iVU gNN3sGSx5FLVZ03uO73w4WB2ePuSXridV7C88fvKl1YXBdw92A16QNVRlfG8US1kCTSw 5yZIjDIuUeAiVt1/u9jK4jkd4bY2IlOC0VKkzjldxQ/bOa70b5GF05hKWJ09zcPdQ3B2 2n+eV4YD+H0yQ1zGWt4ONyiGdUPFfqeKkgf8zyh8qieCR3/jEgkspg2ktarZDfuvyB4j mKuLFkOze+vpkjngmvJm3ni6IBicbAuKks9p+xnNlq0oYO2aU4ZJZLayDrxlR1x+QLgj wlsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=o7ZUoR1k; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw14-20020a17090b4d0e00b001f541fc751fsi22281812pjb.190.2022.09.06.09.27.12; Tue, 06 Sep 2022 09:27:23 -0700 (PDT) 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=@google.com header.s=20210112 header.b=o7ZUoR1k; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232069AbiIFQS6 (ORCPT + 99 others); Tue, 6 Sep 2022 12:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233857AbiIFQRj (ORCPT ); Tue, 6 Sep 2022 12:17:39 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1696E844C2 for ; Tue, 6 Sep 2022 08:46:40 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id z72so9208701iof.12 for ; Tue, 06 Sep 2022 08:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=01CsnEEQfLK1uOpVQ+HH6686vEI9WQZhnhn7tltGMc4=; b=o7ZUoR1kIbCZSNNyLbvrwwtPxnTYEllaZY9cFNDDCCA7TAcp0hkIs2NMKLazX0j/Wb AWxxBk+k5G23dVl64yevMX+VdSw/FzkljOCmS/xASd595atoUnaTjkJmrmR9WjiCsxKE VuyYGhKnfagDzQZ6sGO0kr/wninknslufsnoLThmyJZSuYTU38KSG2qsTZT0WtI8/TFp LX/qK2c50VdG2SVsnEj1+xTC+UMWubZMyMO7uNilERQu9uv4D2aQqwP7+M8bGR8KWyFm OnnkvtEInWpmkIYk4qBKTNg02wGwVlJLJMtpY5HIQ1/Z8WKMbLgAbK2PJvysrvsqnBR+ epoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=01CsnEEQfLK1uOpVQ+HH6686vEI9WQZhnhn7tltGMc4=; b=C3Vn3AlmOaG8kCaSHI504DahtzONfrySvP11EhrzZBvNKbUXsPHuBuhBabFwT3qwzW kH7DfbPCjTo0nyLrYxN1mRlOtf8hUdTFOsxQ7y3DGljgxzW0RxcK2Y+20JjgoX1/r879 92YicEu0MxuauuC3Y6H1zCx/x290yEFH9SDKm4Hbe4Q2HM4mcqE7s49c4yzLNWEyj7C1 1wnUOU7y/6dQdll52N3+t+OtjF75Z97hiqynbK7EPLEIw5rBNBwDGrGg3joGDw1d/0LP 5cU3O+RkZKgwJZN6RBzM55C0Gs2BwZ6VwVPsOSTzLZSUDiYYctkMOOEwL/AkEWX0eTR3 IEMA== X-Gm-Message-State: ACgBeo3fO/MzFJ98j5rhnR3c2K4C0jZpByJjIIW1TJkxhVEIZeXfVX0p 2rC52KQ5Ae9c29BilnUmKHhsVua7pLDWpjJkaCrThg== X-Received: by 2002:a05:6638:1492:b0:34c:d42:ac2f with SMTP id j18-20020a056638149200b0034c0d42ac2fmr16182031jak.305.1662479199238; Tue, 06 Sep 2022 08:46:39 -0700 (PDT) MIME-Version: 1.0 References: <20220901173516.702122-1-surenb@google.com> <20220905203503.tqtr36fsfg4guk4j@moria.home.lan> In-Reply-To: <20220905203503.tqtr36fsfg4guk4j@moria.home.lan> From: Suren Baghdasaryan Date: Tue, 6 Sep 2022 08:46:28 -0700 Message-ID: Subject: Re: [RFC PATCH RESEND 00/28] per-VMA locks proposal To: Kent Overstreet Cc: Michal Hocko , Andrew Morton , Michel Lespinasse , Jerome Glisse , Vlastimil Babka , Johannes Weiner , Mel Gorman , Davidlohr Bueso , Matthew Wilcox , "Liam R. Howlett" , Peter Zijlstra , Laurent Dufour , Laurent Dufour , "Paul E . McKenney" , Andy Lutomirski , Song Liu , Peter Xu , David Hildenbrand , dhowells@redhat.com, Hugh Dickins , Sebastian Andrzej Siewior , David Rientjes , Axel Rasmussen , Joel Fernandes , Minchan Kim , kernel-team , linux-mm , linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 5, 2022 at 1:35 PM Kent Overstreet wrote: > > On Mon, Sep 05, 2022 at 11:32:48AM -0700, Suren Baghdasaryan wrote: > > On Mon, Sep 5, 2022 at 5:32 AM 'Michal Hocko' via kernel-team > > wrote: > > > > > > Unless I am missing something, this is not based on the Maple tree > > > rewrite, right? Does the change in the data structure makes any > > > difference to the approach? I remember discussions at LSFMM where it has > > > been pointed out that some issues with the vma tree are considerably > > > simpler to handle with the maple tree. > > > > Correct, this does not use the Maple tree yet but once Maple tree > > transition happens and it supports RCU-safe lookups, my code in > > find_vma_under_rcu() becomes really simple. > > > > > > > > On Thu 01-09-22 10:34:48, Suren Baghdasaryan wrote: > > > [...] > > > > One notable way the implementation deviates from the proposal is the way > > > > VMAs are marked as locked. Because during some of mm updates multiple > > > > VMAs need to be locked until the end of the update (e.g. vma_merge, > > > > split_vma, etc). > > > > > > I think it would be really helpful to spell out those issues in a greater > > > detail. Not everybody is aware of those vma related subtleties. > > > > Ack. I'll expand the description of the cases when multiple VMAs need > > to be locked in the same update. The main difficulties are: > > 1. Multiple VMAs might need to be locked within one > > mmap_write_lock/mmap_write_unlock session (will call it an update > > transaction). > > 2. Figuring out when it's safe to unlock a previously locked VMA is > > tricky because that might be happening in different functions and at > > different call levels. > > > > So, instead of the usual lock/unlock pattern, the proposed solution > > marks a VMA as locked and provides an efficient way to: > > 1. Identify locked VMAs. > > 2. Unlock all locked VMAs in bulk. > > > > We also postpone unlocking the locked VMAs until the end of the update > > transaction, when we do mmap_write_unlock. Potentially this keeps a > > VMA locked for longer than is absolutely necessary but it results in a > > big reduction of code complexity. > > Correct me if I'm wrong, but it looks like any time multiple VMAs need to be > locked we need mmap_lock anyways, which is what makes your approach so sweet. That is correct. Anytime we need to take VMA's write lock we have to be holding the write side of the mmap_lock as well. That's what allows me to skip locking in cases like checking if the VMA is already locked. > > If however we ever want to lock multiple VMAs without taking mmap_lock, then > deadlock avoidance algorithms aren't that bad - there's the ww_mutex approach, > which is simple and works well when there isn't much expected contention (the > advantage of the ww_mutex approach is that it doesn't have to track all held > locks). I've also written full cycle detection; that approcah gets you fewer > restarts, at the cost of needing a list of all currently held locks. Thanks for the tip! I'll take a closer look at ww_mutex. > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >