From: Trond Myklebust <trondmy@hammerspace.com>
To: "bcodding@redhat.com" <bcodding@redhat.com>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH v7 05/21] NFS: Store the change attribute in the directory page cache
Date: Fri, 25 Feb 2022 02:26:32 +0000 [thread overview]
Message-ID: <1ca16f7e7be9588d15525e3afa4f7a80eb66b12b.camel@hammerspace.com> (raw)
In-Reply-To: <0DBE97BF-3A88-49FD-B078-012B5EDA5849@redhat.com>
On Thu, 2022-02-24 at 09:53 -0500, Benjamin Coddington wrote:
> On 23 Feb 2022, at 16:12, trondmy@kernel.org wrote:
>
> > From: Trond Myklebust <trond.myklebust@hammerspace.com>
> >
> > Use the change attribute and the first cookie in a directory page
> > cache
> > entry to validate that the page is up to date.
> >
> > Suggested-by: Benjamin Coddington <bcodding@redhat.com>
> > Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
> > ---
> > fs/nfs/dir.c | 68
> > ++++++++++++++++++++++++++++------------------------
> > 1 file changed, 37 insertions(+), 31 deletions(-)
> >
> > diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> > index f2258e926df2..5d9367d9b651 100644
> > --- a/fs/nfs/dir.c
> > +++ b/fs/nfs/dir.c
> > @@ -139,6 +139,7 @@ struct nfs_cache_array_entry {
> > };
> >
> > struct nfs_cache_array {
> > + u64 change_attr;
> > u64 last_cookie;
> > unsigned int size;
> > unsigned char page_full : 1,
> > @@ -175,7 +176,8 @@ static void nfs_readdir_array_init(struct
> > nfs_cache_array *array)
> > memset(array, 0, sizeof(struct nfs_cache_array));
> > }
> >
> > -static void nfs_readdir_page_init_array(struct page *page, u64
> > last_cookie)
> > +static void nfs_readdir_page_init_array(struct page *page, u64
> > last_cookie,
> > + u64 change_attr)
> > {
> > struct nfs_cache_array *array;
>
>
> There's a hunk missing here, something like:
>
> @@ -185,6 +185,7 @@ static void nfs_readdir_page_init_array(struct
> page
> *page, u64 last_cookie,
> nfs_readdir_array_init(array);
> array->last_cookie = last_cookie;
> array->cookies_are_ordered = 1;
> + array->change_attr = change_attr;
> kunmap_atomic(array);
> }
>
> >
> > @@ -207,7 +209,7 @@ nfs_readdir_page_array_alloc(u64 last_cookie,
> > gfp_t gfp_flags)
> > {
> > struct page *page = alloc_page(gfp_flags);
> > if (page)
> > - nfs_readdir_page_init_array(page, last_cookie);
> > + nfs_readdir_page_init_array(page, last_cookie, 0);
> > return page;
> > }
> >
> > @@ -304,19 +306,44 @@ int nfs_readdir_add_to_array(struct nfs_entry
> > *entry, struct page *page)
> > return ret;
> > }
> >
> > +static bool nfs_readdir_page_cookie_match(struct page *page, u64
> > last_cookie,
> > + u64 change_attr)
>
> How about "nfs_readdir_page_valid()"? There's more going on than a
> cookie match.
>
>
> > +{
> > + struct nfs_cache_array *array = kmap_atomic(page);
> > + int ret = true;
> > +
> > + if (array->change_attr != change_attr)
> > + ret = false;
>
> Can we skip the next test if ret = false?
I'd expect the compiler to do that.
>
> > + if (array->size > 0 && array->array[0].cookie !=
> > last_cookie)
> > + ret = false;
> > + kunmap_atomic(array);
> > + return ret;
> > +}
> > +
> > +static void nfs_readdir_page_unlock_and_put(struct page *page)
> > +{
> > + unlock_page(page);
> > + put_page(page);
> > +}
> > +
> > static struct page *nfs_readdir_page_get_locked(struct
> > address_space
> > *mapping,
> > pgoff_t index, u64
> > last_cookie)
> > {
> > struct page *page;
> > + u64 change_attr;
> >
> > page = grab_cache_page(mapping, index);
> > - if (page && !PageUptodate(page)) {
> > - nfs_readdir_page_init_array(page, last_cookie);
> > - if (invalidate_inode_pages2_range(mapping, index +
> > 1, -1) < 0)
> > - nfs_zap_mapping(mapping->host, mapping);
> > - SetPageUptodate(page);
> > + if (!page)
> > + return NULL;
> > + change_attr = inode_peek_iversion_raw(mapping->host);
> > + if (PageUptodate(page)) {
> > + if (nfs_readdir_page_cookie_match(page,
> > last_cookie,
> > + change_attr))
> > + return page;
> > + nfs_readdir_clear_array(page);
>
>
> Why use i_version rather than nfs_save_change_attribute? Seems
> having a
> consistent value across the pachecache and dir_verifiers would help
> debugging, and we've already have a bunch of machinery around the
> change_attribute.
The directory cache_change_attribute is not reported in tracepoints
because it is a directory-specific field, so it's not as useful for
debugging.
The inode change attribute is what we have traditionally used for
determining cache consistency, and when to invalidate the cache.
>
> Don't we need to send a GETATTR with READDIR for v4? Not doing so
> means
> that the pagecache is going to behave differently for v3 and v4, and
> we'll
> potentially end up with totally bogus listings for cases where one
> reader
> has cached a page of entries in the middle of the pagecache marked
> with
> i_version A, but entries are actually from i_version A++ on the
> server.
> Then another reader comes along and follows earlier entries from
> i_version A
> on the server that lead into entries from A++. I don't think we can
> detect
> this case unless we're checking the directory on every READDIR.
The value of the change attribute is determined when the page is
allocated. That value is unaffected by the READDIR call.
That works with NFSv2 as well as NFSv3+v4.
>
> Sending a GETATTR for v4 doesn't eliminate that race on the server
> side,
> but
> does remove the large window on the client created by the attribute
> cache
> timeouts, and I think its mostly harmless performance-wise.
>
> Also, we don't need the local change_attr variable just to pass it to
> other
> functions that can access it themselves.
>
> > }
> > -
> > + nfs_readdir_page_init_array(page, last_cookie,
> > change_attr);
> > + SetPageUptodate(page);
> > return page;
> > }
> >
> > @@ -356,12 +383,6 @@ static void nfs_readdir_page_set_eof(struct
> > page
> > *page)
> > kunmap_atomic(array);
> > }
> >
> > -static void nfs_readdir_page_unlock_and_put(struct page *page)
> > -{
> > - unlock_page(page);
> > - put_page(page);
> > -}
> > -
> > static struct page *nfs_readdir_page_get_next(struct address_space
> > *mapping,
> > pgoff_t index, u64
> > cookie)
> > {
> > @@ -418,16 +439,6 @@ static int nfs_readdir_search_for_pos(struct
> > nfs_cache_array *array,
> > return -EBADCOOKIE;
> > }
> >
> > -static bool
> > -nfs_readdir_inode_mapping_valid(struct nfs_inode *nfsi)
> > -{
> > - if (nfsi->cache_validity & (NFS_INO_INVALID_CHANGE |
> > - NFS_INO_INVALID_DATA))
> > - return false;
> > - smp_rmb();
> > - return !test_bit(NFS_INO_INVALIDATING, &nfsi->flags);
> > -}
> > -
> > static bool nfs_readdir_array_cookie_in_range(struct
> > nfs_cache_array
> > *array,
> > u64 cookie)
> > {
> > @@ -456,8 +467,7 @@ static int nfs_readdir_search_for_cookie(struct
> > nfs_cache_array *array,
> > struct nfs_inode *nfsi =
> > NFS_I(file_inode(desc->file));
> >
> > new_pos = nfs_readdir_page_offset(desc-
> > >page) + i;
> > - if (desc->attr_gencount != nfsi-
> > >attr_gencount ||
> > - !nfs_readdir_inode_mapping_valid(nfsi))
> > {
> > + if (desc->attr_gencount != nfsi-
> > >attr_gencount) {
> > desc->duped = 0;
> > desc->attr_gencount = nfsi-
> > >attr_gencount;
> > } else if (new_pos < desc->prev_index) {
> > @@ -1094,11 +1104,7 @@ static int nfs_readdir(struct file *file,
> > struct dir_context *ctx)
> > * to either find the entry with the appropriate number or
> > * revalidate the cookie.
> > */
> > - if (ctx->pos == 0 || nfs_attribute_cache_expired(inode)) {
> > - res = nfs_revalidate_mapping(inode, file-
> > >f_mapping);
> > - if (res < 0)
> > - goto out;
> > - }
> > + nfs_revalidate_inode(inode, NFS_INO_INVALID_CHANGE);
>
> Same as above -> why not send GETATTR with READDIR instead of doing
> it
> in a
> separate RPC?
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com
next prev parent reply other threads:[~2022-02-25 2:26 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 21:12 [PATCH v7 00/21] Readdir improvements trondmy
2022-02-23 21:12 ` [PATCH v7 01/21] NFS: constify nfs_server_capable() and nfs_have_writebacks() trondmy
2022-02-23 21:12 ` [PATCH v7 02/21] NFS: Trace lookup revalidation failure trondmy
2022-02-23 21:12 ` [PATCH v7 03/21] NFS: Use kzalloc() to avoid initialising the nfs_open_dir_context trondmy
2022-02-23 21:12 ` [PATCH v7 04/21] NFS: Calculate page offsets algorithmically trondmy
2022-02-23 21:12 ` [PATCH v7 05/21] NFS: Store the change attribute in the directory page cache trondmy
2022-02-23 21:12 ` [PATCH v7 06/21] NFS: If the cookie verifier changes, we must invalidate the " trondmy
2022-02-23 21:12 ` [PATCH v7 07/21] NFS: Don't re-read the entire page cache to find the next cookie trondmy
2022-02-23 21:12 ` [PATCH v7 08/21] NFS: Adjust the amount of readahead performed by NFS readdir trondmy
2022-02-23 21:12 ` [PATCH v7 09/21] NFS: Simplify nfs_readdir_xdr_to_array() trondmy
2022-02-23 21:12 ` [PATCH v7 10/21] NFS: Reduce use of uncached readdir trondmy
2022-02-23 21:12 ` [PATCH v7 11/21] NFS: Improve heuristic for readdirplus trondmy
2022-02-23 21:12 ` [PATCH v7 12/21] NFS: Don't ask for readdirplus unless it can help nfs_getattr() trondmy
2022-02-23 21:12 ` [PATCH v7 13/21] NFSv4: Ask for a full XDR buffer of readdir goodness trondmy
2022-02-23 21:12 ` [PATCH v7 14/21] NFS: Readdirplus can't help lookup for case insensitive filesystems trondmy
2022-02-23 21:12 ` [PATCH v7 15/21] NFS: Don't request readdirplus when revalidation was forced trondmy
2022-02-23 21:13 ` [PATCH v7 16/21] NFS: Add basic readdir tracing trondmy
2022-02-23 21:13 ` [PATCH v7 17/21] NFS: Trace effects of readdirplus on the dcache trondmy
2022-02-23 21:13 ` [PATCH v7 18/21] NFS: Trace effects of the readdirplus heuristic trondmy
2022-02-23 21:13 ` [PATCH v7 19/21] NFS: Convert readdir page cache to use a cookie based index trondmy
2022-02-23 21:13 ` [PATCH v7 20/21] NFS: Fix up forced readdirplus trondmy
2022-02-23 21:13 ` [PATCH v7 21/21] NFS: Remove unnecessary cache invalidations for directories trondmy
2022-02-24 17:31 ` [PATCH v7 19/21] NFS: Convert readdir page cache to use a cookie based index Benjamin Coddington
2022-02-25 2:33 ` Trond Myklebust
2022-02-25 3:17 ` NeilBrown
2022-02-25 4:25 ` Trond Myklebust
2022-02-25 12:33 ` Benjamin Coddington
2022-02-25 13:11 ` Trond Myklebust
2022-02-24 15:53 ` [PATCH v7 16/21] NFS: Add basic readdir tracing Benjamin Coddington
2022-02-25 2:35 ` Trond Myklebust
2022-02-24 16:55 ` [PATCH v7 10/21] NFS: Reduce use of uncached readdir Anna Schumaker
2022-02-25 4:07 ` Trond Myklebust
2022-02-24 16:30 ` [PATCH v7 08/21] NFS: Adjust the amount of readahead performed by NFS readdir Anna Schumaker
2022-02-24 16:18 ` [PATCH v7 06/21] NFS: If the cookie verifier changes, we must invalidate the page cache Anna Schumaker
2022-02-24 14:53 ` [PATCH v7 05/21] NFS: Store the change attribute in the directory " Benjamin Coddington
2022-02-25 2:26 ` Trond Myklebust [this message]
2022-02-25 3:51 ` Trond Myklebust
2022-02-25 11:38 ` Benjamin Coddington
2022-02-25 13:10 ` Trond Myklebust
2022-02-25 13:26 ` Trond Myklebust
2022-02-25 14:44 ` Benjamin Coddington
2022-02-25 15:18 ` Trond Myklebust
2022-02-25 15:34 ` Benjamin Coddington
2022-02-25 20:23 ` Benjamin Coddington
2022-02-25 20:28 ` Benjamin Coddington
2022-02-25 20:41 ` Trond Myklebust
2022-02-25 22:04 ` Benjamin Coddington
2022-02-25 22:29 ` Trond Myklebust
2022-02-24 14:15 ` [PATCH v7 04/21] NFS: Calculate page offsets algorithmically Benjamin Coddington
2022-02-25 2:11 ` Trond Myklebust
2022-02-25 11:28 ` Benjamin Coddington
2022-02-25 12:44 ` Trond Myklebust
2022-02-24 14:14 ` [PATCH v7 02/21] NFS: Trace lookup revalidation failure Benjamin Coddington
2022-02-25 2:09 ` Trond Myklebust
2022-02-24 12:25 ` [PATCH v7 00/21] Readdir improvements David Wysochanski
2022-02-25 4:00 ` Trond Myklebust
2022-02-24 15:07 ` David Wysochanski
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=1ca16f7e7be9588d15525e3afa4f7a80eb66b12b.camel@hammerspace.com \
--to=trondmy@hammerspace.com \
--cc=bcodding@redhat.com \
--cc=linux-nfs@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