Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1432518ybi; Sat, 8 Jun 2019 09:35:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvB31icVeCEfeWqHii+RbBqvG6c32MZZIGU2gIEeVnZ4jeyF3YYD4nZ1Br4okZ53UHqi+l X-Received: by 2002:a63:e70a:: with SMTP id b10mr441796pgi.26.1560011727283; Sat, 08 Jun 2019 09:35:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560011727; cv=none; d=google.com; s=arc-20160816; b=CEnQb0xQz1Bpqvabti+13AnvYHDwZgs+w8o/VeQKIShItfjVnb+x5awt/BUe0GFPBj eAnXItU/5zNif4c+SWSw4fyt8P8cgdKg1/HvxDe7SDzJUm6yMG/S2EGrs6rdRjaDH4WU YxQs04zC+M1x8ZN8B+c6IDhYBAQ0YClagld4W3wZCnLFSzNBvnKDbpeRe3KvGUlwikZ1 zdeaJ+ghF1gbPZUAuLpY5LldhQgPnPBrqzJCdjzLKewSWvSvoal/d9w5fcdzblgpzUFj 4dEauxKd7oJ+n3ys9lOFxC71HK+m6LzZ5yVuRbWl7z1OHhKnGFrFIFpz9bW3SQ/IzMvi hSOw== 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; bh=Nn9sDzgPkR0HabZ31EILcxUmldc30Ih3BqI8IrawHLY=; b=0n99wrgJdztVR83TVmTe6XsL4NsoIhN1Ys8sSsGt2YAbtIrd3H3bGeBf7z4+BuIDQM G7Ns74fkU+VSLKZmxfsa+xVcc3zqdpF1edSOKvknWXHrIj1thpfxScGVEekQJ+0miIbP hzqvW6ZrZoiBJdpPmC2hH1uo89XLuZABxWZoZpMH/wich1BmhprZSwvPdKPpKn0ZNBCM HKR2aHVePY6cCu9A12NR3hyvft0mDqJ0FqMusL8QN+djZDoHSjMagpo+H6Rl/uhu/ul+ NIMayJ3aUEAZzo8bNxyuDScNMAw0ZW7fsV2+wlXv0APqqVLng2M3O07t1kdHEsCNTWyR vtMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=nYhFEYoR; 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 w10si4858028pgs.50.2019.06.08.09.35.10; Sat, 08 Jun 2019 09:35:27 -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=@amarulasolutions.com header.s=google header.b=nYhFEYoR; 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 S1727316AbfFHQdj (ORCPT + 99 others); Sat, 8 Jun 2019 12:33:39 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53733 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727203AbfFHQdj (ORCPT ); Sat, 8 Jun 2019 12:33:39 -0400 Received: by mail-wm1-f67.google.com with SMTP id x15so4821056wmj.3 for ; Sat, 08 Jun 2019 09:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Nn9sDzgPkR0HabZ31EILcxUmldc30Ih3BqI8IrawHLY=; b=nYhFEYoR1lu0BkTY7WHbXXvOZsZhLVA3CoRdDg4f5sDVL1R4bSCV0Cpmoj9BvcRD8o JEjXX6qpEZnl4eZBuLrt1BV4E+nvFxt7x/5FVoI9o1AECCBxb9Y2CGpKtWrbwTyrj6P6 WtLBuXjL2y2TV4i47PrIRZD33itrVhxCj1rw8= 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=Nn9sDzgPkR0HabZ31EILcxUmldc30Ih3BqI8IrawHLY=; b=Q5LnZqMZ6ibTASEXrYWTlXi3dvYhTxSvZFgVlX1ddwwauY2XxmUEImuuoiDuVbi6Ev z++HrcAD7CfLSVQgc97Cwh3wwznIbDmsBSfcJ41xmnu8pbdeAQ9FGAS91rL2rQ3TZEls 6y5EG2UOobWndEyRYXuPqsG5a7ZO9TaXtIlO2KJNgUuT8xJGnez5Y9WJYJPf/OyxM4pl qGfZNrWLRu1nvXxS8kZKM2MJDUexTCce1biBmhQsaipvpkxNOAVsP15rthasYBIgN/k6 +UXo7pbg9QClzlhsHYm2GN3iH3kl3vCne/z7K+UP6cs0A4Kma2hi+yuE6o7LvUATZwh9 wV9A== X-Gm-Message-State: APjAAAUqSmpFY74O3ppvNMQeKPWxUhEDFyUei1mMGDjjKmWrS1p+HHcb nznztW1Byld341l7VwFWl8neRA== X-Received: by 2002:a1c:5f85:: with SMTP id t127mr7494161wmb.104.1560011616260; Sat, 08 Jun 2019 09:33:36 -0700 (PDT) Received: from andrea (ip-86-49-3-71.net.upcbroadband.cz. [86.49.3.71]) by smtp.gmail.com with ESMTPSA id q14sm3930265wrw.60.2019.06.08.09.33.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Jun 2019 09:33:35 -0700 (PDT) Date: Sat, 8 Jun 2019 18:33:26 +0200 From: Andrea Parri To: Nikolay Borisov Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, paulmck@linux.ibm.com Subject: Re: [PATCH 1/2] btrfs: Implement DRW lock Message-ID: <20190608163326.GA6573@andrea> References: <20190606135219.1086-1-nborisov@suse.com> <20190606135219.1086-2-nborisov@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190606135219.1086-2-nborisov@suse.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 06, 2019 at 04:52:18PM +0300, Nikolay Borisov wrote: > A (D)ouble (R)eader (W)riter lock is a locking primitive that allows > to have multiple readers or multiple writers but not multiple readers > and writers holding it concurrently. The code is factored out from > the existing open-coded locking scheme used to exclude pending > snapshots from nocow writers and vice-versa. Current implementation > actually favors Readers (that is snapshot creaters) to writers (nocow > writers of the filesystem). > > Signed-off-by: Nikolay Borisov Interesting! Thank you for sending this over, Nikolay. I only have a couple of nits (below) to add: [...] > + > +void btrfs_drw_read_unlock(struct btrfs_drw_lock *lock) > +{ > + /* > + * Atomic RMW operations imply full barrier, so woken up writers > + * are guaranteed to see the decrement > + */ Not every atomic RMW operations imply a full barrier (as exemplified, e.g., by the atomic_inc() in btrfs_drw_read_lock()); maybe simply s/Atomic RMW operations imply/atomic_dec_and_test() implies/ FYI, checkpatch.pl issues a few warnings on this patch (you may want to address some of them in the next version). Thanks, Andrea > + if (atomic_dec_and_test(&lock->readers)) > + wake_up(&lock->pending_writers); > +} > + > +