Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp281654lqs; Thu, 13 Jun 2024 09:50:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVt1zqymYMB2bvaMMPCNttVACaxVGkM462Y37uE475+N+hR5JKd50iKusq2JyTwdTLCRizInPr70/0jXDNX6HKQwgmWi7ztLfRT8IXGg== X-Google-Smtp-Source: AGHT+IGx1FfQXaRhLsUE/h2nCEunfnQyHP5LqGVQvC0smVIL3692Zi67DKZ0zGmxYZI+97Wt6tWT X-Received: by 2002:a17:906:916:b0:a6f:4fc8:2666 with SMTP id a640c23a62f3a-a6f60d46201mr22037966b.44.1718297446769; Thu, 13 Jun 2024 09:50:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718297446; cv=pass; d=google.com; s=arc-20160816; b=kiXiyauEMbmRzZP8XjbQItumkaLRH/MFVjz640fM2/ig6PdLCcxr7iSCMxgja31P3/ TjUKFUpmmp/TbPU4pCBYpoUmLSK5VIjHqwG6YPEpg7bDBgs3tihj7SZXOZiqwmvu2VOv Lbk1JfWuYe7RKNdvhgItE4EcAuN+jn6UK8/U5hBY8eKD8vVpO2CM5KM+Xf7A5rQKU4ZS +armpeGEf4sSNJRtlet8cw8vGALVUfbTr54gVGfwlUGWawCUgFvJBnNu+hsPiWtDkECb fRsbO9GKTNGR2+BVRzjWHJ/TyNvB/5t3MKswMPFQwfTvf9M7HuIJnKr+VE1V/+DleW5h zMkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=kGUfdjMjAIbrnKn5yz/1VobC5vlTgVC/FlKj6pp1/y8=; fh=Ug0nuWssUv5wrCUGb1xo+FtKh3WEu3Y81XCa6LCTcio=; b=z/oZ5oIeg/6MyYCnKpFYTuW4odumyNNAxEf+Z8NhiR3fGDBSu4oGet8wRsTJSYBJd3 5XON3WgFR+k8HTt4ONwV9UpW45QyvmSW9QeinjhonLapl5ZUiamcx/PnHmhuBZjWXCjF gP5I6khfbrvk9BxXf2h+/ZwbWFasAsY0gV1pTKwNXQZTibn9SADmd9ShdvW36rP/XKJQ u84sw2Dxi6RWDvQzWUlDzF8N+GXLYC6HvR7DJ1B0Ua4YFtlPxgJtEygDcYuENDXJy7Tu nPVo0B8PCSiJx1AkQ0HJX5+e2SgCMnL27CgFPR+imXRJUY75PJbBOe0tUv78IDpU5LY6 2gMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=KOwz7Fox; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-213681-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213681-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56df7418si87654866b.648.2024.06.13.09.50.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 09:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213681-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=KOwz7Fox; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-213681-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213681-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 52F581F22373 for ; Thu, 13 Jun 2024 16:50:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27B7917FD; Thu, 13 Jun 2024 16:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="KOwz7Fox" Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F55863A5 for ; Thu, 13 Jun 2024 16:50:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297434; cv=none; b=lOfyZdirbK2dMw0usr20tgtGiWShLybofOsq2VBw+QjXcv9HoKLHTmZZpGPcpqsZ7IL+YFjoCbzyDGbptarEnv2auC6SKBhpXGX1r+IlmQL5b4bgJoWrVHG4Zlv7o9z49K4FiW0NCshigGfUTF9/wYQrSpamQ2XzLZcYJCad7n8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297434; c=relaxed/simple; bh=91rjHWfqxTOGztj0zBNywmYUrS6otdLE39NRyBM6T9I=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sQH4qji32Y7cWrJ2qA7ytUVNTph+QHNGFyOKanR1F/jPw8jMthoOKwKf5cJIAHqt4zpbHgVot86Sh7aMZ2TgTucFcLlLxR0ZGiDIjYOJQNKenx9gl1MvAkV2Xx+UbUaCFyLMFQD+PJoC0Man+37+g516GJQug5BHYFliQAO9Jww= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=KOwz7Fox; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-57cb9a370ddso1180404a12.1 for ; Thu, 13 Jun 2024 09:50:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1718297430; x=1718902230; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kGUfdjMjAIbrnKn5yz/1VobC5vlTgVC/FlKj6pp1/y8=; b=KOwz7FoxKkvS1PDjJVKvofQIZ1rdNmQPv7B+Mv67zyZ50PK5Ahr1Ybt7c74CQyHkaI wdiNpqsa9y49bLWYNJc2fji79RKLHQXa8jRrUaIIFGO5zueqVXea01O7Obp9uS1t2HfG /Y3hCbb1me4toEt6VCBMexz6c0JMJ7IM8QW/o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718297430; x=1718902230; 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=kGUfdjMjAIbrnKn5yz/1VobC5vlTgVC/FlKj6pp1/y8=; b=OzuJLO/eyHRpfVmP610BKEReuv9xZK2EuFNgqcezzttY8fZb25wTDYIvnipNqjGPqB GUfuWMNIDd+0VyiXuqwGSROI29UVaq36G2u5TdVI9RDW+bh0ZiHQcUxKEWLh6e+Cko/N y3GVf0K27ZmZJVPj8SLQT8rWp33Xrdu+vu02Cd25wBV4yluTCMqvulzIbsu6N4xqDtRa ZBK7hXZXHKpaH96WWVrLgolv74yqtOgjrjze85OvEpekfn8appw7QVDBfov1gq19Euiu 4/hBjZBQdcaIDCMw0Kr5Z7mClD//l1eZwoU53tCykVFmzmfFg/H92WmArZ01dtbx4Kur +CVQ== X-Forwarded-Encrypted: i=1; AJvYcCUTml+JYfbFULqYrjFbjmeXI0dQtQOWmfZj6NLfgeo9G6L5eQH5zimYFoth1O/3oRf27LGVBYP/ZrDSkiJTPcZ+tc2H6AY4J3VpGzVU X-Gm-Message-State: AOJu0YzwahfpiM8y94igUEjSNf7c5u30VSOTF5sr2fq4NT7TV67N1+2Q nXku3gtlOFSI3QJ5YRv1wg+R9Sn1jWQcx4FeHPKeAKjarrU3nh3r9IFCZgDORtJFythTdPK7YU8 M03JYwg== X-Received: by 2002:a50:d493:0:b0:57c:600d:5879 with SMTP id 4fb4d7f45d1cf-57cbd67ec1amr259726a12.20.1718297430058; Thu, 13 Jun 2024 09:50:30 -0700 (PDT) Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com. [209.85.218.51]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57cb72e9921sm1113327a12.52.2024.06.13.09.50.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jun 2024 09:50:29 -0700 (PDT) Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a6ef793f4b8so146437566b.1 for ; Thu, 13 Jun 2024 09:50:29 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVGbaIsK+szFwurE1ieGSx0+oMDDAozwHG7EIHr+li1ooFo9UDd7mbHCZgBIYYJOs/8joM9mtccxDvixgtmBSnoLIG5Bz7tnDUucl2w X-Received: by 2002:a17:906:37cf:b0:a6f:1979:7b6d with SMTP id a640c23a62f3a-a6f60dc571cmr22187866b.55.1718297429016; Thu, 13 Jun 2024 09:50:29 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240613001215.648829-1-mjguzik@gmail.com> <20240613001215.648829-2-mjguzik@gmail.com> <5cixyyivolodhsru23y5gf5f6w6ov2zs5rbkxleljeu6qvc4gu@ivawdfkvus3p> In-Reply-To: <5cixyyivolodhsru23y5gf5f6w6ov2zs5rbkxleljeu6qvc4gu@ivawdfkvus3p> From: Linus Torvalds Date: Thu, 13 Jun 2024 09:50:12 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] lockref: speculatively spin waiting for the lock to be released To: Mateusz Guzik Cc: brauner@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Wed, 12 Jun 2024 at 23:10, Mateusz Guzik wrote: > > On Wed, Jun 12, 2024 at 06:23:18PM -0700, Linus Torvalds wrote: > > So I have no problem with your patch 2/2 - moving the lockref data > > structure away from everything else that can be shared read-only makes > > a ton of sense independently of anything else. > > > > Except you also randomly increased a retry count in there, which makes no sense. > > Cmon man, that's a change which unintentionally crept into the patch and > I failed to notice. Heh. It wasn't entirely obvious that it was unintentional, since the series very much was about that whole rety thing. But good. > I was playing with a bpftrace probe reporting how many spins were > performed waiting for the lock. For my intentional usage with ls it was > always < 30 or so. The random-ass intruder which messes with my bench on > occasion needed over 100. Ok. So keeping it at 100 is likely fine. Of course, one option is to simply get rid of the retry count entirely, and just make it all be entirely unconditional. The fallback to locking is not technically required at all for the USE_CMPXCHG_LOCKREF case. That has some unfairness issues, though. But my point is mostly that the count is probably not hugely important or meaningful. > I tested your code and confirm it fixes the problem, nothing blows up > either and I fwiw I don't see any bugs in it. I was more worried about some fat-fingering than any huge conceptual bugs, and any minor testing with performance checks would find that. Just as an example: my first attempt switched the while(likely(..)) to the if (unlikely(..)) in the loop, but didn't add the "!" to negate the test. I caught it immediately and obviously never sent that broken thing out (and it was one reason why I decided I needed to make the code more readable with that lockref_locked() helper macro). But that's mainly the kind of thing I was worried about. > When writing the commit message feel free to use mine in whatever capacity > (including none) you want. Ack. > I think lockref claiming to be a general locking facility means it > should not be suffering the degradation problem to begin with, so that > would be the real problem as far as lockref goes. Well, it was certainly originally meant to be generic, but after more than a decade, the number of users is three. And the two non-dcache users are pretty darn random. So it's effectively really just a dcache special case with two filesystems that started using it just because the authors had clearly seen the vfs use of it... > All that aside, you did not indicate how do you want to move forward > regarding patch submission. lockref is fairly unusual, and is pretty much mine. The initial concept was from Waiman Long: https://lore.kernel.org/all/1372268603-46748-1-git-send-email-Waiman.Long@hp.com/ but I ended up redoing it pretty much from scratch, and credited him as author for the initial commit. It's _technically_ a locking thing, but realistically it has never been locking tree and it's effectively a dcache thing. Linus