Skip to content

Commit d136d33

Browse files
committed
erofs: convert z_erofs_onlinepage_.* to folios
Online folios are locked file-backed folios which will eventually keep decoded (e.g. decompressed) data of each inode for end users to utilize. It may belong to a few pclusters and contain other data (e.g. compressed data for inplace I/Os) temporarily in a time-sharing manner to reduce memory footprints for low-ended storage devices with high latencies under heary I/O pressure. Apart from folio_end_read() usage, it's a straight-forward conversion. Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20240305091448.1384242-1-hsiangkao@linux.alibaba.com
1 parent 90d35da commit d136d33

1 file changed

Lines changed: 22 additions & 28 deletions

File tree

fs/erofs/zdata.c

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,46 +117,39 @@ static inline unsigned int z_erofs_pclusterpages(struct z_erofs_pcluster *pcl)
117117
}
118118

119119
/*
120-
* bit 30: I/O error occurred on this page
121-
* bit 0 - 29: remaining parts to complete this page
120+
* bit 30: I/O error occurred on this folio
121+
* bit 0 - 29: remaining parts to complete this folio
122122
*/
123-
#define Z_EROFS_PAGE_EIO (1 << 30)
123+
#define Z_EROFS_FOLIO_EIO (1 << 30)
124124

125-
static inline void z_erofs_onlinepage_init(struct page *page)
125+
static void z_erofs_onlinefolio_init(struct folio *folio)
126126
{
127127
union {
128128
atomic_t o;
129-
unsigned long v;
129+
void *v;
130130
} u = { .o = ATOMIC_INIT(1) };
131131

132-
set_page_private(page, u.v);
133-
smp_wmb();
134-
SetPagePrivate(page);
132+
folio->private = u.v; /* valid only if file-backed folio is locked */
135133
}
136134

137-
static inline void z_erofs_onlinepage_split(struct page *page)
135+
static void z_erofs_onlinefolio_split(struct folio *folio)
138136
{
139-
atomic_inc((atomic_t *)&page->private);
137+
atomic_inc((atomic_t *)&folio->private);
140138
}
141139

142-
static void z_erofs_onlinepage_endio(struct page *page, int err)
140+
static void z_erofs_onlinefolio_end(struct folio *folio, int err)
143141
{
144142
int orig, v;
145143

146-
DBG_BUGON(!PagePrivate(page));
147-
148144
do {
149-
orig = atomic_read((atomic_t *)&page->private);
150-
v = (orig - 1) | (err ? Z_EROFS_PAGE_EIO : 0);
151-
} while (atomic_cmpxchg((atomic_t *)&page->private, orig, v) != orig);
145+
orig = atomic_read((atomic_t *)&folio->private);
146+
v = (orig - 1) | (err ? Z_EROFS_FOLIO_EIO : 0);
147+
} while (atomic_cmpxchg((atomic_t *)&folio->private, orig, v) != orig);
152148

153-
if (!(v & ~Z_EROFS_PAGE_EIO)) {
154-
set_page_private(page, 0);
155-
ClearPagePrivate(page);
156-
if (!(v & Z_EROFS_PAGE_EIO))
157-
SetPageUptodate(page);
158-
unlock_page(page);
159-
}
149+
if (v & ~Z_EROFS_FOLIO_EIO)
150+
return;
151+
folio->private = 0;
152+
folio_end_read(folio, !(v & Z_EROFS_FOLIO_EIO));
160153
}
161154

162155
#define Z_EROFS_ONSTACK_PAGES 32
@@ -965,6 +958,7 @@ static int z_erofs_read_fragment(struct super_block *sb, struct page *page,
965958
static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
966959
struct page *page, bool ra)
967960
{
961+
struct folio *folio = page_folio(page);
968962
struct inode *const inode = fe->inode;
969963
struct erofs_map_blocks *const map = &fe->map;
970964
const loff_t offset = page_offset(page);
@@ -973,7 +967,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
973967
unsigned int cur, end, len, split;
974968
int err = 0;
975969

976-
z_erofs_onlinepage_init(page);
970+
z_erofs_onlinefolio_init(folio);
977971
split = 0;
978972
end = PAGE_SIZE;
979973
repeat:
@@ -1035,7 +1029,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
10351029
if (err)
10361030
goto out;
10371031

1038-
z_erofs_onlinepage_split(page);
1032+
z_erofs_onlinefolio_split(folio);
10391033
if (fe->pcl->pageofs_out != (map->m_la & ~PAGE_MASK))
10401034
fe->pcl->multibases = true;
10411035
if (fe->pcl->length < offset + end - map->m_la) {
@@ -1056,7 +1050,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
10561050
goto repeat;
10571051

10581052
out:
1059-
z_erofs_onlinepage_endio(page, err);
1053+
z_erofs_onlinefolio_end(folio, err);
10601054
return err;
10611055
}
10621056

@@ -1159,7 +1153,7 @@ static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *be,
11591153
cur += len;
11601154
}
11611155
kunmap_local(dst);
1162-
z_erofs_onlinepage_endio(bvi->bvec.page, err);
1156+
z_erofs_onlinefolio_end(page_folio(bvi->bvec.page), err);
11631157
list_del(p);
11641158
kfree(bvi);
11651159
}
@@ -1316,7 +1310,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
13161310
/* recycle all individual short-lived pages */
13171311
if (z_erofs_put_shortlivedpage(be->pagepool, page))
13181312
continue;
1319-
z_erofs_onlinepage_endio(page, err);
1313+
z_erofs_onlinefolio_end(page_folio(page), err);
13201314
}
13211315

13221316
if (be->decompressed_pages != be->onstack_pages)

0 commit comments

Comments
 (0)