From: Benjamin Coddington <bcodding@redhat.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH v3 3/8] NFS: Add a struct to track readdir pagecache location
Date: Wed, 23 Feb 2022 08:40:30 -0500 [thread overview]
Message-ID: <aaedb2e378800a5cdb7071d65690b981274f2c22.1645623510.git.bcodding@redhat.com> (raw)
In-Reply-To: <eedb07d14a96caef1de663a436a326b2c5012ab4.1645623510.git.bcodding@redhat.com>
Directory entries in the NFS readdir pagecache are referenced by their
cookie value and offset. By defining a structure to group these values,
we'll simplify changes to validate pagecache pages in patches that follow.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
fs/nfs/dir.c | 46 ++++++++++++++++++++----------------------
include/linux/nfs_fs.h | 6 ++++++
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 79bdcedc0cad..009187c0ae0f 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -158,11 +158,10 @@ struct nfs_readdir_descriptor {
struct file *file;
struct page *page;
struct dir_context *ctx;
- pgoff_t page_index;
pgoff_t page_index_max;
u64 dir_cookie;
- u64 last_cookie;
u64 dup_cookie;
+ struct nfs_dir_page_cursor pgc;
loff_t current_index;
loff_t prev_index;
@@ -172,7 +171,6 @@ struct nfs_readdir_descriptor {
unsigned long gencount;
unsigned long attr_gencount;
unsigned int page_fill_misses;
- unsigned int cache_entry_index;
unsigned int buffer_fills;
unsigned int dtsize;
signed char duped;
@@ -457,7 +455,7 @@ static int nfs_readdir_search_for_pos(struct nfs_cache_array *array,
index = (unsigned int)diff;
desc->dir_cookie = array->array[index].cookie;
- desc->cache_entry_index = index;
+ desc->pgc.entry_index = index;
return 0;
out_eof:
desc->eof = true;
@@ -526,7 +524,7 @@ static int nfs_readdir_search_for_cookie(struct nfs_cache_array *array,
else
desc->ctx->pos = new_pos;
desc->prev_index = new_pos;
- desc->cache_entry_index = i;
+ desc->pgc.entry_index = i;
return 0;
}
}
@@ -553,9 +551,9 @@ static int nfs_readdir_search_array(struct nfs_readdir_descriptor *desc)
status = nfs_readdir_search_for_cookie(array, desc);
if (status == -EAGAIN) {
- desc->last_cookie = array->last_cookie;
+ desc->pgc.index_cookie = array->last_cookie;
desc->current_index += array->size;
- desc->page_index++;
+ desc->pgc.page_index++;
}
kunmap_atomic(array);
return status;
@@ -968,8 +966,8 @@ static struct page *
nfs_readdir_page_get_cached(struct nfs_readdir_descriptor *desc)
{
return nfs_readdir_page_get_locked(desc->file->f_mapping,
- desc->page_index,
- desc->last_cookie);
+ desc->pgc.page_index,
+ desc->pgc.index_cookie);
}
#define NFS_READDIR_PAGE_FILL_MISS_MAX 5
@@ -1001,10 +999,10 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
if (nfs_readdir_page_needs_filling(desc->page)) {
if (!nfs_readdir_may_fill_pagecache(desc))
return -EBADCOOKIE;
- desc->page_index_max = desc->page_index;
+ desc->page_index_max = desc->pgc.page_index;
trace_nfs_readdir_cache_fill(desc->file, nfsi->cookieverf,
- desc->last_cookie,
- desc->page_index, desc->dtsize);
+ desc->pgc.index_cookie,
+ desc->pgc.page_index, desc->dtsize);
res = nfs_readdir_xdr_to_array(desc, nfsi->cookieverf, verf,
&desc->page, 1);
if (res < 0) {
@@ -1012,7 +1010,7 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
trace_nfs_readdir_cache_fill_done(inode, res);
if (res == -EBADCOOKIE || res == -ENOTSYNC) {
invalidate_inode_pages2(desc->file->f_mapping);
- desc->page_index = 0;
+ desc->pgc.page_index = 0;
return -EAGAIN;
}
return res;
@@ -1020,7 +1018,7 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
/*
* Set the cookie verifier if the page cache was empty
*/
- if (desc->page_index == 0)
+ if (desc->pgc.page_index == 0)
memcpy(nfsi->cookieverf, verf,
sizeof(nfsi->cookieverf));
desc->page_fill_misses++;
@@ -1040,10 +1038,10 @@ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc)
int res;
do {
- if (desc->page_index == 0) {
+ if (desc->pgc.page_index == 0) {
desc->current_index = 0;
desc->prev_index = 0;
- desc->last_cookie = 0;
+ desc->pgc.index_cookie = 0;
}
res = find_and_lock_cache_page(desc);
} while (res == -EAGAIN);
@@ -1061,7 +1059,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc,
unsigned int i = 0;
array = kmap(desc->page);
- for (i = desc->cache_entry_index; i < array->size; i++) {
+ for (i = desc->pgc.entry_index; i < array->size; i++) {
struct nfs_cache_array_entry *ent;
ent = &array->array[i];
@@ -1119,13 +1117,13 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc)
if (!arrays[0])
goto out;
- desc->page_index = 0;
- desc->cache_entry_index = 0;
- desc->last_cookie = desc->dir_cookie;
+ desc->pgc.page_index = 0;
+ desc->pgc.entry_index = 0;
+ desc->pgc.index_cookie = desc->dir_cookie;
desc->duped = 0;
desc->page_index_max = 0;
- trace_nfs_readdir_uncached(desc->file, desc->verf, desc->last_cookie,
+ trace_nfs_readdir_uncached(desc->file, desc->verf, desc->pgc.index_cookie,
-1, desc->dtsize);
status = nfs_readdir_xdr_to_array(desc, desc->verf, verf, arrays, sz);
@@ -1258,7 +1256,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
}
if (res == -ETOOSMALL && desc->plus) {
nfs_zap_caches(inode);
- desc->page_index = 0;
+ desc->pgc.page_index = 0;
desc->plus = false;
desc->eof = false;
continue;
@@ -1271,7 +1269,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
if (desc->eob || desc->eof)
break;
/* Grow the dtsize if we have to go back for more pages */
- if (desc->page_index == desc->page_index_max)
+ if (desc->pgc.page_index == desc->page_index_max)
nfs_grow_dtsize(desc);
} while (!desc->eob && !desc->eof);
@@ -1280,7 +1278,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
dir_ctx->dup_cookie = desc->dup_cookie;
dir_ctx->duped = desc->duped;
dir_ctx->attr_gencount = desc->attr_gencount;
- dir_ctx->page_index = desc->page_index;
+ dir_ctx->page_index = desc->pgc.page_index;
dir_ctx->page_fill_misses = desc->page_fill_misses;
dir_ctx->eof = desc->eof;
dir_ctx->dtsize = desc->dtsize;
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 0a5425a58bbd..2f5ded282477 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -99,6 +99,12 @@ struct nfs_open_context {
struct rcu_head rcu_head;
};
+struct nfs_dir_page_cursor {
+ __u64 index_cookie;
+ pgoff_t page_index;
+ unsigned int entry_index;
+};
+
struct nfs_open_dir_context {
struct list_head list;
atomic_t cache_hits;
--
2.31.1
next prev parent reply other threads:[~2022-02-23 13:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-21 16:08 [PATCH v6 00/13] Readdir improvements trondmy
2022-02-21 16:08 ` [PATCH v6 01/13] NFS: constify nfs_server_capable() and nfs_have_writebacks() trondmy
2022-02-21 16:08 ` [PATCH v6 02/13] NFS: Trace lookup revalidation failure trondmy
2022-02-21 16:08 ` [PATCH v6 03/13] NFS: Adjust the amount of readahead performed by NFS readdir trondmy
2022-02-21 16:08 ` [PATCH v6 04/13] NFS: Simplify nfs_readdir_xdr_to_array() trondmy
2022-02-21 16:08 ` [PATCH v6 05/13] NFS: Improve algorithm for falling back to uncached readdir trondmy
2022-02-21 16:08 ` [PATCH v6 06/13] NFS: Improve heuristic for readdirplus trondmy
2022-02-21 16:08 ` [PATCH v6 07/13] NFS: Don't ask for readdirplus unless it can help nfs_getattr() trondmy
2022-02-21 16:08 ` [PATCH v6 08/13] NFSv4: Ask for a full XDR buffer of readdir goodness trondmy
2022-02-21 16:08 ` [PATCH v6 09/13] NFS: Readdirplus can't help lookup for case insensitive filesystems trondmy
2022-02-21 16:08 ` [PATCH v6 10/13] NFS: Don't request readdirplus when revaldation was forced trondmy
2022-02-21 16:08 ` [PATCH v6 11/13] NFS: Add basic readdir tracing trondmy
2022-02-21 16:08 ` [PATCH v6 12/13] NFS: Trace effects of readdirplus on the dcache trondmy
2022-02-21 16:08 ` [PATCH v6 13/13] NFS: Trace effects of the readdirplus heuristic trondmy
2022-02-23 13:40 ` [PATCH v3 1/8] NFS: save the directory's change attribute on pagecache pages Benjamin Coddington
2022-02-23 13:40 ` [PATCH v3 2/8] NFSv4: Send GETATTR with READDIR Benjamin Coddington
2022-02-23 13:40 ` Benjamin Coddington [this message]
2022-02-23 13:40 ` [PATCH v3 4/8] NFS: Keep the readdir pagecache cursor updated Benjamin Coddington
2022-02-23 13:40 ` [PATCH v3 5/8] NFS: readdir per-page cache validation Benjamin Coddington
2022-02-23 13:40 ` [PATCH v3 6/8] NFS: stash the readdir pagecache cursor on the open directory context Benjamin Coddington
2022-02-23 13:40 ` [PATCH v3 7/8] NFS: Support headless readdir pagecache pages Benjamin Coddington
2022-02-23 13:40 ` [PATCH v3 8/8] NFS: Revalidate the directory pagecache on every nfs_readdir() Benjamin Coddington
2022-02-21 16:45 ` [PATCH v6 05/13] NFS: Improve algorithm for falling back to uncached readdir Benjamin Coddington
2022-02-21 19:58 ` Trond Myklebust
2022-02-21 20:22 ` Benjamin Coddington
2022-02-21 20:55 ` Trond Myklebust
2022-02-21 21:10 ` Benjamin Coddington
2022-02-21 23:20 ` Trond Myklebust
2022-02-22 12:50 ` Benjamin Coddington
2022-02-22 20:11 ` Trond Myklebust
2022-02-22 20:21 ` Benjamin Coddington
2022-02-23 12:17 ` Trond Myklebust
2022-02-23 13:34 ` Benjamin Coddington
2022-02-23 21:31 ` Trond Myklebust
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=aaedb2e378800a5cdb7071d65690b981274f2c22.1645623510.git.bcodding@redhat.com \
--to=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