Skip to content

Commit 05b63d2

Browse files
committed
erofs: allocate extra bvec pages directly instead of retrying
If non-bootstrap bvecs cannot be kept in place (very rarely), an extra short-lived page is allocated. Let's just allocate it immediately rather than do unnecessary -EAGAIN return first and retry as a cleanup. Also it's unnecessary to use __GFP_NOFAIL here since we could gracefully fail out this case instead. Signed-off-by: Gao Xiang <[email protected]> Reviewed-by: Yue Hu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 796e914 commit 05b63d2

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

fs/erofs/zdata.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,17 @@ static int z_erofs_bvec_enqueue(struct z_erofs_bvec_iter *iter,
242242
struct z_erofs_bvec *bvec,
243243
struct page **candidate_bvpage)
244244
{
245-
if (iter->cur == iter->nr) {
246-
if (!*candidate_bvpage)
247-
return -EAGAIN;
248-
245+
if (iter->cur >= iter->nr) {
246+
struct page *nextpage = *candidate_bvpage;
247+
248+
if (!nextpage) {
249+
nextpage = alloc_page(GFP_NOFS);
250+
if (!nextpage)
251+
return -ENOMEM;
252+
set_page_private(nextpage, Z_EROFS_SHORTLIVED_PAGE);
253+
}
249254
DBG_BUGON(iter->bvset->nextpage);
250-
iter->bvset->nextpage = *candidate_bvpage;
255+
iter->bvset->nextpage = nextpage;
251256
z_erofs_bvset_flip(iter);
252257

253258
iter->bvset->nextpage = NULL;
@@ -906,10 +911,8 @@ static bool z_erofs_collector_end(struct z_erofs_decompress_frontend *fe)
906911
z_erofs_bvec_iter_end(&fe->biter);
907912
mutex_unlock(&pcl->lock);
908913

909-
if (fe->candidate_bvpage) {
910-
DBG_BUGON(z_erofs_is_shortlived_page(fe->candidate_bvpage));
914+
if (fe->candidate_bvpage)
911915
fe->candidate_bvpage = NULL;
912-
}
913916

914917
/*
915918
* if all pending pages are added, don't hold its reference
@@ -1054,24 +1057,13 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
10541057
if (cur)
10551058
tight &= (fe->mode >= Z_EROFS_PCLUSTER_FOLLOWED);
10561059

1057-
retry:
10581060
err = z_erofs_attach_page(fe, &((struct z_erofs_bvec) {
10591061
.page = page,
10601062
.offset = offset - map->m_la,
10611063
.end = end,
10621064
}), exclusive);
1063-
/* should allocate an additional short-lived page for bvset */
1064-
if (err == -EAGAIN && !fe->candidate_bvpage) {
1065-
fe->candidate_bvpage = alloc_page(GFP_NOFS | __GFP_NOFAIL);
1066-
set_page_private(fe->candidate_bvpage,
1067-
Z_EROFS_SHORTLIVED_PAGE);
1068-
goto retry;
1069-
}
1070-
1071-
if (err) {
1072-
DBG_BUGON(err == -EAGAIN && fe->candidate_bvpage);
1065+
if (err)
10731066
goto out;
1074-
}
10751067

10761068
z_erofs_onlinepage_split(page);
10771069
/* bump up the number of spiltted parts of a page */

0 commit comments

Comments
 (0)