Re: [PATCH v2 3/3] nfsd: start non-blocking writeback after adding nfsd_file to the LRU

Jeff Layton
2022-10-28T13:01:57Z

On Fri, 2022-10-28 at 09:25 +1100, NeilBrown wrote:
> On Fri, 28 Oct 2022, Jeff Layton wrote:
> > When a GC entry gets added to the LRU, kick off SYNC_NONE writeback
> > so that we can be ready to close it out when the time comes.
> >
> > Signed-off-by: Jeff Layton <jlayton@kernel.org>
>
> This looks sensible.
> Reviewed-by: NeilBrown <neilb@suse.de>
>
> Thanks,
> NeilBrown
>
>
> > ---
> > fs/nfsd/filecache.c | 37 +++++++++++++++++++++++++++++++------
> > 1 file changed, 31 insertions(+), 6 deletions(-)
> >
> > diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
> > index d2bbded805d4..491d3d9a1870 100644
> > --- a/fs/nfsd/filecache.c
> > +++ b/fs/nfsd/filecache.c
> > @@ -316,7 +316,7 @@ nfsd_file_alloc(struct nfsd_file_lookup_key *key, unsigned int may)
> > }
> >
> > static void
> > -nfsd_file_flush(struct nfsd_file *nf)
> > +nfsd_file_fsync(struct nfsd_file *nf)
> > {
> > struct file *file = nf->nf_file;
> >
> > @@ -327,6 +327,22 @@ nfsd_file_flush(struct nfsd_file *nf)
> > nfsd_reset_write_verifier(net_generic(nf->nf_net, nfsd_net_id));
> > }
> >
> > +static void
> > +nfsd_file_flush(struct nfsd_file *nf)
> > +{
> > + struct file *file = nf->nf_file;
> > + unsigned long nrpages;
> > +
> > + if (!file || !(file->f_mode & FMODE_WRITE))
> > + return;
> > +
> > + nrpages = file->f_mapping->nrpages;
> > + if (nrpages) {
> >

I may change this to:

if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {

I'm not sure here...Does nrpages count all of the pages in the mapping,
or just the dirty ones? I'm wondering if we're overcounting in
nfsd_file_pages_flushed?

> > + this_cpu_add(nfsd_file_pages_flushed, nrpages);
> > + filemap_flush(file->f_mapping);
> > + }
> > +}
> > +
> > static void
> > nfsd_file_free(struct nfsd_file *nf)
> > {
> > @@ -337,7 +353,7 @@ nfsd_file_free(struct nfsd_file *nf)
> > this_cpu_inc(nfsd_file_releases);
> > this_cpu_add(nfsd_file_total_age, age);
> >
> > - nfsd_file_flush(nf);
> > + nfsd_file_fsync(nf);
> >
> > if (nf->nf_mark)
> > nfsd_file_mark_put(nf->nf_mark);
> > @@ -500,12 +516,21 @@ nfsd_file_put(struct nfsd_file *nf)
> >
> > if (test_bit(NFSD_FILE_GC, &nf->nf_flags)) {
> > /*
> > - * If this is the last reference (nf_ref == 1), then transfer
> > - * it to the LRU. If the add to the LRU fails, just put it as
> > - * usual.
> > + * If this is the last reference (nf_ref == 1), then try
> > + * to transfer it to the LRU.
> > + */
> > + if (refcount_dec_not_one(&nf->nf_ref))
> > + return;
> > +
> > + /*
> > + * If the add to the list succeeds, try to kick off SYNC_NONE
> > + * writeback. If the add fails, then just fall through to
> > + * decrement as usual.
> > */
> > - if (refcount_dec_not_one(&nf->nf_ref) || nfsd_file_lru_add(nf))
> > + if (nfsd_file_lru_add(nf)) {
> > + nfsd_file_flush(nf);
> > return;
> > + }
> > }
> > __nfsd_file_put(nf);
> > }
> > --
> > 2.37.3
> >
> >

--
Jeff Layton <jlayton@kernel.org>