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 0f6273ab46 ("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>
This commit is contained in:
Chunhai Guo 2024-09-06 06:11:10 -06:00 committed by Gao Xiang
parent 2349d2fa02
commit 79f504a2cd

View File

@ -196,7 +196,8 @@ static int z_erofs_bvec_enqueue(struct z_erofs_bvec_iter *iter,
struct page *nextpage = *candidate_bvpage; struct page *nextpage = *candidate_bvpage;
if (!nextpage) { if (!nextpage) {
nextpage = erofs_allocpage(pagepool, GFP_KERNEL); nextpage = __erofs_allocpage(pagepool, GFP_KERNEL,
true);
if (!nextpage) if (!nextpage)
return -ENOMEM; return -ENOMEM;
set_page_private(nextpage, Z_EROFS_SHORTLIVED_PAGE); set_page_private(nextpage, Z_EROFS_SHORTLIVED_PAGE);
@ -1464,7 +1465,7 @@ repeat:
folio_unlock(folio); folio_unlock(folio);
folio_put(folio); folio_put(folio);
out_allocfolio: out_allocfolio:
page = erofs_allocpage(&f->pagepool, gfp); page = __erofs_allocpage(&f->pagepool, gfp, true);
spin_lock(&pcl->obj.lockref.lock); spin_lock(&pcl->obj.lockref.lock);
if (unlikely(pcl->compressed_bvecs[nr].page != zbv.page)) { if (unlikely(pcl->compressed_bvecs[nr].page != zbv.page)) {
if (page) if (page)