From fdae1f4c1190986ed8dcaa4b25907374f7e18f3d Mon Sep 17 00:00:00 2001 From: Chunhai Guo <guochunhai@vivo.com> Date: Fri, 6 Sep 2024 06:11:10 -0600 Subject: [PATCH] BACKPORT: erofs: allocate more short-lived pages from reserved pool first This patch aims to allocate bvpages and short-lived compressed pages from the reserved pool first. After applying this patch, there are three benefits. 1. It reduces the page allocation time. The bvpages and short-lived compressed pages account for about 4% of the pages allocated from the system in the multi-app launch benchmarks [1]. It reduces the page allocation time accordingly and lowers the likelihood of blockage by page allocation in low memory scenarios. 2. The pages in the reserved pool will be allocated on demand. Currently, bvpages and short-lived compressed pages are short-lived pages allocated from the system, and the pages in the reserved pool all originate from short-lived pages. Consequently, the number of reserved pool pages will increase to z_erofs_rsv_nrpages over time. With this patch, all short-lived pages are allocated from the reserved pool first, so the number of reserved pool pages will only increase when there are not enough pages. Thus, even if z_erofs_rsv_nrpages is set to a large number for specific reasons, the actual number of reserved pool pages may remain low as per demand. In the multi-app launch benchmarks [1], z_erofs_rsv_nrpages is set at 256, while the number of reserved pool pages remains below 64. 3. When erofs cache decompression is disabled (EROFS_ZIP_CACHE_DISABLED), all pages will *only* be allocated from the reserved pool for erofs. This will significantly reduce the memory pressure from erofs. [1] For additional details on the multi-app launch benchmarks, please refer to commit 0f6273ab4637 ("erofs: add a reserved buffer pool for lz4 decompression"). Signed-off-by: Chunhai Guo <guochunhai@vivo.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Reviewed-by: Chao Yu <chao@kernel.org> Link: https://lore.kernel.org/r/20240906121110.3701889-1-guochunhai@vivo.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Bug: 387202250 Bug: 404427448 Change-Id: Ife45adcb4c22c9d73952db1de956e1b9cda1b8c2 (cherry picked from commit 79f504a2cd3c0b7d953d0015618a2a41559a2cfd) Signed-off-by: liujinbao1 <liujinbao1@xiaomi.corp-partner.google.com> (cherry picked from commit 6e7af99d68e309a0a1a14e7674406d9462e1b0bb) --- fs/erofs/zdata.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index bb474619f9d39..038cd474b706f 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -233,7 +233,8 @@ static int z_erofs_bvec_enqueue(struct z_erofs_bvec_iter *iter, struct page *nextpage = *candidate_bvpage; if (!nextpage) { - nextpage = erofs_allocpage(pagepool, GFP_KERNEL); + nextpage = __erofs_allocpage(pagepool, GFP_KERNEL, + true); if (!nextpage) return -ENOMEM; set_page_private(nextpage, Z_EROFS_SHORTLIVED_PAGE); @@ -1517,7 +1518,7 @@ static void z_erofs_fill_bio_vec(struct bio_vec *bvec, unlock_page(page); put_page(page); out_allocpage: - page = erofs_allocpage(&f->pagepool, gfp | __GFP_NOFAIL); + page = __erofs_allocpage(&f->pagepool, gfp | __GFP_NOFAIL, true); spin_lock(&pcl->obj.lockref.lock); if (pcl->compressed_bvecs[nr].page) { erofs_pagepool_add(&f->pagepool, page); -- GitLab