Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1192896rwe; Thu, 1 Sep 2022 14:11:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR5/Akc7zFL/8TrIuqcZgV4ONqqGEwmSq8e8m+bQdo3WIxg+pICGvi3dbpEdSiHB4vKiLbcD X-Received: by 2002:a17:906:8a4e:b0:730:9fcd:d988 with SMTP id gx14-20020a1709068a4e00b007309fcdd988mr24972152ejc.636.1662066675868; Thu, 01 Sep 2022 14:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662066675; cv=none; d=google.com; s=arc-20160816; b=nroDAIxjXG0yVaTLDaGorTRQPh37mAlzIvS+nLMCirYJoMSG7rxwPOLXJz+pC2batC HQqTQt3QsryKTCd5wOSHZa6CXrRGPjzitzuJiuWx0Vwa3oILq0kLf2SSNdD/6sEcOa/2 sxSNSPzhh2hHj53FW8O9JqhRQtG3stAtn16JsebgP7YRJFE97CfK2y782PwoCNxGv354 MGm3EBpjDlq1Wg8bmpgEVcJ1lusinW0VkzFPDJiGMXlMxRB3ENjG9ANPBNvV1RYmOQsE hhIRDJlqDsB69EtxT7BBilTr6+IV2k+Zo8JSB0VEP186MdmIf+4bGfpmwYsmNmmOkXQj T4Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:dkim-signature:date; bh=4hkUsmhoc/mtitBsMEKBISOd/1pAkSpFc2P/cfXQtjM=; b=ReoE9hNQz4z+HpnkMP2U00rDkP1i3VRLYbuahYNQdWzkv8cOhX+Bd4ouqHLaKTuXY/ cp7J+0ytuqA5dZBI0GM6OXXV+xoD8hWC5kKNB8BexPRKYnInJMNf3dX+pIQjph9HhiqF 8nu4DWDMeTO1tCg1KSovGCCdI6ISSOgLQsYNzNN3b4vqDj4IJHyHZrnadb5iy/qmxTmT sU/IsN/64ssMWDu7KN/l+Zz9MBk7KoAiiixD2ejtUMky7dxK7EKhQJ2d8VMwl2rdXTrR IMhchqTHao4lpLkxqcxzt4xunEkdem+7o1txvD95hN7+PcdAC20PdRfEfYloe8m+spBq kkhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="GBx/osHm"; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a056402054900b00448624125c9si124035edx.480.2022.09.01.14.10.48; Thu, 01 Sep 2022 14:11:15 -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=@linux.dev header.s=key1 header.b="GBx/osHm"; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235154AbiIAU70 (ORCPT + 99 others); Thu, 1 Sep 2022 16:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235031AbiIAU6n (ORCPT ); Thu, 1 Sep 2022 16:58:43 -0400 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2949A9C1DA for ; Thu, 1 Sep 2022 13:58:31 -0700 (PDT) Date: Thu, 1 Sep 2022 16:58:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1662065909; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4hkUsmhoc/mtitBsMEKBISOd/1pAkSpFc2P/cfXQtjM=; b=GBx/osHm3HGi4Ds4wKNlfh+0rOeAjSc5fMxjCY9+prDg46Our7ah2+T4UCkEyoyjGAR3Ey DNyFdaH7yElNXaYOG7p+DGMlnJB29QeQAVtRk4yNGTDim3sXPR4Q5JwB92gpqpAdtQY8uE Z2Ok6tGIN+Dib9yzL+1nMDwaoBKyC1E= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, paulmck@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, kernel-team@android.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH RESEND 00/28] per-VMA locks proposal Message-ID: <20220901205819.emxnnschszqv4ahy@moria.home.lan> References: <20220901173516.702122-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220901173516.702122-1-surenb@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Thu, Sep 01, 2022 at 10:34:48AM -0700, Suren Baghdasaryan wrote: > Resending to fix the issue with the In-Reply-To tag in the original > submission at [4]. > > This is a proof of concept for per-vma locks idea that was discussed > during SPF [1] discussion at LSF/MM this year [2], which concluded with > suggestion that “a reader/writer semaphore could be put into the VMA > itself; that would have the effect of using the VMA as a sort of range > lock. There would still be contention at the VMA level, but it would be an > improvement.” This patchset implements this suggested approach. > > When handling page faults we lookup the VMA that contains the faulting > page under RCU protection and try to acquire its lock. If that fails we > fall back to using mmap_lock, similar to how SPF handled this situation. > > 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). Tracking all the locked VMAs, avoiding recursive locks > and other complications would make the code more complex. Therefore we > provide a way to "mark" VMAs as locked and then unmark all locked VMAs > all at once. This is done using two sequence numbers - one in the > vm_area_struct and one in the mm_struct. VMA is considered locked when > these sequence numbers are equal. To mark a VMA as locked we set the > sequence number in vm_area_struct to be equal to the sequence number > in mm_struct. To unlock all VMAs we increment mm_struct's seq number. > This allows for an efficient way to track locked VMAs and to drop the > locks on all VMAs at the end of the update. I like it - the sequence numbers are a stroke of genuius. For what it's doing the patchset seems almost small. Two complaints so far: - I don't like the vma_mark_locked() name. To me it says that the caller already took or is taking the lock and this function is just marking that we're holding the lock, but it's really taking a different type of lock. But this function can block, it really is taking a lock, so it should say that. This is AFAIK a new concept, not sure I'm going to have anything good either, but perhaps vma_lock_multiple()? - I don't like the #ifdef and the separate fallback path in the fault handlers. Can we make find_and_lock_anon_vma() do the right thing, and not fail unless e.g. there isn't a vma at that address? Just have it wait for vm_lock_seq to change and then retry if needed.