Skip to content

Commit 92cc38e

Browse files
committed
erofs: convert z_erofs_fill_bio_vec() to folios
Introduce a folio member to `struct z_erofs_bvec` and convert most of z_erofs_fill_bio_vec() to folios, which is still straight-forward. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 19fb907 commit 92cc38e

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

fs/erofs/zdata.c

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
typedef void *z_erofs_next_pcluster_t;
2020

2121
struct z_erofs_bvec {
22-
struct page *page;
22+
union {
23+
struct page *page;
24+
struct folio *folio;
25+
};
2326
int offset;
2427
unsigned int end;
2528
};
@@ -1420,33 +1423,32 @@ static void z_erofs_fill_bio_vec(struct bio_vec *bvec,
14201423
struct page *page;
14211424
int bs = i_blocksize(f->inode);
14221425

1423-
/* Except for inplace pages, the entire page can be used for I/Os */
1426+
/* Except for inplace folios, the entire folio can be used for I/Os */
14241427
bvec->bv_offset = 0;
14251428
bvec->bv_len = PAGE_SIZE;
14261429
repeat:
14271430
spin_lock(&pcl->obj.lockref.lock);
14281431
zbv = pcl->compressed_bvecs[nr];
1429-
page = zbv.page;
14301432
spin_unlock(&pcl->obj.lockref.lock);
1431-
if (!page)
1432-
goto out_allocpage;
1433+
if (!zbv.folio)
1434+
goto out_allocfolio;
14331435

1434-
bvec->bv_page = page;
1435-
DBG_BUGON(z_erofs_is_shortlived_page(page));
1436+
bvec->bv_page = &zbv.folio->page;
1437+
DBG_BUGON(z_erofs_is_shortlived_page(bvec->bv_page));
14361438
/*
1437-
* Handle preallocated cached pages. We tried to allocate such pages
1439+
* Handle preallocated cached folios. We tried to allocate such folios
14381440
* without triggering direct reclaim. If allocation failed, inplace
1439-
* file-backed pages will be used instead.
1441+
* file-backed folios will be used instead.
14401442
*/
1441-
if (page->private == Z_EROFS_PREALLOCATED_PAGE) {
1442-
set_page_private(page, 0);
1443+
if (zbv.folio->private == (void *)Z_EROFS_PREALLOCATED_PAGE) {
1444+
zbv.folio->private = 0;
14431445
tocache = true;
14441446
goto out_tocache;
14451447
}
14461448

1447-
mapping = READ_ONCE(page->mapping);
1449+
mapping = READ_ONCE(zbv.folio->mapping);
14481450
/*
1449-
* File-backed pages for inplace I/Os are all locked steady,
1451+
* File-backed folios for inplace I/Os are all locked steady,
14501452
* therefore it is impossible for `mapping` to be NULL.
14511453
*/
14521454
if (mapping && mapping != mc) {
@@ -1456,22 +1458,21 @@ static void z_erofs_fill_bio_vec(struct bio_vec *bvec,
14561458
return;
14571459
}
14581460

1459-
lock_page(page);
1460-
/* the cached page is still in managed cache */
1461-
if (page->mapping == mc) {
1461+
folio_lock(zbv.folio);
1462+
if (zbv.folio->mapping == mc) {
14621463
/*
1463-
* The cached page is still available but without a valid
1464-
* `->private` pcluster hint. Let's reconnect them.
1464+
* The cached folio is still in managed cache but without
1465+
* a valid `->private` pcluster hint. Let's reconnect them.
14651466
*/
1466-
if (!PagePrivate(page)) {
1467-
/* compressed_bvecs[] already takes a ref */
1468-
attach_page_private(page, pcl);
1469-
put_page(page);
1467+
if (!folio_test_private(zbv.folio)) {
1468+
folio_attach_private(zbv.folio, pcl);
1469+
/* compressed_bvecs[] already takes a ref before */
1470+
folio_put(zbv.folio);
14701471
}
14711472

14721473
/* no need to submit if it is already up-to-date */
1473-
if (PageUptodate(page)) {
1474-
unlock_page(page);
1474+
if (folio_test_uptodate(zbv.folio)) {
1475+
folio_unlock(zbv.folio);
14751476
bvec->bv_page = NULL;
14761477
}
14771478
return;
@@ -1481,32 +1482,32 @@ static void z_erofs_fill_bio_vec(struct bio_vec *bvec,
14811482
* It has been truncated, so it's unsafe to reuse this one. Let's
14821483
* allocate a new page for compressed data.
14831484
*/
1484-
DBG_BUGON(page->mapping);
1485+
DBG_BUGON(zbv.folio->mapping);
14851486
tocache = true;
1486-
unlock_page(page);
1487-
put_page(page);
1488-
out_allocpage:
1487+
folio_unlock(zbv.folio);
1488+
folio_put(zbv.folio);
1489+
out_allocfolio:
14891490
page = erofs_allocpage(&f->pagepool, gfp | __GFP_NOFAIL);
14901491
spin_lock(&pcl->obj.lockref.lock);
1491-
if (pcl->compressed_bvecs[nr].page) {
1492+
if (pcl->compressed_bvecs[nr].folio) {
14921493
erofs_pagepool_add(&f->pagepool, page);
14931494
spin_unlock(&pcl->obj.lockref.lock);
14941495
cond_resched();
14951496
goto repeat;
14961497
}
1497-
pcl->compressed_bvecs[nr].page = page;
1498+
pcl->compressed_bvecs[nr].folio = zbv.folio = page_folio(page);
14981499
spin_unlock(&pcl->obj.lockref.lock);
14991500
bvec->bv_page = page;
15001501
out_tocache:
15011502
if (!tocache || bs != PAGE_SIZE ||
1502-
add_to_page_cache_lru(page, mc, pcl->obj.index + nr, gfp)) {
1503-
/* turn into a temporary shortlived page (1 ref) */
1504-
set_page_private(page, Z_EROFS_SHORTLIVED_PAGE);
1503+
filemap_add_folio(mc, zbv.folio, pcl->obj.index + nr, gfp)) {
1504+
/* turn into a temporary shortlived folio (1 ref) */
1505+
zbv.folio->private = (void *)Z_EROFS_SHORTLIVED_PAGE;
15051506
return;
15061507
}
1507-
attach_page_private(page, pcl);
1508+
folio_attach_private(zbv.folio, pcl);
15081509
/* drop a refcount added by allocpage (then 2 refs in total here) */
1509-
put_page(page);
1510+
folio_put(zbv.folio);
15101511
}
15111512

15121513
static struct z_erofs_decompressqueue *jobqueue_init(struct super_block *sb,

0 commit comments

Comments
 (0)