From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1C5ECA0EEC for ; Tue, 12 Sep 2023 13:58:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AAF06B00FC; Tue, 12 Sep 2023 09:58:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45AF36B00FD; Tue, 12 Sep 2023 09:58:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3229C6B00FE; Tue, 12 Sep 2023 09:58:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 211C26B00FC for ; Tue, 12 Sep 2023 09:58:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F2B6940C20 for ; Tue, 12 Sep 2023 13:58:44 +0000 (UTC) X-FDA: 81228100968.12.0AA9917 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id DDB3D14000C for ; Tue, 12 Sep 2023 13:58:42 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="C4dp3zc/"; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694527123; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HLmUvHYjOx5CSGh1JuF73s0prezlWCqoq7fl6e++tvY=; b=BQrIQnT+zuLw0kXjYtgBADc7sOHTBaGtvw+0E2ek4PsVR9Pm44d1K8jgBDqOnsKCvGsTri sZxxw15oL8UBDwMAGAqHJjxfgevUwp83BikIeQ9IQ9bIZEPVMlixrXou8ZiKgMn4gXilpA BbQ/LLZIh2wHbfqUd2Oc8feB0jYkXJU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="C4dp3zc/"; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694527123; a=rsa-sha256; cv=none; b=1I+g19VmSszF0pcYt866Q/ZUW3NB6cf0at/QUAP8Dfrt2ahCDt0qVkjiUGUu/SU3Cb/a8/ yuCwYEyWLDFBWiSO5lDr4S5/RRReN2MuFqK/Q6t68I5XkMW/SFPcF8zr3AmuPKz+0xMZwn L41t4d9gQqja+8ozvg3Rn0UfTStUQKc= 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=HLmUvHYjOx5CSGh1JuF73s0prezlWCqoq7fl6e++tvY=; b=C4dp3zc/srLNk1O5LCPz7WiVIl WeS9N0E29pdEYfHkVCt7Btc1NSXni+wJoEFBjTeLUj/+wDBk2ullMwbj5vydn10EntGUrQAn/8sfk KisApbEl4A19ddb+g1RkaOUeezkH83SpxC/HpEgwfWgXQEzKq+Lm23GXf8QrQtjaM+fh6/M3zZYJh CEAODiUyuUO091KirHgiB4kCXbYBN52SbPjMJ9DTedD6MTqWaGf7VRtsGU3yyFJ+If1OWfhy7vjZ8 hpsdRTVjjPw1TbqE7kec1kMZgqwNDfi6FnYjrEnxLl4dHzXHVAWwTFUkqMpyjumYYdsLZIGumUaG6 EYx5yTtg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qg3uS-007vmd-JF; Tue, 12 Sep 2023 13:58:32 +0000 Date: Tue, 12 Sep 2023 14:58:32 +0100 From: Matthew Wilcox To: Peter Zijlstra Cc: Dave Chinner , Waiman Long , Ingo Molnar , Will Deacon , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chandan Babu R , "Darrick J . Wong" , linux-xfs@vger.kernel.org Subject: Re: [PATCH 1/5] locking: Add rwsem_is_write_locked() Message-ID: References: <20230908104434.GB24372@noisy.programming.kicks-ass.net> <70d89bf4-708b-f131-f90e-5250b6804d48@redhat.com> <20230912090342.GC35261@noisy.programming.kicks-ass.net> <20230912135213.GA22127@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230912135213.GA22127@noisy.programming.kicks-ass.net> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DDB3D14000C X-Stat-Signature: t4b1esbuqxo8qbtjcikjifjq4gfbm8kg X-Rspam-User: X-HE-Tag: 1694527122-519757 X-HE-Meta: U2FsdGVkX18wat5SGnGu0967XMYLXDJTxMvay7UP7goiXLks1GRf61uSwMq39Q9L5VBZw3VoJoRCwauQzHXyBO1QHRnMZA4EpoA4Jz1+vTuL8On02Z8uMC6FHW/pjxXtnn8AjuUnmQyUNFzHjWU4HwZmApPbELKgCcddqCMAggGxU3K41OUADHAehkRpI+pr52yTMwfTpKqp13NBNuDgbJE+jkOTF1KUuqYnL8Myn4RwkwMMpQYn7NmoKvzf1UC2QUEbWlpSGkCUPZck2nHPF9aj9l0MSYe292me3Y0P7yxHPCdAWTXADAtG3diBvOTHxOGjs6duARJ43ppd6AQvIP9Z93xJnmpZPSlizAVQOBgiHC8J/sWPpFNbTwu4twinl04F5Y9WKCz6dx8io/y4vy2kZPcY/dx+Lx0ft51f481BZxPGbecakTQ+vaLs5yxPJmegKKflDDu7G5QGz9IaFlREEFhJWVkXyL2mi8eNWICsuHeRD8l9za79W4UJ/8bnJKunlxDGGb4cinnyKwKCFn3xuDqradxDFLmBOJ8UL9AaVI1cvTcMB+HVfYhC8gMyxgqo7zUre8cJgAT+LTASoKkOzPCWqgc3UhGlQgcS+cYmS0R5NJ0h1/VKJxw+QQabq0ExKgQBGwhcOGLNvdOCLTTbHtVNA2jIMVOQR7dkAHO9NO7l50joxmKbJ9YyOjsW3MUqpQ/vhaWE+bFUuxssH/GP2d4U1ZYTwQg4H9LLH5QFJbOIudg/ZvjJ101bzOOjYvCX0tikCpouD1OCYBvZkrFd8XKtItjmkZuO71yGImQEG4yPIsqnKRMLmWB0aIH6E8dkuaBymLwR05ysCCqXtHXeYM44j4G2ZwPqKNDKJUFyQlYQQKHMayVsOmMaUKKi+9HF/Jd5BvdiwGlSantIVHKDmwEghuqn3wQ9J6RAN3DfJNRcVYopkUIx8dy06Q0Mn1EiYNs1vKEKjv9ua2s Cq/99QRv 1C91wpvKYrojD7iCDi3u/eInp2N0wIbxnvJzPltE//xMKlwgEBgOSvSs/vjdNGcGvsnTosR+SzP8Z8xe8HP6zs5Atrsd8sd4J0v0d9T+2N6LTpdMN3LRtIMgOcNw4b3CHJV1PjCnlKXImiahqa9huj/aaYtvjoXS80/d9/MD44J6PG+p9XSp4fsSd3w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Sep 12, 2023 at 03:52:13PM +0200, Peter Zijlstra wrote: > On Tue, Sep 12, 2023 at 01:28:13PM +0100, Matthew Wilcox wrote: > > On Tue, Sep 12, 2023 at 11:03:42AM +0200, Peter Zijlstra wrote: > > > If not, then sure we can do this; it's not like I managed to get rid of > > > muteX_is_locked() -- and I actually tried at some point :/ > > > > > > And just now I grepped for it, and look what I find: > > > > > > drivers/hid/hid-nintendo.c: if (unlikely(mutex_is_locked(&ctlr->output_mutex))) { > > > drivers/nvdimm/btt.c: if (mutex_is_locked(&arena->err_lock) > > > > > > And there's more :-( > > > > Are these actually abuse? I looked at these two, and they both seem to > > be asking "Does somebody else currently have this mutex?" rather than > > "Do I have this mutex?". > > It's effectively a random number generator in that capacity. Someone > might have it or might have had it when you looked and no longer have > it, or might have it now but not when you asked. Well, no. if (mutex_is_locked(&arena->err_lock) || arena->freelist[lane].has_err) { nd_region_release_lane(btt->nd_region, lane); ret = arena_clear_freelist_error(arena, lane); So that's "Is somebody currently processing an error, or have they already finished setting an error". Sure, it's somewhat racy, but it looks like a performance optimisation, not something that needs 100% accuracy. The other one's in a similar boat; an optimisation if anyone else is currently holding this mutex: /* * Immediately after receiving a report is the most reliable time to * send a subcommand to the controller. Wake any subcommand senders * waiting for a report. */ if (unlikely(mutex_is_locked(&ctlr->output_mutex))) { spin_lock_irqsave(&ctlr->lock, flags); ctlr->received_input_report = true; spin_unlock_irqrestore(&ctlr->lock, flags); wake_up(&ctlr->wait); } Sure, they might not still be holding it, or it may have been grabbed one clock tick later; that just means they miss out on this optimisation.