From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever III <chuck.lever@oracle.com>
Cc: Linux NFS Mailing List <linux-nfs@vger.kernel.org>,
Neil Brown <neilb@suse.de>
Subject: Re: [PATCH v3] nfsd: rework hashtable handling in nfsd_do_file_acquire
Date: Mon, 03 Oct 2022 10:29:52 -0400 [thread overview]
Message-ID: <5fc85ec6a9ae4c0ef5a1f4f9ea378c0b85f4070f.camel@kernel.org> (raw)
In-Reply-To: <F4DF35B2-CE11-4BD9-8442-97852F57CE2E@oracle.com>
On Mon, 2022-10-03 at 13:11 +0000, Chuck Lever III wrote:
>
> > On Oct 3, 2022, at 7:34 AM, Jeff Layton <jlayton@kernel.org> wrote:
> >
> > nfsd_file is RCU-freed, so we need to hold the rcu_read_lock long enough
> > to get a reference after finding it in the hash. Take the
> > rcu_read_lock() and call rhashtable_lookup directly.
> >
> > Switch to using rhashtable_lookup_insert_key as well, and use the usual
> > retry mechanism if we hit an -EEXIST. Eliminiate the insert_err goto
> > target as well.
>
> The insert_err goto is there to remove a very rare case from
> the hot path. I'd kinda like to keep that feature of this code.
>
IDK. I'm not sold that this goto spaghetti has any value as an
optimization. I can put it back in if you like, but I think eliminating
one of the goto targets here is a good thing.
> The rest of the patch looks good.
>
>
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > ---
> > fs/nfsd/filecache.c | 46 ++++++++++++++++++++-------------------------
> > 1 file changed, 20 insertions(+), 26 deletions(-)
> >
> > diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
> > index be152e3e3a80..63955f3353ed 100644
> > --- a/fs/nfsd/filecache.c
> > +++ b/fs/nfsd/filecache.c
> > @@ -1043,9 +1043,10 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > .need = may_flags & NFSD_FILE_MAY_MASK,
> > .net = SVC_NET(rqstp),
> > };
> > - struct nfsd_file *nf, *new;
> > + struct nfsd_file *nf;
> > bool retry = true;
> > __be32 status;
> > + int ret;
> >
> > status = fh_verify(rqstp, fhp, S_IFREG,
> > may_flags|NFSD_MAY_OWNER_OVERRIDE);
> > @@ -1055,35 +1056,35 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > key.cred = get_current_cred();
> >
> > retry:
> > - /* Avoid allocation if the item is already in cache */
> > - nf = rhashtable_lookup_fast(&nfsd_file_rhash_tbl, &key,
> > - nfsd_file_rhash_params);
> > + rcu_read_lock();
> > + nf = rhashtable_lookup(&nfsd_file_rhash_tbl, &key,
> > + nfsd_file_rhash_params);
> > if (nf)
> > nf = nfsd_file_get(nf);
> > + rcu_read_unlock();
> > if (nf)
> > goto wait_for_construction;
> >
> > - new = nfsd_file_alloc(&key, may_flags);
> > - if (!new) {
> > + nf = nfsd_file_alloc(&key, may_flags);
> > + if (!nf) {
> > status = nfserr_jukebox;
> > goto out_status;
> > }
> >
> > - nf = rhashtable_lookup_get_insert_key(&nfsd_file_rhash_tbl,
> > - &key, &new->nf_rhash,
> > - nfsd_file_rhash_params);
> > - if (!nf) {
> > - nf = new;
> > - goto open_file;
> > - }
> > - if (IS_ERR(nf))
> > - goto insert_err;
> > - nf = nfsd_file_get(nf);
> > - if (nf == NULL) {
> > - nf = new;
> > + ret = rhashtable_lookup_insert_key(&nfsd_file_rhash_tbl,
> > + &key, &nf->nf_rhash,
> > + nfsd_file_rhash_params);
> > + if (ret == 0)
> > goto open_file;
> > +
> > + nfsd_file_slab_free(&nf->nf_rcu);
> > + if (retry && ret == EEXIST) {
> > + retry = false;
> > + goto retry;
> > }
> > - nfsd_file_slab_free(&new->nf_rcu);
> > + trace_nfsd_file_insert_err(rqstp, key.inode, may_flags, ret);
> > + status = nfserr_jukebox;
> > + goto out_status;
> >
> > wait_for_construction:
> > wait_on_bit(&nf->nf_flags, NFSD_FILE_PENDING, TASK_UNINTERRUPTIBLE);
> > @@ -1143,13 +1144,6 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
> > smp_mb__after_atomic();
> > wake_up_bit(&nf->nf_flags, NFSD_FILE_PENDING);
> > goto out;
> > -
> > -insert_err:
> > - nfsd_file_slab_free(&new->nf_rcu);
> > - trace_nfsd_file_insert_err(rqstp, key.inode, may_flags, PTR_ERR(nf));
> > - nf = NULL;
> > - status = nfserr_jukebox;
> > - goto out_status;
> > }
> >
> > /**
> > --
> > 2.37.3
> >
>
> --
> Chuck Lever
>
>
>
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2022-10-03 14:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-03 11:34 [PATCH v3] nfsd: rework hashtable handling in nfsd_do_file_acquire Jeff Layton
2022-10-03 13:11 ` Chuck Lever III
2022-10-03 14:29 ` Jeff Layton [this message]
2022-10-03 22:07 ` NeilBrown
2022-10-04 13:28 ` Chuck Lever III
2022-10-04 23:06 ` NeilBrown
2022-10-03 22:04 ` NeilBrown
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=5fc85ec6a9ae4c0ef5a1f4f9ea378c0b85f4070f.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
/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).