From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752217AbeBVF3J (ORCPT ); Thu, 22 Feb 2018 00:29:09 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:40824 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750725AbeBVF3I (ORCPT ); Thu, 22 Feb 2018 00:29:08 -0500 Date: Thu, 22 Feb 2018 05:29:06 +0000 From: Al Viro To: John Ogness Cc: Linus Torvalds , linux-fsdevel , Christoph Hellwig , Thomas Gleixner , Peter Zijlstra , Sebastian Andrzej Siewior , Linux Kernel Mailing List Subject: Re: [PATCH 4/4] fs/dcache: Avoid the try_lock loops in dentry_kill() Message-ID: <20180222052906.GM30522@ZenIV.linux.org.uk> References: <20180216150933.971-1-john.ogness@linutronix.de> <20180216150933.971-5-john.ogness@linutronix.de> <87y3js36s7.fsf@linutronix.de> <87r2pk358g.fsf@linutronix.de> <87lgfs3374.fsf@linutronix.de> <878tbov9i6.fsf@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878tbov9i6.fsf@linutronix.de> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 20, 2018 at 12:34:57AM +0100, John Ogness wrote: > Implementation 3: The same as implementation 2 but using if's to > support branch prediction. This approach is probably the most > complicated to understand but will be the fastest. > > /* > * Lock the inode. Might drop dentry->d_lock temporarily > * which allows inode to change. Start over if that happens. > */ > int ret = dentry_lock_inode(dentry); > if (unlikely(ret != LOCK_FAST)) { > if (ret == LOCK_FAILED) > goto again; > /* > * Recheck refcount as it might have been > * incremented while d_lock was dropped. > */ > if (dentry->d_lockref.count != 1) > goto drop_ref; > } Implementation 4: screw the tristate, move the loop inside dentry_lock_inode(). > If lock_parent() returns a non-NULL, it is returning > dentry->d_parent. So the return value is really just a boolean and the > locked parent is the parent of the dentry. The function is a little bit > tricky because it could return NULL (lock failed) even if the dentry has > a non-NULL d_parent. So any caller using a tristate return variation of > lock_parent() must rely on the return value instead of a non-NULL > dentry->d_parent. dentry always has non-NULL ->d_parent; it might point to dentry itself, but it's never NULL. > if (!dentry->d_lockref.count) { > - struct dentry *parent = lock_parent(dentry); > + int ret = lock_parent(dentry); > + parent = dentry->d_parent; > if (likely(!dentry->d_lockref.count)) { > __dentry_kill(dentry); > dput(parent); Broken. In IS_ROOT case you'll hit an extra dput() on dentry itself. dput(NULL) is no-op; this, OTOH, isn't.