All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Guo Chao <yan@linux.vnet.ibm.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [RFC v4 Patch 0/4] fs/inode.c: optimization for inode lock usage
Date: Thu, 27 Sep 2012 21:51:28 +1000	[thread overview]
Message-ID: <20120927115128.GT15236@dastard> (raw)
In-Reply-To: <20120927084148.GA29769@yanx>

On Thu, Sep 27, 2012 at 04:41:48PM +0800, Guo Chao wrote:
> On Wed, Sep 26, 2012 at 10:54:09AM +1000, Dave Chinner wrote:
> > On Tue, Sep 25, 2012 at 04:59:55PM +0800, Guo Chao wrote:
> > > > @@ -1078,8 +1098,7 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino)
> > > >  		struct inode *old;
> > > > 
> > > >  		spin_lock(&inode_hash_lock);
> > > > -		/* We released the lock, so.. */
> > > > -		old = find_inode_fast(sb, head, ino);
> > > > +		old = find_inode_fast(sb, head, ino, true);
> > > >  		if (!old) {
> > > >  			inode->i_ino = ino;
> > > >  			spin_lock(&inode->i_lock);
> > > 
> > > Emmmm ... couldn't we use memory barrier API instead of irrelevant spin
> > > lock on newly allocated inode to publish I_NEW?
> > 
> > Yes, we could.
> > 
> > However, having multiple synchronisation methods for a single
> > variable that should only be used in certain circumstances is
> > something that is easy to misunderstand and get wrong. Memory
> > barriers are much more subtle and harder to understand than spin
> > locks, and every memory barrier needs to be commented to explain
> > what the barrier is actually protecting against.
> > 
> > In the case where a spin lock is guaranteed to be uncontended and
> > the cache line hot in the CPU cache, it makes no sense to replace
> > the spin lock with a memory barrier, especially when every other
> > place we modify the i_state/i_hash fields we have to wrap them
> > with i_lock....
> > 
> > Simple code is good code - save the complexity for something that
> > needs it.
> > 
> 
> Emmm, I doubt "it's simpler and need no document". 

It is simpler because it follows the documented locking rules. THey
are right at the top of fs/inode.c:

/*
 * Inode locking rules:
 *
 * inode->i_lock protects:
 *   inode->i_state, inode->i_hash, __iget()
.....
 * Lock ordering:
.....
 * inode_hash_lock
 *   inode_sb_list_lock
 *   inode->i_lock
 *
.....

If you think it's simpler to have multiple access and update rules
for the same fields that can only be applied in certain
circumstances and can document it as such, then I look forward to
reviewing the patch. :)

> I bet someday there will be other guys stand out and ask "why take spin 
> lock on a inode which apparently does not subject to any race condition?". 

And we now have a thread to point them at so we don't have to
explain it again. :)

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

      reply	other threads:[~2012-09-27 11:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-21  9:31 [RFC v4 Patch 0/4] fs/inode.c: optimization for inode lock usage Guo Chao
2012-09-21  9:31 ` [PATCH 1/4] fs/inode.c: do not take i_lock on newly allocated inode Guo Chao
2012-09-21  9:31 ` [PATCH 2/4] fs/inode.c: do not take i_lock in __(insert|remove)_inode_hash Guo Chao
2012-09-21  9:31 ` [PATCH 3/4] fs/inode.c: do not take i_lock when identify an inode Guo Chao
2012-09-21  9:31 ` [PATCH 4/4] fs/inode.c: always take i_lock before calling filesystem's test() method Guo Chao
2012-09-21 12:17 ` [RFC v4 Patch 0/4] fs/inode.c: optimization for inode lock usage Matthew Wilcox
2012-09-21 22:49 ` Dave Chinner
2012-09-24  2:42   ` Guo Chao
2012-09-24  4:23     ` Dave Chinner
2012-09-24  6:12       ` Guo Chao
2012-09-24  6:28         ` Dave Chinner
2012-09-24  7:08           ` Guo Chao
2012-09-24  8:26             ` Dave Chinner
2012-09-25  8:59               ` Guo Chao
2012-09-26  0:54                 ` Dave Chinner
2012-09-27  8:41                   ` Guo Chao
2012-09-27 11:51                     ` Dave Chinner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120927115128.GT15236@dastard \
    --to=david@fromorbit.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=yan@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.