Skip to content

Commit 61f02e0

Browse files
committed
NFS: Convert the readdir array-of-pages into an array-of-folios
This patch only converts the actual array, but doesn't touch the individual nfs_cache_array pages and related functions (that will be done in the next patch). I also adjust the names of the fields in the nfs_readdir_descriptor to say "folio" instead of "page". Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 3db63da commit 61f02e0

1 file changed

Lines changed: 65 additions & 64 deletions

File tree

fs/nfs/dir.c

Lines changed: 65 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ struct nfs_cache_array {
154154

155155
struct nfs_readdir_descriptor {
156156
struct file *file;
157-
struct page *page;
157+
struct folio *folio;
158158
struct dir_context *ctx;
159-
pgoff_t page_index;
160-
pgoff_t page_index_max;
159+
pgoff_t folio_index;
160+
pgoff_t folio_index_max;
161161
u64 dir_cookie;
162162
u64 last_cookie;
163163
loff_t current_index;
@@ -312,8 +312,8 @@ static int nfs_readdir_array_can_expand(struct nfs_cache_array *array)
312312
}
313313

314314
static int nfs_readdir_page_array_append(struct page *page,
315-
const struct nfs_entry *entry,
316-
u64 *cookie)
315+
const struct nfs_entry *entry,
316+
u64 *cookie)
317317
{
318318
struct nfs_cache_array *array;
319319
struct nfs_cache_array_entry *cache_entry;
@@ -485,7 +485,7 @@ static void nfs_readdir_seek_next_array(struct nfs_cache_array *array,
485485
desc->last_cookie = array->last_cookie;
486486
desc->current_index += array->size;
487487
desc->cache_entry_index = 0;
488-
desc->page_index++;
488+
desc->folio_index++;
489489
} else
490490
desc->last_cookie = nfs_readdir_array_index_cookie(array);
491491
}
@@ -494,7 +494,7 @@ static void nfs_readdir_rewind_search(struct nfs_readdir_descriptor *desc)
494494
{
495495
desc->current_index = 0;
496496
desc->last_cookie = 0;
497-
desc->page_index = 0;
497+
desc->folio_index = 0;
498498
}
499499

