Skip to content

Commit baff974

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
ceph: Convert ceph_readdir_cache_control to store a folio
Pass a folio around instead of a page. This removes an access to page->index and a few hidden calls to compound_head(). Signed-off-by: "Matthew Wilcox (Oracle)" <willy@infradead.org> Link: https://lore.kernel.org/r/20250217185119.430193-5-willy@infradead.org Tested-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com> Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent f9707a8 commit baff974

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

fs/ceph/dir.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,18 @@ __dcache_find_get_entry(struct dentry *parent, u64 idx,
141141
if (ptr_pos >= i_size_read(dir))
142142
return NULL;
143143

144-
if (!cache_ctl->page || ptr_pgoff != cache_ctl->page->index) {
144+
if (!cache_ctl->folio || ptr_pgoff != cache_ctl->folio->index) {
145145
ceph_readdir_cache_release(cache_ctl);
146-
cache_ctl->page = find_lock_page(&dir->i_data, ptr_pgoff);
147-
if (!cache_ctl->page) {
148-
doutc(cl, " page %lu not found\n", ptr_pgoff);
146+
cache_ctl->folio = filemap_lock_folio(&dir->i_data, ptr_pgoff);
147+
if (IS_ERR(cache_ctl->folio)) {
148+
cache_ctl->folio = NULL;
149+
doutc(cl, " folio %lu not found\n", ptr_pgoff);
149150
return ERR_PTR(-EAGAIN);
150151
}
151152
/* reading/filling the cache are serialized by
152-
i_rwsem, no need to use page lock */
153-
unlock_page(cache_ctl->page);
154-
cache_ctl->dentries = kmap(cache_ctl->page);
153+
i_rwsem, no need to use folio lock */
154+
folio_unlock(cache_ctl->folio);
155+
cache_ctl->dentries = kmap_local_folio(cache_ctl->folio, 0);
155156
}
156157

157158
cache_ctl->index = idx & idx_mask;

fs/ceph/inode.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,10 +1845,9 @@ static int readdir_prepopulate_inodes_only(struct ceph_mds_request *req,
18451845

18461846
void ceph_readdir_cache_release(struct ceph_readdir_cache_control *ctl)
18471847
{
1848-
if (ctl->page) {
1849-
kunmap(ctl->page);
1850-
put_page(ctl->page);
1851-
ctl->page = NULL;
1848+
if (ctl->folio) {
1849+
folio_release_kmap(ctl->folio, ctl->dentries);
1850+
ctl->folio = NULL;
18521851
}
18531852
}
18541853

@@ -1862,20 +1861,23 @@ static int fill_readdir_cache(struct inode *dir, struct dentry *dn,
18621861
unsigned idx = ctl->index % nsize;
18631862
pgoff_t pgoff = ctl->index / nsize;
18641863

1865-
if (!ctl->page || pgoff != ctl->page->index) {
1864+
if (!ctl->folio || pgoff != ctl->folio->index) {
18661865
ceph_readdir_cache_release(ctl);
1866+
fgf_t fgf = FGP_LOCK;
1867+
18671868
if (idx == 0)
1868-
ctl->page = grab_cache_page(&dir->i_data, pgoff);
1869-
else
1870-
ctl->page = find_lock_page(&dir->i_data, pgoff);
1871-
if (!ctl->page) {
1869+
fgf |= FGP_ACCESSED | FGP_CREAT;
1870+
1871+
ctl->folio = __filemap_get_folio(&dir->i_data, pgoff,
1872+
fgf, mapping_gfp_mask(&dir->i_data));
1873+
if (!ctl->folio) {
18721874
ctl->index = -1;
18731875
return idx == 0 ? -ENOMEM : 0;
18741876
}
18751877
/* reading/filling the cache are serialized by
1876-
* i_rwsem, no need to use page lock */
1877-
unlock_page(ctl->page);
1878-
ctl->dentries = kmap(ctl->page);
1878+
* i_rwsem, no need to use folio lock */
1879+
folio_unlock(ctl->folio);
1880+
ctl->dentries = kmap_local_folio(ctl->folio, 0);
18791881
if (idx == 0)
18801882
memset(ctl->dentries, 0, PAGE_SIZE);
18811883
}

fs/ceph/super.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ ceph_find_rw_context(struct ceph_file_info *cf)
903903
}
904904

905905
struct ceph_readdir_cache_control {
906-
struct page *page;
906+
struct folio *folio;
907907
struct dentry **dentries;
908908
int index;
909909
};

0 commit comments

Comments
 (0)