Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5360165rwb; Tue, 17 Jan 2023 12:38:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXvfFNb/uvFj38/y19jOU3fAYdrZ+h5Suuga4eaQlUzcafsrJ/nYv26dzXxWYGgXNuMB+PEy X-Received: by 2002:a17:907:c5c5:b0:86f:5375:9f5d with SMTP id ts5-20020a170907c5c500b0086f53759f5dmr4542468ejc.1.1673987935130; Tue, 17 Jan 2023 12:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673987935; cv=none; d=google.com; s=arc-20160816; b=o0RbW7AMjGtmItPCwlw/e02sw/WiqPtaSE+3HqR0ohqtCIQulc9HbeXhNv6BB9qPqR xYpyDTlLHnc9g+sMPNXJazNoUiuGfsxqtxcRQ0x73BdiFuOA7i2zDItJkMVjWieySrvD Vp+DICemWLEetF6w6Q1i6wwCp44s1YelVhX5aChOxoTd18C/ic6dE5UUyRA6P/EMBahp /EhN0cz2qrv7rXwq/GGtwpgHGZH2rt8r9o+WWilbEj5JVefuy6mtBTWPxJhTWRaf6ELZ J207uCluNlCOcx38ZXrbE7RjXKHD0FT8jdvZxUyGN7mREO0VDCZyxx1Yif0p721ZT5Ns 53zA== 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=hTLKMGXMSAT6MMmNyJi78XQQyP4rpea0yj1IeoSeHZk=; b=TbV2JzGYBM6Sebn69dpHT9TZ/X4/VA+iAYJn5NjzJ8DT8jKEODsr4DA4/jxBgpirAc M+cuL1NVlLw6tmwGUlNFWeS1Uc5nQDLSMfxXd3Px9aCBYemGdCYnON0lx2NB1hyjZGEf EBfxmnSGHpY1KHS6zu0JZ1EMACCe1IzKp2yBgxYJReOqkd59IbsNcZLJ0xTGiyN+n1O7 OgAScSPwwsYU7gHArN3dPyTxtWx3Y2b4fmV+JdtecJpWAvr6qXqD86dzWGbAJ+laFnFb GGVEhIrikfEYelCvyo7D+Jzp5aMR9/TECDB3qq3JzssBrxq/1wfV3FKV2tkO8a5b8EuR EVaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cYvU74tR; 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 qf9-20020a1709077f0900b0084a52896279si34313967ejc.950.2023.01.17.12.38.43; Tue, 17 Jan 2023 12:38:55 -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=@google.com header.s=20210112 header.b=cYvU74tR; 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 S230526AbjAQTao (ORCPT + 47 others); Tue, 17 Jan 2023 14:30:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234156AbjAQTTE (ORCPT ); Tue, 17 Jan 2023 14:19:04 -0500 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C5F4391D for ; Tue, 17 Jan 2023 10:31:58 -0800 (PST) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-4a263c4ddbaso435496847b3.0 for ; Tue, 17 Jan 2023 10:31:58 -0800 (PST) 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:message-id:reply-to; bh=hTLKMGXMSAT6MMmNyJi78XQQyP4rpea0yj1IeoSeHZk=; b=cYvU74tR9mP6Fn9b7plkY3/qUjiSWAQ8Nqo6zWa89Tvw3EfblIo+iwk47g313J50zD OI4yi6Ydglcj6heTHBV+OqDdwSJdnr4wqTbrPmLmh9mqThWV5UYKM05VFEyTkYkAXo3j QMlnnmbDe/lKf1GxHO5kvU0IsXr+gApsS4fTkOq58OZbDpcCBOXxdRO1KDTxZLEelrTC m1K0eNZmldk1GQtixeCW1w6HH+dj9szNi1qhHJcN/MOVBP2CYZjpyXxYNkaGlkAf0JZG TY6bU4vvOEanEihNcw0eqEUfw/p+tEb9UMV8eQ3gmuV1CSkeyLzVwMRJSYmZhbCyUoWj hjlA== 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:message-id :reply-to; bh=hTLKMGXMSAT6MMmNyJi78XQQyP4rpea0yj1IeoSeHZk=; b=oThYYxT6RQBiU9HqUr4s3KBH5Jh9vlc/AladuyPZqUr8SPIk1Ce4I7Cc3ZAXYL2JH0 McBkZY1lt0oqZRi+eMIKbtgmpW3GUzg2JqrSFFvcJd6yreBXbXA52mCIKxTJwfs1jXGC CGGJbZl3ifcgMjeeXxp3/NzEVbRfKsDqe9z9gMpsYhtiOWle2MJfaoGnM/NtQiximafJ d6f7n5FI1VrIWWoqMDOkhYiBCwrwg+yh3o/2AQ+fpT1Ychv632DvElEKvEGdSvqSCoSx Nr0PBMZAHCnt5ccdc7HloDt9dyh5csomlEWNrZzOZQ9MC8EEOBB49ncp1a3Yh0hTknSs 4Ztw== X-Gm-Message-State: AFqh2kpKLT0GB4eQoEbSUlDhgj2rk7rs/+YmagRB3nqvGT6XzT0gXRWn G8MBwDNYuDx/9jVEY5aKuYSDIsRVhg4qhRrCdRbR2g== X-Received: by 2002:a81:1d2:0:b0:433:f1c0:3f1c with SMTP id 201-20020a8101d2000000b00433f1c03f1cmr558134ywb.438.1673980317150; Tue, 17 Jan 2023 10:31:57 -0800 (PST) MIME-Version: 1.0 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> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 17 Jan 2023 10:31:46 -0800 Message-ID: Subject: Re: [PATCH 41/41] mm: replace rw_semaphore with atomic_t in vma_lock To: Matthew Wilcox 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 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, 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 Tue, Jan 17, 2023 at 10:27 AM Matthew Wilcox wrote: > > 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/ Thanks for the pointer, Matthew. I think we can safely remove cpu_relax() since it's unlikely the count is constantly changing under a reader. >