500500
static int nfs_readdir_search_for_pos(struct nfs_cache_array *array,
@@ -568,7 +568,7 @@ static int nfs_readdir_search_array(struct nfs_readdir_descriptor *desc)
568568
struct nfs_cache_array *array;
569569
int status;
570570

571-
array = kmap_local_page(desc->page);
571+
array = kmap_local_folio(desc->folio, 0);
572572

573573
if (desc->dir_cookie == 0)
574574
status = nfs_readdir_search_for_pos(array, desc);
@@ -819,16 +819,17 @@ static int nfs_readdir_entry_decode(struct nfs_readdir_descriptor *desc,
819819
}
820820

821821
/* Perform conversion from xdr to cache array */
822-
static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc,
823-
struct nfs_entry *entry,
824-
struct page **xdr_pages, unsigned int buflen,
825-
struct page **arrays, size_t narrays,
826-
u64 change_attr)
822+
static int nfs_readdir_folio_filler(struct nfs_readdir_descriptor *desc,
823+
struct nfs_entry *entry,
824+
struct page **xdr_pages, unsigned int buflen,
825+
struct folio **arrays, size_t narrays,
826+
u64 change_attr)
827827
{
828828
struct address_space *mapping = desc->file->f_mapping;
829+
struct folio *folio = *arrays;
829830
struct xdr_stream stream;
831+
struct page *scratch, *new;
830832
struct xdr_buf buf;
831-
struct page *scratch, *new, *page = *arrays;
832833
u64 cookie;
833834
int status;
834835

@@ -844,36 +845,36 @@ static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc,
844845
if (status != 0)
845846
break;
846847

847-
status = nfs_readdir_page_array_append(page, entry, &cookie);
848+
status = nfs_readdir_page_array_append(folio_page(folio, 0), entry, &cookie);
848849
if (status != -ENOSPC)
849850
continue;
850851

851-
if (page->mapping != mapping) {
852+
if (folio->mapping != mapping) {
852853
if (!--narrays)
853854
break;
854855
new = nfs_readdir_page_array_alloc(cookie, GFP_KERNEL);
855856
if (!new)
856857
break;
857858
arrays++;
858-
*arrays = page = new;
859+
*arrays = folio = page_folio(new);
859860
} else {
860861
new = nfs_readdir_page_get_next(mapping, cookie,
861862
change_attr);
862863
if (!new)
863864
break;
864-
if (page != *arrays)
865-
nfs_readdir_page_unlock_and_put(page);
866-
page = new;
865+
if (folio != *arrays)
866+
nfs_readdir_page_unlock_and_put(folio_page(folio, 0));
867+
folio = page_folio(new);
867868
}
868-
desc->page_index_max++;
869-
status = nfs_readdir_page_array_append(page, entry, &cookie);
869+
desc->folio_index_max++;
870+
status = nfs_readdir_page_array_append(folio_page(folio, 0), entry, &cookie);
870871
} while (!status && !entry->eof);
871872

872873
switch (status) {
873874
case -EBADCOOKIE:
874875
if (!entry->eof)
875876
break;
876-
nfs_readdir_page_set_eof(page);
877+
nfs_readdir_page_set_eof(folio_page(folio, 0));
877878
fallthrough;
878879
case -EAGAIN:
879880
status = 0;
@@ -886,8 +887,8 @@ static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc,
886887
;
887888
}
888889

889-
if (page != *arrays)
890-
nfs_readdir_page_unlock_and_put(page);
890+
if (folio != *arrays)
891+
nfs_readdir_page_unlock_and_put(folio_page(folio, 0));
891892

892893
put_page(scratch);
893894
return status;
@@ -927,11 +928,11 @@ static struct page **nfs_readdir_alloc_pages(size_t npages)
927928

928929
static int nfs_readdir_xdr_to_array(struct nfs_readdir_descriptor *desc,
929930
__be32 *verf_arg, __be32 *verf_res,
930-
struct page **arrays, size_t narrays)
931+
struct folio **arrays, size_t narrays)
931932
{
932933
u64 change_attr;
933934
struct page **pages;
934-
struct page *page = *arrays;
935+
struct folio *folio = *arrays;
935936
struct nfs_entry *entry;
936937
size_t array_size;
937938
struct inode *inode = file_inode(desc->file);
@@ -942,7 +943,7 @@ static int nfs_readdir_xdr_to_array(struct nfs_readdir_descriptor *desc,
942943
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
943944
if (!entry)
944945
return -ENOMEM;
945-
entry->cookie = nfs_readdir_page_last_cookie(page);
946+
entry->cookie = nfs_readdir_page_last_cookie(folio_page(folio, 0));
946947
entry->fh = nfs_alloc_fhandle();
947948
entry->fattr = nfs_alloc_fattr_with_label(NFS_SERVER(inode));
948949
entry->server = NFS_SERVER(inode);
@@ -962,10 +963,10 @@ static int nfs_readdir_xdr_to_array(struct nfs_readdir_descriptor *desc,
962963

963964
pglen = status;
964965
if (pglen != 0)
965-
status = nfs_readdir_page_filler(desc, entry, pages, pglen,
966-
arrays, narrays, change_attr);
966+
status = nfs_readdir_folio_filler(desc, entry, pages, pglen,
967+
arrays, narrays, change_attr);
967968
else
968-
nfs_readdir_page_set_eof(page);
969+
nfs_readdir_page_set_eof(folio_page(folio, 0));
969970
desc->buffer_fills++;
970971

971972
free_pages:
@@ -977,21 +978,21 @@ static int nfs_readdir_xdr_to_array(struct nfs_readdir_descriptor *desc,
977978
return status;
978979
}
979980

980-
static void nfs_readdir_page_put(struct nfs_readdir_descriptor *desc)
981+
static void nfs_readdir_folio_put(struct nfs_readdir_descriptor *desc)
981982
{
982-
put_page(desc->page);
983-
desc->page = NULL;
983+
folio_put(desc->folio);
984+
desc->folio = NULL;
984985
}
985986

986987
static void
987-
nfs_readdir_page_unlock_and_put_cached(struct nfs_readdir_descriptor *desc)
988+
nfs_readdir_folio_unlock_and_put_cached(struct nfs_readdir_descriptor *desc)
988989
{
989-
unlock_page(desc->page);
990-
nfs_readdir_page_put(desc);
990+
folio_unlock(desc->folio);
991+
nfs_readdir_folio_put(desc);
991992
}
992993

993-
static struct page *
994-
nfs_readdir_page_get_cached(struct nfs_readdir_descriptor *desc)
994+
static struct folio *
995+
nfs_readdir_folio_get_cached(struct nfs_readdir_descriptor *desc)
995996
{
996997
struct address_space *mapping = desc->file->f_mapping;
997998
u64 change_attr = inode_peek_iversion_raw(mapping->host);
@@ -1003,7 +1004,7 @@ nfs_readdir_page_get_cached(struct nfs_readdir_descriptor *desc)
10031004
return NULL;
10041005
if (desc->clear_cache && !nfs_readdir_page_needs_filling(page))
10051006
nfs_readdir_page_reinit_array(page, cookie, change_attr);
1006-
return page;
1007+
return page_folio(page);
10071008
}
10081009

10091010
/*
@@ -1017,21 +1018,21 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
10171018
__be32 verf[NFS_DIR_VERIFIER_SIZE];
10181019
int res;
10191020

1020-
desc->page = nfs_readdir_page_get_cached(desc);
1021-
if (!desc->page)
1021+
desc->folio = nfs_readdir_folio_get_cached(desc);
1022+
if (!desc->folio)
10221023
return -ENOMEM;
1023-
if (nfs_readdir_page_needs_filling(desc->page)) {
1024+
if (nfs_readdir_page_needs_filling(folio_page(desc->folio, 0))) {
10241025
/* Grow the dtsize if we had to go back for more pages */
1025-
if (desc->page_index == desc->page_index_max)
1026+
if (desc->folio_index == desc->folio_index_max)
10261027
nfs_grow_dtsize(desc);
1027-
desc->page_index_max = desc->page_index;
1028+
desc->folio_index_max = desc->folio_index;
10281029
trace_nfs_readdir_cache_fill(desc->file, nfsi->cookieverf,
10291030
desc->last_cookie,
1030-
desc->page->index, desc->dtsize);
1031+
desc->folio->index, desc->dtsize);
10311032
res = nfs_readdir_xdr_to_array(desc, nfsi->cookieverf, verf,
1032-
&desc->page, 1);
1033+
&desc->folio, 1);
10331034
if (res < 0) {
1034-
nfs_readdir_page_unlock_and_put_cached(desc);
1035+
nfs_readdir_folio_unlock_and_put_cached(desc);
10351036
trace_nfs_readdir_cache_fill_done(inode, res);
10361037
if (res == -EBADCOOKIE || res == -ENOTSYNC) {
10371038
invalidate_inode_pages2(desc->file->f_mapping);
@@ -1059,7 +1060,7 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
10591060
res = nfs_readdir_search_array(desc);
10601061
if (res == 0)
10611062
return 0;
1062-
nfs_readdir_page_unlock_and_put_cached(desc);
1063+
nfs_readdir_folio_unlock_and_put_cached(desc);
10631064
return res;
10641065
}
10651066

@@ -1087,7 +1088,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc,
10871088
unsigned int i;
10881089
bool first_emit = !desc->dir_cookie;
10891090

1090-
array = kmap_local_page(desc->page);
1091+
array = kmap_local_folio(desc->folio, 0);
10911092
for (i = desc->cache_entry_index; i < array->size; i++) {
10921093
struct nfs_cache_array_entry *ent;
10931094

@@ -1136,7 +1137,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc,
11361137
*/
11371138
static int uncached_readdir(struct nfs_readdir_descriptor *desc)
11381139
{
1139-
struct page **arrays;
1140+
struct folio **arrays;
11401141
size_t i, sz = 512;
11411142
__be32 verf[NFS_DIR_VERIFIER_SIZE];
11421143
int status = -ENOMEM;
@@ -1147,14 +1148,14 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc)
11471148
arrays = kcalloc(sz, sizeof(*arrays), GFP_KERNEL);
11481149
if (!arrays)
11491150
goto out;
1150-
arrays[0] = nfs_readdir_page_array_alloc(desc->dir_cookie, GFP_KERNEL);
1151+
arrays[0] = page_folio(nfs_readdir_page_array_alloc(desc->dir_cookie, GFP_KERNEL));
11511152
if (!arrays[0])
11521153
goto out;
11531154

1154-
desc->page_index = 0;
1155+
desc->folio_index = 0;
11551156
desc->cache_entry_index = 0;
11561157
desc->last_cookie = desc->dir_cookie;
1157-
desc->page_index_max = 0;
1158+
desc->folio_index_max = 0;
11581159

11591160
trace_nfs_readdir_uncached(desc->file, desc->verf, desc->last_cookie,
11601161
-1, desc->dtsize);
@@ -1166,10 +1167,10 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc)
11661167
}
11671168

11681169
for (i = 0; !desc->eob && i < sz && arrays[i]; i++) {
1169-
desc->page = arrays[i];
1170+
desc->folio = arrays[i];
11701171
nfs_do_filldir(desc, verf);
11711172
}
1172-
desc->page = NULL;
1173+
desc->folio = NULL;
11731174

11741175
/*
11751176
* Grow the dtsize if we have to go back for more pages,
@@ -1179,16 +1180,16 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc)
11791180
if (!desc->eob)
11801181
nfs_grow_dtsize(desc);
11811182
else if (desc->buffer_fills == 1 &&
1182-
i < (desc->page_index_max >> 1))
1183+
i < (desc->folio_index_max >> 1))
11831184
nfs_shrink_dtsize(desc);
11841185
}
11851186
out_free:
11861187
for (i = 0; i < sz && arrays[i]; i++)
1187-
nfs_readdir_page_array_free(arrays[i]);
1188+
nfs_readdir_page_array_free(folio_page(arrays[i], 0));
11881189
out:
11891190
if (!nfs_readdir_use_cookie(desc->file))
11901191
nfs_readdir_rewind_search(desc);
1191-
desc->page_index_max = -1;
1192+
desc->folio_index_max = -1;
11921193
kfree(arrays);
11931194
dfprintk(DIRCACHE, "NFS: %s: returns %d\n", __func__, status);
11941195
return status;
@@ -1240,11 +1241,11 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
12401241
goto out;
12411242
desc->file = file;
12421243
desc->ctx = ctx;
1243-
desc->page_index_max = -1;
1244+
desc->folio_index_max = -1;
12441245

12451246
spin_lock(&file->f_lock);
12461247
desc->dir_cookie = dir_ctx->dir_cookie;
1247-
desc->page_index = dir_ctx->page_index;
1248+
desc->folio_index = dir_ctx->page_index;
12481249
desc->last_cookie = dir_ctx->last_cookie;
12491250
desc->attr_gencount = dir_ctx->attr_gencount;
12501251
desc->eof = dir_ctx->eof;
@@ -1291,16 +1292,16 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
12911292
break;
12921293

12931294
nfs_do_filldir(desc, nfsi->cookieverf);
1294-
nfs_readdir_page_unlock_and_put_cached(desc);
1295-
if (desc->page_index == desc->page_index_max)
1295+
nfs_readdir_folio_unlock_and_put_cached(desc);
1296+
if (desc->folio_index == desc->folio_index_max)
12961297
desc->clear_cache = force_clear;
12971298
} while (!desc->eob && !desc->eof);
12981299

12991300
spin_lock(&file->f_lock);
13001301
dir_ctx->dir_cookie = desc->dir_cookie;
13011302
dir_ctx->last_cookie = desc->last_cookie;
13021303
dir_ctx->attr_gencount = desc->attr_gencount;
1303-
dir_ctx->page_index = desc->page_index;
1304+
dir_ctx->page_index = desc->folio_index;
13041305
dir_ctx->force_clear = force_clear;
13051306
dir_ctx->eof = desc->eof;
13061307
dir_ctx->dtsize = desc->dtsize;

0 commit comments

Comments
 (0)