Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4403015imm; Fri, 18 May 2018 04:40:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpKoZxaw8j5mLj9v3hFXyNvc2n+KIYxnWwPIo1o9n80fNAU9ICoV+KXirzZk4uooxq/ijbW X-Received: by 2002:a62:2417:: with SMTP id r23-v6mr9085657pfj.108.1526643602252; Fri, 18 May 2018 04:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526643602; cv=none; d=google.com; s=arc-20160816; b=Yvps3EsTB39bHXmBGW6AS3yjAlJJnLmEVskE0XzMSJNA9UWcCa2TQL9I+EBDggY19E /eBa1DTl3ZOvA4O5D6mrsqf/E9KQC0dDQDB5Fe3L8UXtQF8iCHZAGTua+1RwQskDMV9k GpVJrulzAV6pIqdfxaBWiCuc63mU10oQoIjUJH65te6uhYZ7dYcGowSVuG+NAxX7YB6E /1YeSB2lIuIZ+oiTD12k7TxpVFx8rqzuTCALo8OTiMMDmA96rvEXXO+KjfUsGsUUYEFg 83X6kA+pHwHCWhKBuTSZs/rS2CL3m6I2LsQYRbe9+qtvATaMFY1Dl7XTATYq9XT8uZms cIcA== 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=/SHs86A74kQgXAm8Cf8eNbpIbm3rmErfhH0AnBz65Mg=; b=XJvZQJCxIzN56PAnFkpnrWEs1NH5AfPfzm6p5zmOVB608slrW8Q3cO3BL+XAE8/Di7 0LBKJeRigbFt21bMzgif9JBuXCLBEDIFbjSFnUg/sbZnnoTfFBo1173jEYwQ/xgGd2lz awMKT3j/HSiMKTfwox5EPbbpdDLDb8DLyWRWDNKUgtkIwlsw/UilxdBF4NMYfagEO1at Uu8UIi61EMBnz1LmZ85nNU3V1zKpAgNquxOcnbAApYoQqvOHI2jnGsahT4YRzdewacwC Bewo3gD0Sxd/zra4F6isMKOwsl9tcazuCTCfM9eZJmjAb/9nb6me0sflPhcYYqGIEdtf Cd8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tjtOYHRA; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i4-v6si7320822plt.581.2018.05.18.04.39.45; Fri, 18 May 2018 04:40:02 -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=pass header.i=@gmail.com header.s=20161025 header.b=tjtOYHRA; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752065AbeERLjc (ORCPT + 99 others); Fri, 18 May 2018 07:39:32 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:46834 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751117AbeERLja (ORCPT ); Fri, 18 May 2018 07:39:30 -0400 Received: by mail-qk0-f193.google.com with SMTP id s70-v6so6115756qks.13; Fri, 18 May 2018 04:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/SHs86A74kQgXAm8Cf8eNbpIbm3rmErfhH0AnBz65Mg=; b=tjtOYHRAsAnzPdKf09fkFKcfZF5mtK0bUkmegJxG3sKSBpDQ+oz9E3hLqU+xk2hbXg uT1yfe8OvAvhZ6QE32cbD+pXdGLKTvF9gYJdO+3ktbTMETVZwYnZtQGLqaLZv9MtL/I0 /cgmVdoiIg6RhFZBqAhbDwwKwQxd5/E85Enz4je5Lyb+Z6AkEhJ1YaV2JAhf4n8GfhmM CH7PqDcMl5r4VmQdq+VIS4i3Wo+P02BA4GLzJZwWFAa4P8g0aAacKwxYwNlWG78yvFup bQ9dSnIKQmRIsgRAP5zfvC53lH4xRvuVTjkNQ6N/arIG7QL+kvYwYEsZQ7rprq7naWHt NhZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/SHs86A74kQgXAm8Cf8eNbpIbm3rmErfhH0AnBz65Mg=; b=tuDKCjRO5jUs+fKBQBXPaluxK09OcdbILT4fLsDZ3U9M8fkThJLTX0Knh15Aj5DZtx +V3U9jCvnbmb/Fo7bnB9pXkfkN5gaaEe28MgjlQhxKptNM1qcXLoUd4cY+iEGPSOBUiq 4roIybuVgdK4Gl+NfUoQmvNT7ix1r8aGYIe77s/BMzA4VzpdyAE0C8lcTyoSH9TQacua zEAYaCeZucT92fxkU0dlxhQb/nOl4ZrKEch533BwbwoaypHBcHONAZ+/xZLdf0lDKhb6 JumGMYCyJeinN3MwKJYwX+rtcbq6SOD05M0KsteIQhmG9Q+6eQUfusQ/U8igMJgWI12j ChVQ== X-Gm-Message-State: ALKqPwewAkZim8dSeUIYqbVdKZlbIOS50zcd4VUS7WhRCbCc04wm/pqV Gg68es5+m4c5VQsO1gFtjQ== X-Received: by 2002:a37:c5c4:: with SMTP id k65-v6mr8326089qkl.158.1526643569338; Fri, 18 May 2018 04:39:29 -0700 (PDT) Received: from kmo-pixel (c-71-234-172-214.hsd1.vt.comcast.net. [71.234.172.214]) by smtp.gmail.com with ESMTPSA id 193-v6sm5273354qkh.2.2018.05.18.04.39.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 04:39:27 -0700 (PDT) Date: Fri, 18 May 2018 07:39:25 -0400 From: Kent Overstreet To: Peter Zijlstra 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: <20180518113925.GB16943@kmo-pixel> 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> <20180518110339.GG12217@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180518110339.GG12217@hirez.programming.kicks-ass.net> 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 01:03:39PM +0200, Peter Zijlstra wrote: > 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 ;-) Ok, I think this might work. I'll have to stare awhile and make sure I remember everything I'm currently depending on the lglock for...