mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
BACKPORT: erofs: relaxed temporary buffers allocation on readahead
Even with inplace decompression, sometimes very few temporary buffers may be still needed for a single decompression shot (e.g. 16 pages for 64k sliding window or 4 pages for 16k sliding window). In low-memory scenarios, it would be better to try to allocate with GFP_NOWAIT on readahead first. That can help reduce the time spent on page allocation under durative memory pressure. Here are detailed performance numbers under multi-app launch benchmark workload [1] on ARM64 Android devices (8-core CPU and 8GB of memory) running a 5.15 LTS kernel with EROFS of 4k pclusters: +----------------------------------------------+ | LZ4 | vanilla | patched | diff | |----------------+---------+---------+---------| | Average (ms) | 3364 | 2684 | -20.21% | [64k sliding window] |----------------+---------+---------+---------| | Average (ms) | 2079 | 1610 | -22.56% | [16k sliding window] +----------------------------------------------+ The total size of system images for 4k pclusters is almost unchanged: (64k sliding window) 9,117,044 KB (16k sliding window) 9,113,096 KB Therefore, in addition to switch the sliding window from 64k to 16k, after applying this patch, it can eventually save 52.14% (3364 -> 1610) on average with no memory reservation. That is particularly useful for embedded devices with limited resources. [1] https://lore.kernel.org/r/20240109074143.4138783-1-guochunhai@vivo.com Suggested-by: Gao Xiang <xiang@kernel.org> Signed-off-by: Chunhai Guo <guochunhai@vivo.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Reviewed-by: Yue Hu <huyue2@coolpad.com> Link: https://lore.kernel.org/r/20240126140142.201718-1-hsiangkao@linux.alibaba.com Bug: 348591003 Change-Id: I84cf5b5dbccbd707b6f4339e525ca52efbcf167f (cherry picked from commit d9281660ff3ffb4a05302b485cc59a87e709aefc) [Chunhai: Resolved minor conflict in fs/erofs/zdata.c and remove modification on fs/erofs/decompressor_deflate.c as it is not existed in 6.1 kernel ] Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
This commit is contained in:
committed by
Matthias Männich
parent
a3fb83b3f5
commit
bab4765e5f
@@ -11,13 +11,12 @@
|
||||
struct z_erofs_decompress_req {
|
||||
struct super_block *sb;
|
||||
struct page **in, **out;
|
||||
|
||||
unsigned short pageofs_in, pageofs_out;
|
||||
unsigned int inputsize, outputsize;
|
||||
|
||||
/* indicate the algorithm will be used for decompression */
|
||||
unsigned int alg;
|
||||
unsigned int alg; /* the algorithm for decompression */
|
||||
bool inplace_io, partial_decoding, fillgaps;
|
||||
gfp_t gfp; /* allocation flags for extra temporary buffers */
|
||||
};
|
||||
|
||||
struct z_erofs_decompressor {
|
||||
|
||||
@@ -112,8 +112,9 @@ static int z_erofs_lz4_prepare_dstpages(struct z_erofs_lz4_decompress_ctx *ctx,
|
||||
victim = availables[--top];
|
||||
get_page(victim);
|
||||
} else {
|
||||
victim = erofs_allocpage(pagepool,
|
||||
GFP_KERNEL | __GFP_NOFAIL);
|
||||
victim = erofs_allocpage(pagepool, rq->gfp);
|
||||
if (!victim)
|
||||
return -ENOMEM;
|
||||
set_page_private(victim, Z_EROFS_SHORTLIVED_PAGE);
|
||||
}
|
||||
rq->out[i] = victim;
|
||||
|
||||
@@ -151,7 +151,7 @@ again:
|
||||
}
|
||||
|
||||
int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
|
||||
struct page **pagepool)
|
||||
struct page **pgpl)
|
||||
{
|
||||
const unsigned int nrpages_out =
|
||||
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
|
||||
@@ -218,8 +218,11 @@ again:
|
||||
PAGE_SIZE - pageofs);
|
||||
outlen -= strm->buf.out_size;
|
||||
if (!rq->out[no] && rq->fillgaps) { /* deduped */
|
||||
rq->out[no] = erofs_allocpage(pagepool,
|
||||
GFP_KERNEL | __GFP_NOFAIL);
|
||||
rq->out[no] = erofs_allocpage(pgpl, rq->gfp);
|
||||
if (!rq->out[no]) {
|
||||
err = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
set_page_private(rq->out[no],
|
||||
Z_EROFS_SHORTLIVED_PAGE);
|
||||
}
|
||||
@@ -261,8 +264,11 @@ again:
|
||||
|
||||
DBG_BUGON(erofs_page_is_managed(EROFS_SB(rq->sb),
|
||||
rq->in[j]));
|
||||
tmppage = erofs_allocpage(pagepool,
|
||||
GFP_KERNEL | __GFP_NOFAIL);
|
||||
tmppage = erofs_allocpage(pgpl, rq->gfp);
|
||||
if (!tmppage) {
|
||||
err = -ENOMEM;
|
||||
goto failed;
|
||||
}
|
||||
set_page_private(tmppage, Z_EROFS_SHORTLIVED_PAGE);
|
||||
copy_highpage(tmppage, rq->in[j]);
|
||||
rq->in[j] = tmppage;
|
||||
@@ -280,6 +286,7 @@ again:
|
||||
break;
|
||||
}
|
||||
}
|
||||
failed:
|
||||
if (no < nrpages_out && strm->buf.out)
|
||||
kunmap(rq->out[no]);
|
||||
if (ni < nrpages_in)
|
||||
|
||||
@@ -83,6 +83,9 @@ struct z_erofs_pcluster {
|
||||
/* L: indicate several pageofs_outs or not */
|
||||
bool multibases;
|
||||
|
||||
/* L: whether extra buffer allocations are best-effort */
|
||||
bool besteffort;
|
||||
|
||||
/* A: compressed bvecs (can be cached or inplaced pages) */
|
||||
struct z_erofs_bvec compressed_bvecs[];
|
||||
};
|
||||
@@ -972,7 +975,7 @@ static int z_erofs_read_fragment(struct super_block *sb, struct page *page,
|
||||
}
|
||||
|
||||
static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
|
||||
struct page *page)
|
||||
struct page *page, bool ra)
|
||||
{
|
||||
struct inode *const inode = fe->inode;
|
||||
struct erofs_map_blocks *const map = &fe->map;
|
||||
@@ -1023,6 +1026,7 @@ repeat:
|
||||
err = z_erofs_pcluster_begin(fe);
|
||||
if (err)
|
||||
goto out;
|
||||
fe->pcl->besteffort |= !ra;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1305,6 +1309,9 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
|
||||
.inplace_io = overlapped,
|
||||
.partial_decoding = pcl->partial,
|
||||
.fillgaps = pcl->multibases,
|
||||
.gfp = pcl->besteffort ?
|
||||
GFP_KERNEL | __GFP_NOFAIL :
|
||||
GFP_NOWAIT | __GFP_NORETRY
|
||||
}, be->pagepool);
|
||||
|
||||
out:
|
||||
@@ -1350,6 +1357,7 @@ out:
|
||||
pcl->length = 0;
|
||||
pcl->partial = true;
|
||||
pcl->multibases = false;
|
||||
pcl->besteffort = false;
|
||||
pcl->bvset.nextpage = NULL;
|
||||
pcl->vcnt = 0;
|
||||
|
||||
@@ -1815,7 +1823,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
|
||||
if (PageUptodate(page)) {
|
||||
unlock_page(page);
|
||||
} else {
|
||||
err = z_erofs_do_read_page(f, page);
|
||||
err = z_erofs_do_read_page(f, page, !!rac);
|
||||
if (err)
|
||||
erofs_err(inode->i_sb,
|
||||
"readmore error at page %lu @ nid %llu",
|
||||
@@ -1842,7 +1850,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio)
|
||||
f.headoffset = (erofs_off_t)page->index << PAGE_SHIFT;
|
||||
|
||||
z_erofs_pcluster_readmore(&f, NULL, true);
|
||||
err = z_erofs_do_read_page(&f, page);
|
||||
err = z_erofs_do_read_page(&f, page, false);
|
||||
z_erofs_pcluster_readmore(&f, NULL, false);
|
||||
z_erofs_pcluster_end(&f);
|
||||
|
||||
@@ -1883,7 +1891,7 @@ static void z_erofs_readahead(struct readahead_control *rac)
|
||||
/* traversal in reverse order */
|
||||
head = (void *)page_private(page);
|
||||
|
||||
err = z_erofs_do_read_page(&f, page);
|
||||
err = z_erofs_do_read_page(&f, page, true);
|
||||
if (err)
|
||||
erofs_err(inode->i_sb,
|
||||
"readahead error at page %lu @ nid %llu",
|
||||
|
||||
Reference in New Issue
Block a user