linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fox Chen <foxhlchen@gmail.com>
To: Ian Kent <raven@themaw.net>
Cc: Tejun Heo <tj@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rick Lindsley <ricklind@linux.vnet.ibm.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	David Howells <dhowells@redhat.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH 5/6] kernfs: stay in rcu-walk mode if possible
Date: Fri, 5 Feb 2021 16:23:02 +0800	[thread overview]
Message-ID: <CAC2o3DKc0expAJAiNHnU5dY8hpom4z6TdRegQxahRBrZKL+7qg@mail.gmail.com> (raw)
In-Reply-To: <160862330474.291330.11664503360150456908.stgit@mickey.themaw.net>

Hi Ian,

On Tue, Dec 22, 2020 at 3:48 PM Ian Kent <raven@themaw.net> wrote:
>
> During path walks in sysfs (kernfs) needing to take a reference to
> a mount doesn't happen often since the walk won't be crossing mount
> point boundaries.
>
> Also while staying in rcu-walk mode where possible wouldn't normally
> give much improvement.
>
> But when there are many concurrent path walks and there is high d_lock
> contention dget() will often need to resort to taking a spin lock to
> get the reference. And that could happen each time the reference is
> passed from component to component.
>
> So, in the high contention case, it will contribute to the contention.
>
> Therefore staying in rcu-walk mode when possible will reduce contention.
>
> Signed-off-by: Ian Kent <raven@themaw.net>
> ---
>  fs/kernfs/dir.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 47 insertions(+), 1 deletion(-)
>
> diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
> index fdeae2c6e7ba..50c5c8c886af 100644
> --- a/fs/kernfs/dir.c
> +++ b/fs/kernfs/dir.c
> @@ -1048,8 +1048,54 @@ static int kernfs_dop_revalidate(struct dentry *dentry, unsigned int flags)
>         struct kernfs_node *parent;
>         struct kernfs_node *kn;
>
> -       if (flags & LOOKUP_RCU)
> +       if (flags & LOOKUP_RCU) {
> +               parent = kernfs_dentry_node(dentry->d_parent);
> +
> +               /* Directory node changed, no, then don't search? */
> +               if (!kernfs_dir_changed(parent, dentry))
> +                       return 1;
> +
> +               kn = kernfs_dentry_node(dentry);
> +               if (!kn) {
> +                       /* Negative hashed dentry, tell the VFS to switch to
> +                        * ref-walk mode and call us again so that node
> +                        * existence can be checked.
> +                        */
> +                       if (!d_unhashed(dentry))
> +                               return -ECHILD;
> +
> +                       /* Negative unhashed dentry, this shouldn't happen
> +                        * because this case occurs in ref-walk mode after
> +                        * dentry allocation which is followed by a call
> +                        * to ->loopup(). But if it does happen the dentry
> +                        * is surely invalid.
> +                        */
> +                       return 0;
> +               }
> +
> +               /* Since the dentry is positive (we got the kernfs node) a
> +                * kernfs node reference was held at the time. Now if the
> +                * dentry reference count is still greater than 0 it's still
> +                * positive so take a reference to the node to perform an
> +                * active check.
> +                */
> +               if (d_count(dentry) <= 0 || !atomic_inc_not_zero(&kn->count))
> +                       return -ECHILD;
> +
> +               /* The kernfs node reference count was greater than 0, if
> +                * it's active continue in rcu-walk mode.
> +                */
> +               if (kernfs_active_read(kn)) {
We are in RCU-walk mode, kernfs_rwsem should not be held, however,
kernfs_active_read will assert the readlock is held. I believe it
should be kernfs_active(kn) here. Am I wrong??

> +                       kernfs_put(kn);
> +                       return 1;
> +               }
> +
> +               /* Otherwise, just tell the VFS to switch to ref-walk mode
> +                * and call us again so the kernfs node can be validated.
> +                */
> +               kernfs_put(kn);
>                 return -ECHILD;
> +       }
>
>         down_read(&kernfs_rwsem);
>
>
>

thanks,
fox

  reply	other threads:[~2021-02-05  8:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-22  7:47 [PATCH 0/6] kernfs: proposed locking and concurrency improvement Ian Kent
2020-12-22  7:47 ` [PATCH 1/6] kernfs: move revalidate to be near lookup Ian Kent
2020-12-22  7:47 ` [PATCH 2/6] kernfs: use VFS negative dentry caching Ian Kent
2020-12-22  7:47 ` [PATCH 3/6] kernfs: use revision to identify directory node changes Ian Kent
2020-12-22  7:48 ` [PATCH 4/6] kernfs: switch kernfs to use an rwsem Ian Kent
2020-12-22  7:48 ` [PATCH 5/6] kernfs: stay in rcu-walk mode if possible Ian Kent
2021-02-05  8:23   ` Fox Chen [this message]
2021-02-05 12:10     ` Ian Kent
2020-12-22  7:48 ` [PATCH 6/6] kernfs: add a spinlock to kernfs iattrs for inode updates Ian Kent
2020-12-24  6:23   ` [kernfs] ca0f27ecb7: BUG:kernel_NULL_pointer_dereference,address kernel test robot
2020-12-23  7:30 ` [PATCH 0/6] kernfs: proposed locking and concurrency improvement Fox Chen
2021-01-04  0:42   ` Ian Kent
2021-01-06  2:38     ` Fox Chen
2021-01-11  3:19       ` Ian Kent
2021-01-11  4:20         ` Ian Kent
2021-01-11  7:04           ` Fox Chen
2021-01-11  8:42             ` Ian Kent
2021-01-11  9:02               ` Fox Chen
2021-01-12  0:27                 ` Ian Kent
2021-01-13  5:17                 ` Ian Kent
2021-01-13  7:00                   ` Fox Chen
2021-01-13  7:47                     ` Ian Kent
2021-01-13  7:50                       ` Ian Kent
2021-01-13  8:00                         ` Fox Chen
2021-01-14  3:20                           ` Fox Chen
2021-01-14  5:37                           ` Ian Kent

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=CAC2o3DKc0expAJAiNHnU5dY8hpom4z6TdRegQxahRBrZKL+7qg@mail.gmail.com \
    --to=foxhlchen@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=raven@themaw.net \
    --cc=ricklind@linux.vnet.ibm.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).