Skip to content

Commit cef58a3

Browse files
hsiangkaogregkh
authored andcommitted
erofs: allocate extra bvec pages directly instead of retrying
[ Upstream commit 05b63d2beb8b0f752d1f5cdd051c8bdbf532cedd ] 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] Stable-dep-of: 99f7619a77a0 ("erofs: fix to add missing tracepoint in erofs_read_folio()") Signed-off-by: Sasha Levin <[email protected]>
1 parent 241d3c6 commit cef58a3

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
@@ -238,12 +238,17 @@ static int z_erofs_bvec_enqueue(struct z_erofs_bvec_iter *iter,
238238
struct z_erofs_bvec *bvec,
239239
struct page **candidate_bvpage)
240240
{
241-
if (iter->cur == iter->nr) {
242-
if (!*candidate_bvpage)
243-
return -EAGAIN;
244-
241+
if (iter->cur >= iter->nr) {
242+
struct page *nextpage = *candidate_bvpage;
243+
244+
if (!nextpage) {
245+
nextpage = alloc_page(GFP_NOFS);
246+
if (!nextpage)
247+
return -ENOMEM;
248+
set_page_private(nextpage, Z_EROFS_SHORTLIVED_PAGE);
249+
}
245250
DBG_BUGON(iter->bvset->nextpage);
246-
iter->bvset->nextpage = *candidate_bvpage;
251+
iter->bvset->nextpage = nextpage;
247252
z_erofs_bvset_flip(iter);
248253

249254
iter->bvset->nextpage = NULL;
@@ -744,10 +749,8 @@ static bool z_erofs_collector_end(struct z_erofs_decompress_frontend *fe)
744749
z_erofs_bvec_iter_end(&fe->biter);
745750
mutex_unlock(&pcl->lock);
746751

747-
if (fe->candidate_bvpage) {
748-
DBG_BUGON(z_erofs_is_shortlived_page(fe->candidate_bvpage));
752+
if (fe->candidate_bvpage)
749753
fe->candidate_bvpage = NULL;
750-
}
751754

752755
/*
753756
* if all pending pages are added, don't hold its reference
@@ -896,24 +899,13 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
896899
if (cur)
897900
tight &= (fe->mode >= Z_EROFS_PCLUSTER_FOLLOWED);
898901

899-
retry:
900902
err = z_erofs_attach_page(fe, &((struct z_erofs_bvec) {
901903
.page = page,
902904
.offset = offset - map->m_la,
903905
.end = end,
904906
}), exclusive);
905-
/* should allocate an additional short-lived page for bvset */
906-
if (err == -EAGAIN && !fe->candidate_bvpage) {
907-
fe->candidate_bvpage = alloc_page(GFP_NOFS | __GFP_NOFAIL);
908-
set_page_private(fe->candidate_bvpage,
909-
Z_EROFS_SHORTLIVED_PAGE);
910-
goto retry;
911-
}
912-
913-
if (err) {
914-
DBG_BUGON(err == -EAGAIN && fe->candidate_bvpage);
907+
if (err)
915908
goto out;
916-
}
917909

918910
z_erofs_onlinepage_split(page);
919911
/* bump up the number of spiltted parts of a page */

0 commit comments

Comments
 (0)