Skip to content

Commit 706fd68

Browse files
committed
erofs: refine managed cache operations to folios
Convert erofs_try_to_free_all_cached_pages() and z_erofs_cache_release_folio(). Besides, erofs_page_is_managed() is moved to zdata.c and renamed as erofs_folio_is_managed(). Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9266f2d commit 706fd68

File tree

6 files changed

+34
-48
lines changed

6 files changed

+34
-48
lines changed

fs/erofs/compress.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,6 @@ static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
8181
return true;
8282
}
8383

84-
#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
85-
static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi,
86-
struct page *page)
87-
{
88-
return page->mapping == MNGD_MAPPING(sbi);
89-
}
90-
9184
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
9285
unsigned int padbufsize);
9386
extern const struct z_erofs_decompressor erofs_decompressors[];

fs/erofs/decompressor_deflate.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,6 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
212212

213213
if (rq->out[no] != rq->in[j])
214214
continue;
215-
216-
DBG_BUGON(erofs_page_is_managed(EROFS_SB(sb),
217-
rq->in[j]));
218215
tmppage = erofs_allocpage(pgpl, rq->gfp);
219216
if (!tmppage) {
220217
err = -ENOMEM;

fs/erofs/decompressor_lzma.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
258258

259259
if (rq->out[no] != rq->in[j])
260260
continue;
261-
262-
DBG_BUGON(erofs_page_is_managed(EROFS_SB(rq->sb),
263-
rq->in[j]));
264261
tmppage = erofs_allocpage(pgpl, rq->gfp);
265262
if (!tmppage) {
266263
err = -ENOMEM;

fs/erofs/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ int __init erofs_init_shrinker(void);
467467
void erofs_exit_shrinker(void);
468468
int __init z_erofs_init_zip_subsystem(void);
469469
void z_erofs_exit_zip_subsystem(void);
470-
int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
471-
struct erofs_workgroup *egrp);
470+
int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
471+
struct erofs_workgroup *egrp);
472472
int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
473473
int flags);
474474
void *erofs_get_pcpubuf(unsigned int requiredpages);

fs/erofs/utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
129129
* the XArray. Otherwise some cached pages could be still attached to
130130
* the orphan old workgroup when the new one is available in the tree.
131131
*/
132-
if (erofs_try_to_free_all_cached_pages(sbi, grp))
132+
if (erofs_try_to_free_all_cached_folios(sbi, grp))
133133
goto out;
134134

135135
/*

fs/erofs/zdata.c

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ static inline unsigned int z_erofs_pclusterpages(struct z_erofs_pcluster *pcl)
119119
return PAGE_ALIGN(pcl->pclustersize) >> PAGE_SHIFT;
120120
}
121121

122+
#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
123+
static bool erofs_folio_is_managed(struct erofs_sb_info *sbi, struct folio *fo)
124+
{
125+
return fo->mapping == MNGD_MAPPING(sbi);
126+
}
127+
122128
/*
123129
* bit 30: I/O error occurred on this folio
124130
* bit 0 - 29: remaining parts to complete this folio
@@ -611,37 +617,32 @@ static void z_erofs_bind_cache(struct z_erofs_decompress_frontend *fe)
611617
fe->mode = Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE;
612618
}
613619

614-
/* called by erofs_shrinker to get rid of all compressed_pages */
615-
int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
616-
struct erofs_workgroup *grp)
620+
/* called by erofs_shrinker to get rid of all cached compressed bvecs */
621+
int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
622+
struct erofs_workgroup *grp)
617623
{
618624
struct z_erofs_pcluster *const pcl =
619625
container_of(grp, struct z_erofs_pcluster, obj);
620626
unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
621627
int i;
622628

623629
DBG_BUGON(z_erofs_is_inline_pcluster(pcl));
624-
/*
625-
* refcount of workgroup is now freezed as 0,
626-
* therefore no need to worry about available decompression users.
627-
*/
630+
/* There is no actice user since the pcluster is now freezed */
628631
for (i = 0; i < pclusterpages; ++i) {
629-
struct page *page = pcl->compressed_bvecs[i].page;
632+
struct folio *folio = pcl->compressed_bvecs[i].folio;
630633

631-
if (!page)
634+
if (!folio)
632635
continue;
633636

634-
/* block other users from reclaiming or migrating the page */
635-
if (!trylock_page(page))
637+
/* Avoid reclaiming or migrating this folio */
638+
if (!folio_trylock(folio))
636639
return -EBUSY;
637640

638-
if (!erofs_page_is_managed(sbi, page))
641+
if (!erofs_folio_is_managed(sbi, folio))
639642
continue;
640-
641-
/* barrier is implied in the following 'unlock_page' */
642-
WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
643-
detach_page_private(page);
644-
unlock_page(page);
643+
pcl->compressed_bvecs[i].folio = NULL;
644+
folio_detach_private(folio);
645+
folio_unlock(folio);
645646
}
646647
return 0;
647648
}
@@ -658,20 +659,17 @@ static bool z_erofs_cache_release_folio(struct folio *folio, gfp_t gfp)
658659

659660
ret = false;
660661
spin_lock(&pcl->obj.lockref.lock);
661-
if (pcl->obj.lockref.count > 0)
662-
goto out;
663-
664-
DBG_BUGON(z_erofs_is_inline_pcluster(pcl));
665-
for (i = 0; i < pclusterpages; ++i) {
666-
if (pcl->compressed_bvecs[i].page == &folio->page) {
667-
WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
668-
ret = true;
669-
break;
662+
if (pcl->obj.lockref.count <= 0) {
663+
DBG_BUGON(z_erofs_is_inline_pcluster(pcl));
664+
for (i = 0; i < pclusterpages; ++i) {
665+
if (pcl->compressed_bvecs[i].folio == folio) {
666+
pcl->compressed_bvecs[i].folio = NULL;
667+
folio_detach_private(folio);
668+
ret = true;
669+
break;
670+
}
670671
}
671672
}
672-
if (ret)
673-
folio_detach_private(folio);
674-
out:
675673
spin_unlock(&pcl->obj.lockref.lock);
676674
return ret;
677675
}
@@ -1201,7 +1199,7 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be,
12011199
be->compressed_pages[i] = page;
12021200

12031201
if (z_erofs_is_inline_pcluster(pcl) ||
1204-
erofs_page_is_managed(EROFS_SB(be->sb), page)) {
1202+
erofs_folio_is_managed(EROFS_SB(be->sb), page_folio(page))) {
12051203
if (!PageUptodate(page))
12061204
err = -EIO;
12071205
continue;
@@ -1286,7 +1284,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
12861284
/* consider shortlived pages added when decompressing */
12871285
page = be->compressed_pages[i];
12881286

1289-
if (!page || erofs_page_is_managed(sbi, page))
1287+
if (!page ||
1288+
erofs_folio_is_managed(sbi, page_folio(page)))
12901289
continue;
12911290
(void)z_erofs_put_shortlivedpage(be->pagepool, page);
12921291
WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL);
@@ -1573,7 +1572,7 @@ static void z_erofs_submissionqueue_endio(struct bio *bio)
15731572

15741573
DBG_BUGON(folio_test_uptodate(folio));
15751574
DBG_BUGON(z_erofs_page_is_invalidated(&folio->page));
1576-
if (!erofs_page_is_managed(EROFS_SB(q->sb), &folio->page))
1575+
if (!erofs_folio_is_managed(EROFS_SB(q->sb), folio))
15771576
continue;
15781577

15791578
if (!err)

0 commit comments

Comments
 (0)