linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Andrew Morton <akpm@osdl.org>
Cc: David Howells <dhowells@redhat.com>,
	torvalds@osdl.org, steved@redhat.com, trond.myklebust@fys.uio.no,
	aviro@redhat.com, linux-fsdevel@vger.kernel.org,
	linux-cachefs@redhat.com, nfsv4@linux-nfs.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 7/5] Optimise d_find_alias()
Date: Fri, 3 Mar 2006 07:48:04 -0700	[thread overview]
Message-ID: <20060303144804.GJ1598@parisc-linux.org> (raw)
In-Reply-To: <20060303034552.5fcedc49.akpm@osdl.org>

On Fri, Mar 03, 2006 at 03:45:52AM -0800, Andrew Morton wrote:
> David Howells <dhowells@redhat.com> wrote:
> >  struct dentry * d_find_alias(struct inode *inode)
> >   {
> >  -	struct dentry *de;
> >  -	spin_lock(&dcache_lock);
> >  -	de = __d_find_alias(inode, 0);
> >  -	spin_unlock(&dcache_lock);
> >  +	struct dentry *de = NULL;
> >  +	if (!list_empty(&inode->i_dentry)) {
> >  +		spin_lock(&dcache_lock);
> >  +		de = __d_find_alias(inode, 0);
> >  +		spin_unlock(&dcache_lock);
> >  +	}
> >   	return de;
> >   }
> 
> How can we get away without a barrier?

We'd have to be synchronised higher up in order to care, I think.

The condition we're testing is !list_empty(&inode->i_dentry)
which will presumably be optimised by the compiler into
inode->i_dentry.next != &inode->i_dentry -- IOW determined by a single
load.

Both false negatives and false positives are interesting, so we're
concerned with any write from another CPU that changes inode->i_dentry.next 
d_instantiate() looks like a good candidate for analysing races.

CPU1				CPU2

d_instantiate()
spin_lock(&dcache_lock);
				
				d_find_alias()
				if (!list_empty(&inode->i_dentry)) {
list_add(&entry->d_alias, &inode->i_dentry);
spin_unlock(&dcache_lock);
					spin_lock(&dcache_lock);
					__d_find_alias()
					spin_unlock(&dcache_lock);
				}

I don't see how putting a barrier in helps determine whether the
list_add is before or after the load for list_empty.  So I think it's
a  benign race.  If it returns NULL, it's the same as the case where
d_instantiate() is called after __d_find_alias() returns.  If
list_empty() is false, grabbing the dcache_lock means we'll find the
list really is empty after all.

So it's not a correctness thing, it's a question of how many times we
lose the race, and what the performance penalty is for doing so (and what
the performance penalty is for ensuring we lose the race less often).
And I don't know the answer to that.

  reply	other threads:[~2006-03-03 14:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-02 21:33 [PATCH 0/5] Permit NFS superblock sharing [try #3] David Howells
2006-03-02 21:33 ` [PATCH 1/5] NFS: Permit filesystem to override root dentry on mount " David Howells
2006-03-02 21:34 ` [PATCH 2/5] NFS: Apply mount root dentry override to filesystems " David Howells
2006-03-02 21:34 ` [PATCH 3/5] NFS: Abstract out namespace initialisation " David Howells
2006-03-02 21:34 ` [PATCH 4/5] NFS: Add dentry materialisation op " David Howells
2006-03-02 21:34 ` [PATCH 5/5] NFS: Unify NFS superblocks per-protocol per-server " David Howells
2006-03-03  3:22   ` Andrew Morton
2006-03-02 22:07 ` [PATCH 0/5] Permit NFS superblock sharing " Linus Torvalds
2006-03-03  9:59 ` [PATCH 5/5] NFS: Unify NFS superblocks per-protocol per-server [try #3a] David Howells
2006-03-03 10:49 ` [PATCH 6/5] 9p: Fix error handling on superblock alloc failure David Howells
2006-03-03 11:30 ` [PATCH 7/5] Optimise d_find_alias() David Howells
2006-03-03 11:45   ` Andrew Morton
2006-03-03 14:48     ` Matthew Wilcox [this message]
2006-03-03 15:46     ` Al Viro
2006-03-03 13:00   ` David Howells
2006-03-03 15:43     ` Ingo Molnar
2006-03-03 13:01   ` David Howells
2006-03-03 13:38 ` [PATCH 7/5] Optimise d_find_alias() [try #2] David Howells
2006-03-04 12:16 ` [PATCH 0/5] Permit NFS superblock sharing [try #3] Andrew Morton
2006-03-06 11:55 ` David Howells
2006-03-06 13:57   ` Jörn Engel
2006-03-06 15:25   ` Linus Torvalds
2006-03-06 14:03 ` [PATCH 1/5] NFS: Permit filesystem to override root dentry on mount [try #4] David Howells
2006-03-06 14:59 ` [PATCH 1+2/5] NFS: Permit filesystem to override root dentry on mount [try #5] David Howells
2006-03-07 11:08 ` [PATCH] Fix multiple blockdev-based filesystem mounts David Howells
2006-03-07 11:35   ` Alexander Viro
2006-03-07 13:23   ` David Howells
2006-05-23 16:53 ` [PATCH 0/5] Permit NFS superblock sharing [try #3] David Howells

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=20060303144804.GJ1598@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=akpm@osdl.org \
    --cc=aviro@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nfsv4@linux-nfs.org \
    --cc=steved@redhat.com \
    --cc=torvalds@osdl.org \
    --cc=trond.myklebust@fys.uio.no \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).