From: Al Viro <viro@ZenIV.linux.org.uk>
To: "J. R. Okajima" <hooanon05g@gmail.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: Q. hlist_bl_add_head_rcu() in d_alloc_parallel()
Date: Fri, 17 Jun 2016 23:56:26 +0100 [thread overview]
Message-ID: <20160617225626.GF14480@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20160617221614.GE14480@ZenIV.linux.org.uk>
On Fri, Jun 17, 2016 at 11:16:14PM +0100, Al Viro wrote:
> We are *NOT* modifying the primary hash in d_alloc_parallel(). At all.
> With respect to the primary hash it's a pure reader. And in-lookup hash
> is only accessed under hlist_bl_lock() on its chains - no RCU accesses to
> that one.
Note that if d_alloc_parallel() finds a matching dentry in the in-lookup hash,
it does *NOT* return it until it has left in-lookup hash and had been moved
to the primary one.
That's what d_wait_lookup() call is about; we wait for whoever had added it
into in-lookup hash to be done with it. Then we check if it's been transferred
into the primary hash (with the same name and parent). If it has been,
we treat it as if we'd found it in the primary hash in the first place -
it's not an in-lookup one anymore. If it hasn't, we repeat the whole thing
from scratch, starting with primary hash lookup.
The *only* case when we return an in-lookup dentry is when we had allocated
it, found no matches either in primary or in-lookup hashes and inserted it
into in-lookup hash. What happens is an optimized variant of this:
new = new dentry instance
retry:
fetch the value of ->i_dir_seq
look for match in primary
if found - drop what we'd allocated and return what we'd found
lock the chain in in-lookup hash
check if ->i_dir_seq has changed
if it has changed
unlock the chain
goto retry
look for match in in-lookup hash
if found
unlock the chain
wait for the match to cease being in-lookup
drop the match
goto retry [see below]
insert new into in-lookup hash
unlock the chain
return new
The difference between that and actual d_alloc_parallel() is a simple
optimisation in the last goto retry - the one after waiting for match
to leave in-lookup hash. Pseudocode above would rescan the primary hash;
very often it would end up finding the same dentry we'd just been waiting
for. So if our match is hashed and still has the same name and parent we
can return it without bothering with primary hash lookup. It is common
enough to be worth doing, but it's just an optimisation - behaviour is
the same as if we'd followed d_wait_lookup() with unconditional
spin_unlock(&dentry->d_lock);
dput(dentry);
goto retry;
The only difference is that we don't bother with drop/search in primary/find
and grab the same match in a very common case.
next prev parent reply other threads:[~2016-06-17 22:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-17 20:50 Q. hlist_bl_add_head_rcu() in d_alloc_parallel() J. R. Okajima
2016-06-17 22:16 ` Al Viro
2016-06-17 22:56 ` Al Viro [this message]
2016-06-19 5:24 ` J. R. Okajima
2016-06-19 16:55 ` Al Viro
2016-06-20 4:34 ` J. R. Okajima
2016-06-20 5:35 ` Al Viro
2016-06-20 14:51 ` Al Viro
2016-06-20 17:14 ` [git pull] vfs fixes Al Viro
2016-06-23 1:19 ` Q. hlist_bl_add_head_rcu() in d_alloc_parallel() J. R. Okajima
2016-06-23 2:58 ` Al Viro
2016-06-24 5:57 ` Linus Torvalds
2016-06-25 22:54 ` Al Viro
2016-06-26 1:25 ` Linus Torvalds
2016-06-29 8:17 ` Al Viro
2016-06-29 9:22 ` Hekuang
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=20160617225626.GF14480@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=hooanon05g@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
/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).