All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: NeilBrown <neilb@suse.de>
Cc: chuck.lever@oracle.com, linux-nfs@vger.kernel.org
Subject: Re: [PATCH v2 2/3] nfsd: only keep unused entries on the LRU
Date: Thu, 27 Oct 2022 18:47:21 -0400	[thread overview]
Message-ID: <dd3936feb109857040ad79e7da47d7b7e5732a41.camel@kernel.org> (raw)
In-Reply-To: <166690925944.13915.14734120966513564215@noble.neil.brown.name>

On Fri, 2022-10-28 at 09:20 +1100, NeilBrown wrote:
> On Fri, 28 Oct 2022, Jeff Layton wrote:
> > Currently, nfsd_files live on the LRU once they are added until they are
> > unhashed. There's no need to keep ones that are actively in use there.
> 
> Is that true?
> nfsd_file_do_acquire() calls nfsd_file_lru_remove()
> Isn't that enough to keep the file off the lru while it is active?
> 
> Thanks,
> NeilBrown
> 

After patch #1, it doesn't call that anymore. That's probably a (minor)
regression then.

After patch #1, the LRU holds a reference. If you successfully remove it
from the LRU, you need to transfer or put that reference. Doing the LRU
handling in the get and put routines seems more natural, I think.

Maybe I just need to squash this patch into #1?

> 
> > 
> > Before incrementing the refcount, do a lockless check for nf_lru being
> > empty. If it's not then attempt to remove the entry from the LRU. If
> > that's successful, claim the LRU reference and return it. If the removal
> > fails (or if the list_head was empty), then just increment the counter
> > as we normally would.
> > 
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
> > ---
> >  fs/nfsd/filecache.c | 23 ++++++++++++++++++++---
> >  1 file changed, 20 insertions(+), 3 deletions(-)
> > 
> > diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
> > index e63534f4b9f8..d2bbded805d4 100644
> > --- a/fs/nfsd/filecache.c
> > +++ b/fs/nfsd/filecache.c
> > @@ -420,14 +420,31 @@ nfsd_file_unhash(struct nfsd_file *nf)
> >  	return false;
> >  }
> >  
> > -struct nfsd_file *
> > -nfsd_file_get(struct nfsd_file *nf)
> > +static struct nfsd_file *
> > +__nfsd_file_get(struct nfsd_file *nf)
> >  {
> >  	if (likely(refcount_inc_not_zero(&nf->nf_ref)))
> >  		return nf;
> >  	return NULL;
> >  }
> >  
> > +struct nfsd_file *
> > +nfsd_file_get(struct nfsd_file *nf)
> > +{
> > +	/*
> > +	 * Do a lockless list_empty check first, before attempting to
> > +	 * remove it, so we can avoid the spinlock when it's not on the
> > +	 * list.
> > +	 *
> > +	 * If we successfully remove it from the LRU, then we can just
> > +	 * claim the LRU reference and return it. Otherwise, we need to
> > +	 * bump the counter the old-fashioned way.
> > +	 */
> > +	if (!list_empty(&nf->nf_lru) && nfsd_file_lru_remove(nf))
> > +		return nf;
> > +	return __nfsd_file_get(nf);
> > +}
> > +
> >  /**
> >   * nfsd_file_unhash_and_queue - unhash a file and queue it to the dispose list
> >   * @nf: nfsd_file to be unhashed and queued
> > @@ -449,7 +466,7 @@ nfsd_file_unhash_and_queue(struct nfsd_file *nf, struct list_head *dispose)
> >  		 * to take a reference. If that fails, just ignore
> >  		 * the file altogether.
> >  		 */
> > -		if (!nfsd_file_lru_remove(nf) && !nfsd_file_get(nf))
> > +		if (!nfsd_file_lru_remove(nf) && !__nfsd_file_get(nf))
> >  			return false;
> >  		list_add(&nf->nf_lru, dispose);
> >  		return true;
> > -- 
> > 2.37.3
> > 
> > 

-- 
Jeff Layton <jlayton@kernel.org>

  reply	other threads:[~2022-10-27 22:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-27 21:52 [PATCH v2 0/3] nfsd: clean up refcounting in filecache Jeff Layton
2022-10-27 21:52 ` [PATCH v2 1/3] nfsd: rework " Jeff Layton
2022-10-27 22:51   ` NeilBrown
2022-10-28  9:57     ` Jeff Layton
2022-10-28 22:14       ` NeilBrown
2022-10-30 21:29         ` NeilBrown
2022-10-31  9:58           ` Jeff Layton
2022-10-31  9:54         ` Jeff Layton
2022-10-27 21:52 ` [PATCH v2 2/3] nfsd: only keep unused entries on the LRU Jeff Layton
2022-10-27 22:20   ` NeilBrown
2022-10-27 22:47     ` Jeff Layton [this message]
2022-10-27 22:55       ` NeilBrown
2022-10-27 23:52         ` Chuck Lever III
2022-10-27 21:52 ` [PATCH v2 3/3] nfsd: start non-blocking writeback after adding nfsd_file to " Jeff Layton
2022-10-27 22:25   ` NeilBrown
2022-10-28 13:01     ` Jeff Layton
2022-10-28 13:16   ` Chuck Lever III
2022-10-28 15:05     ` Jeff Layton
2022-10-28 15:29       ` Chuck Lever III
2022-10-28 15:51         ` Jeff Layton
2022-10-28 17:21           ` Chuck Lever III
2022-10-28 17:43             ` Jeff Layton
2022-10-28 18:53               ` Chuck Lever III
2022-10-28 20:04                 ` Jeff Layton

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=dd3936feb109857040ad79e7da47d7b7e5732a41.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 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.