Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5367092rwb; Tue, 17 Jan 2023 12:45:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWb9Pi+YB3PpdOxRlgDoPbgDviZpEPIyX1Z5q+5t1D4U2syTs3H87jdNG1SfuNBEJszSYQ X-Received: by 2002:a05:6402:221b:b0:493:a6eb:874f with SMTP id cq27-20020a056402221b00b00493a6eb874fmr4612706edb.7.1673988325580; Tue, 17 Jan 2023 12:45:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673988325; cv=none; d=google.com; s=arc-20160816; b=OI936WxTVF8h4yaOB73BZsSgfr/dlPY6ipStR7egQ8XA6AgTF7lfj0mH0CzmIDOeJj eromscFlXfCdU86AwjMfKaN3ClPM/HAasS3Bzst0Qh2ON7A3wpNqgfv+OO8D9GH+b+rb d18Fuso9CMgZCrXgzlrwSyb/YFmvqV3QOIK/4w/W7vnFq8YjxZoS2REdBDuPiUv9OxWd JeIDxZKFLbgaEcqhLBIx/I7ncpMkiG/8J5nzUEGqbeaa2b+9Ks0pH/KKSu47Gdv06KG1 qk52OhrKL00C6gnJiQx4Jo0JdvAazk2NJAEF+ouoJypy79BGkZ3wxlBlgACnLAMfV0e/ E5NA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sqjn7HH62j6yzN+lPodxIW/463YLLqHM4Pu7i7CuDbA=; b=Pd2Ool7++1eIwvjCXBo749Se137dS+xGB/iF/LbJ9HTLjM6LxhYrIvBRSpIYLddVCP CB0YE8lSSyS5L2Z5Nl4MP7BKVr4iDg8nBEGcZXyIxQYJ5n8cr4W5PY10yxrG0mGbTGyK 0pHBM7NmgW7lyfpenAu/Com/4iC9C6L0+QoAzhLMk7TlRYghycGBfdu2hZ2qjUaxEw5K +wIUvIYGNzKjTZQtapj/NiifGPpmvHzGTzJc23GThkDZchFTQ6sgwhdjhSA9o0nURELf Fb4rw9zejstFE/KH/ZhbHH3A3IZT94s2kIvpUSBIrzXWOPhFIBgjcmJBx7i8fd9QhIb7 9gWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="Ex/AaOWH"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di11-20020a170906730b00b0087264124dcbsi4951945ejc.573.2023.01.17.12.45.13; Tue, 17 Jan 2023 12:45:25 -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=@infradead.org header.s=casper.20170209 header.b="Ex/AaOWH"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234233AbjAQT24 (ORCPT + 47 others); Tue, 17 Jan 2023 14:28:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233550AbjAQTOB (ORCPT ); Tue, 17 Jan 2023 14:14:01 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09C7241B7C for ; Tue, 17 Jan 2023 10:27:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sqjn7HH62j6yzN+lPodxIW/463YLLqHM4Pu7i7CuDbA=; b=Ex/AaOWHR37R8oMcEjxCmXcjAo nDl0l/c47RCRWjDMBMtrqachAlZciiZA/0GTanIl6Fyg96pj7Avp7L4TJtEo897AVuglFi//8kWFZ G3cdIWlxMbSicNc2gX8v4QoN4mQ2MJbFU1ITRQwshhp9m/pF0odZ9BwZvuzuOHGH0KxA6SOdbLDlw 77JDB0bs9s/5xFIVhQnzaRfHPlo4QMi24vt/dUdnvzKasmg7dmucwTCk6AwZnthMXd895Gi5EVRBS v5Kk21a6BdLiTpNvhKZfwGaNi2jYgtUVNzz20Om8tp1C0L1IEk6oy4/A6pFIgGqRRXQdzMTYdOeH3 ZDl1bUyA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHqfl-009uMY-Sl; Tue, 17 Jan 2023 18:27:02 +0000 Date: Tue, 17 Jan 2023 18:27:01 +0000 From: Matthew Wilcox To: Suren Baghdasaryan Cc: Hillf Danton , vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, peterz@infradead.org, hughd@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 41/41] mm: replace rw_semaphore with atomic_t in vma_lock Message-ID: References: <20230109205336.3665937-42-surenb@google.com> <20230116140649.2012-1-hdanton@sina.com> <20230117031632.2321-1-hdanton@sina.com> <20230117083355.2374-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 Tue, Jan 17, 2023 at 10:21:28AM -0800, Suren Baghdasaryan wrote: > static inline bool vma_read_trylock(struct vm_area_struct *vma) > { > int count, new; > > /* Check before locking. A race might cause false locked result. */ > if (READ_ONCE(vma->vm_lock->lock_seq) == > READ_ONCE(vma->vm_mm->mm_lock_seq)) > return false; > > count = atomic_read(&vma->vm_lock->count); > for (;;) { > /* > * Is VMA is write-locked? Overflow might produce false > locked result. > * False unlocked result is impossible because we modify and check > * vma->vm_lock_seq under vma->vm_lock protection and > mm->mm_lock_seq > * modification invalidates all existing locks. > */ > if (count < 0) > return false; > > new = count + 1; > /* If atomic_t overflows, fail to lock. */ > if (new < 0) > return false; > > /* > * Atomic RMW will provide implicit mb on success to pair > with smp_wmb in > * vma_write_lock, on failure we retry. > */ > new = atomic_cmpxchg(&vma->vm_lock->count, count, new); > if (new == count) > break; > count = new; > cpu_relax(); The cpu_relax() is exactly the wrong thing to do here. See this thread: https://lore.kernel.org/linux-fsdevel/20230113184447.1707316-1-mjguzik@gmail.com/