Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4367320imm; Fri, 18 May 2018 04:04:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrGQsocmF8UUoWMR895K5/zwyqHOWyO+5pEGptb45bEwIrXUg8N+20TwFKyJv5bOr4x6tLE X-Received: by 2002:a17:902:2927:: with SMTP id g36-v6mr8910275plb.303.1526641453004; Fri, 18 May 2018 04:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526641452; cv=none; d=google.com; s=arc-20160816; b=sqA8PkFsQeZboJbkH3y4BRFRNDnXCeTM2uCmvHEj0AZKA5PwmrXNV+qgDnumQOCNZG KzMu8edzWNJ471CahlzuHO/1oqPHEhiI5EXW+fuY8+FtWhUz+0f2WisfQ1QVej1Bi5bw hs7fMlBu9Vn4QIWD4qhZZCAgLufabL1yeZaLtnHjTyfKxdIe2zigPZWWDk+fil8ixLC+ gJAgs4XR/4Qa6hc2CBj4A2DD/TPecmYb7irmybkjQAfCtKOFzU4UdznwdsDQZllDQcbw p+RzbtVSm0HZP0kahUMLXoYUos/qQD3mMvaVG25SDFKNJVFCYZgUWddLNY82QiZMQsc+ 7JVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Bff/CV9RjpGaONGsbsCoQpAXWlka2OwCUrwZpasJBlE=; b=l4ZnZBy6++vHMV7gYOg13NG0d5d6R0h+4wQ8c7OQ9hjwgYlsxj2FbOsyQrX9oinhtg mJnhNal1SzgYAhdAiekexW3i7rwGvSJaS4IAquwgauVueh8YlhpFiAKTErWpkfBK96wx eVQw1v88xo5YL14DLTkJfCMEDo3hBJQWJCodZ3jEwE9eNo7Pp+TPL9kwRrRPDP/TlVn0 8HWlXRy5RZXmTprVQf9gT/u8L64hapkRBWKC5Qb6GEzT7fRbYwvBEpknFj6bAyhF8miv EcR2DTMrFeBgyfQNZxqwjGk9JI04xrDon603AVL1ihlAPll9G0AFRsEsn0B+0mEmcWVf 7xjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Bj2U+lhx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12-v6si7089972pld.367.2018.05.18.04.03.57; Fri, 18 May 2018 04:04:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Bj2U+lhx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752073AbeERLDt (ORCPT + 99 others); Fri, 18 May 2018 07:03:49 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:49846 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750763AbeERLDr (ORCPT ); Fri, 18 May 2018 07:03:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Bff/CV9RjpGaONGsbsCoQpAXWlka2OwCUrwZpasJBlE=; b=Bj2U+lhxzyyzREHjjZrk03n4W UJQCkBgMZK7giK49/eiloPxv/cpCZQUFwXoTNfSnftUI+/XBHgALpSV3hMpFigHbznlru0ly1V7Nx OA+N88Aq56tmFg4/cX2dFSCAIkJJruSwskiXXyGRJ8G54vXVBVN9NElIsYnzxC8dqB3le2HUvkdSK JYRfQP1Tk+G2gQb+OySJa3tuLuiNjmO/DqHiBMivsLeje5MlWKcxkiZXsqzkxEFpggxawy3Zqo1jq ZVEMnOBvzRH2puHL3iVKpO89RAPkm7BiyjFW2yvcIAivJ2hS0syx1PAMHrlp5SwyUl6T17vfGZclj GE9xlFBMQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fJdAj-0005d7-UW; Fri, 18 May 2018 11:03:42 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F273F2029F870; Fri, 18 May 2018 13:03:39 +0200 (CEST) Date: Fri, 18 May 2018 13:03:39 +0200 From: Peter Zijlstra To: Kent Overstreet Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Dave Chinner , darrick.wong@oracle.com, tytso@mit.edu, linux-btrfs@vger.kernel.org, clm@fb.com, jbacik@fb.com, viro@zeniv.linux.org.uk, willy@infradead.org Subject: Re: [PATCH 03/10] locking: bring back lglocks Message-ID: <20180518110339.GG12217@hirez.programming.kicks-ass.net> References: <20180518074918.13816-1-kent.overstreet@gmail.com> <20180518074918.13816-7-kent.overstreet@gmail.com> <20180518095102.GE12217@hirez.programming.kicks-ass.net> <20180518101353.GA15403@kmo-pixel> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180518101353.GA15403@kmo-pixel> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 06:13:53AM -0400, Kent Overstreet wrote: > On Fri, May 18, 2018 at 11:51:02AM +0200, Peter Zijlstra wrote: > > On Fri, May 18, 2018 at 03:49:04AM -0400, Kent Overstreet wrote: > > > bcachefs makes use of them - also, add a proper lg_lock_init() > > > > Why?! lglocks are horrid things, we got rid of them for a reason. They > > have terrifying worst case preemption off latencies. > > Ah. That was missing from your commit message. Yeah, sorry, sometimes it's hard to state what is obvious to oneself :/ > > Why can't you use something like per-cpu rwsems? > > Well, > > a) in my use case, lg_global_lock() pretty much isn't used in normal operation, > it's only called when starting mark and sweep gc (which is not needed > anymore and disabled by default, it'll eventually get rolled into online > fsck) and for device resize > > b) I'm using it in conjection with percpu counters, and technically yes I > certainly _could_ use per-cpu sleepable locks (mutexes would make more sense > for me than rwsems), there's a bit of a clash there and it's going to be a > bit ugly and messy and it's more work for me. (this_cpu_ptr() no longer > makes any sense in that case, so it'd mean auditing and converting all the > code that touches the relevant data structures). Well, lg is a reader-writer style lock per definition, as you want concurrency on the local and full exclusion against the global, so I'm not sure how mutexes fit into this. In any case, have a look at percpu_down_read_preempt_disable() and percpu_up_read_preempt_enable(); they're a bit of a hack but they should work for you I think. They will sleep at down_read, but the entire actual critical section will be with preemption disabled -- therefore it had better be short and bounded, and the RT guys will thank you for not using spinlock_t under it (use raw_spinlock_t if you have to). The (global) writer side will block and be preemptible like normal. > If you're really that dead set against lglocks I might just come up with a new > lock with similar semantics, that doesn't break this_cpu_ptr() but sleeps if the > global lock is held... See above, we already have this ;-)