erofs: relaxed temporary buffers allocation on readahead
PATCH v2 1/1 erofs: relaxed temporary buffers allocation on readahead
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. 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 memory pressure.
There is an average reduction of 21% in page allocation time under multi-app launch benchmark workload [1] on ARM64 Android devices running the 5.15 kernel with an 8-core CPU and 8GB of memory.
[1] https://lore.kernel.org/r/[email protected]
--- fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)
fs/erofs/compress.h +2 -3
@@ -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 {
fs/erofs/decompressor.c +3 -2
@@ -111,8 +111,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;
fs/erofs/decompressor_deflate.c +13 -6
@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;
@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }
@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;
@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)
fs/erofs/decompressor_lzma.c +12 -5
@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;
@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }
@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;
@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)
fs/erofs/zdata.c +12 -4
@@ -82,6 +82,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[]; };
@@ -964,7 +967,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;
@@ -1014,6 +1017,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/*
@@ -1280,7 +1284,11 @@ 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); + pcl->besteffort = false;/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {
@@ -1785,7 +1793,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }
@@ -1806,7 +1814,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);
@@ -1847,7 +1855,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Signature · 1 line
2.25.1
Quoted 6 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
Otherwise it looks good to me,
Thanks,
Gao Xiang
Quoted 221 lines
multi-app launch benchmark workload [1] on ARM64 Android devices running the 5.15 kernel with an 8-core CPU and 8GB of memory.
[1] https://lore.kernel.org/r/[email protected]
Suggested-by Gao Xiang <[email protected]>Signed-off-by Chunhai Guo <[email protected]>--- fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)fs/erofs/compress.h +2
-3@@ -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 {fs/erofs/decompressor.c +3
-2@@ -111,8 +111,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;fs/erofs/decompressor_deflate.c +13
-6@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)fs/erofs/decompressor_lzma.c +12
-5@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)fs/erofs/zdata.c +12
-4@@ -82,6 +82,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[]; };@@ -964,7 +967,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;@@ -1014,6 +1017,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/* @@ -1280,7 +1284,11 @@ 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); + pcl->besteffort = false;/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {@@ -1785,7 +1793,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }@@ -1806,7 +1814,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);@@ -1847,7 +1855,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Quoted 8 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.
Quoted 5 lines
Quoted 1 line
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+
Thanks,
Quoted 227 lines
Otherwise it looks good to me,
Thanks,
Gao XiangQuoted 221 lines
multi-app launch benchmark workload [1] on ARM64 Android devices running the 5.15 kernel with an 8-core CPU and 8GB of memory.
[1] https://lore.kernel.org/r/[email protected]
Suggested-by Gao Xiang <[email protected]>Signed-off-by Chunhai Guo <[email protected]>--- fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)fs/erofs/compress.h +2
-3@@ -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 {fs/erofs/decompressor.c +3
-2@@ -111,8 +111,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;fs/erofs/decompressor_deflate.c +13
-6@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)fs/erofs/decompressor_lzma.c +12
-5@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)fs/erofs/zdata.c +12
-4@@ -82,6 +82,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[]; };@@ -964,7 +967,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;@@ -1014,6 +1017,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/* @@ -1280,7 +1284,11 @@ 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); + pcl->besteffort = false;/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {@@ -1785,7 +1793,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }@@ -1806,7 +1814,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);@@ -1847,7 +1855,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Quoted 21 lines · Chunhai Guo
Quoted 8 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.Quoted 5 lines
Quoted 1 line
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
Quoted 5 lines
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+
Did it test without the 16k sliding window change?
https://lore.kernel.org/linux-erofs/[email protected]
Could you benchmark these two optimizations together to show the extreme optimized case without a global pool? With a new table if possible? I will add this to the commit message too.
Thanks,
Gao Xiang
Quoted 233 lines
Thanks,
Quoted 227 lines
Otherwise it looks good to me,
Thanks,
Gao XiangQuoted 221 lines
multi-app launch benchmark workload [1] on ARM64 Android devices running the 5.15 kernel with an 8-core CPU and 8GB of memory.
[1] https://lore.kernel.org/r/[email protected]
Suggested-by Gao Xiang <[email protected]>Signed-off-by Chunhai Guo <[email protected]>--- fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)fs/erofs/compress.h +2
-3@@ -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 {fs/erofs/decompressor.c +3
-2@@ -111,8 +111,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;fs/erofs/decompressor_deflate.c +13
-6@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)fs/erofs/decompressor_lzma.c +12
-5@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)fs/erofs/zdata.c +12
-4@@ -82,6 +82,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[]; };@@ -964,7 +967,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;@@ -1014,6 +1017,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/* @@ -1280,7 +1284,11 @@ 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); + pcl->besteffort = false;/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {@@ -1785,7 +1793,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }@@ -1806,7 +1814,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);@@ -1847,7 +1855,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Quoted 23 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 20 lines · Chunhai Guo
Quoted 8 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.Quoted 5 lines
Quoted 1 line
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
Quoted 7 lines
Quoted 5 lines
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+Did it test without the 16k sliding window change?
https://lore.kernel.org/linux-erofs/[email protected]
The result is tested with 64k sliding window change.
Quoted 4 lines
Could you benchmark these two optimizations together to show the extreme optimized case without a global pool? With a new table if possible? I will add this to the commit message too.
OK. I will reply to this email when the benchmark is finished.
Quoted 233 lines
Thanks,
Gao XiangQuoted 230 lines
Thanks,
Quoted 226 lines
Otherwise it looks good to me,
Thanks,
Gao XiangQuoted 221 lines
multi-app launch benchmark workload [1] on ARM64 Android devices running the 5.15 kernel with an 8-core CPU and 8GB of memory.
[1] https://lore.kernel.org/r/[email protected]
Suggested-by Gao Xiang <[email protected]>Signed-off-by Chunhai Guo <[email protected]>--- fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)fs/erofs/compress.h +2
-3@@ -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 {fs/erofs/decompressor.c +3
-2@@ -111,8 +111,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;fs/erofs/decompressor_deflate.c +13
-6@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)fs/erofs/decompressor_lzma.c +12
-5@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)fs/erofs/zdata.c +12
-4@@ -82,6 +82,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[]; };@@ -964,7 +967,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;@@ -1014,6 +1017,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/* @@ -1280,7 +1284,11 @@ 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); + pcl->besteffort = false;/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {@@ -1785,7 +1793,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }@@ -1806,7 +1814,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);@@ -1847,7 +1855,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Quoted 30 lines · Chunhai Guo
Quoted 22 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 19 lines · Chunhai Guo
Quoted 8 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.Quoted 5 lines
Quoted 1 line
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
Quoted 7 lines
Quoted 5 lines
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+Did it test without the 16k sliding window change?
https://lore.kernel.org/linux-erofs/[email protected]
Quoted 8 lines
The result is tested with 64k sliding window change.
Quoted 4 lines
Could you benchmark these two optimizations together to show the extreme optimized case without a global pool? With a new table if possible? I will add this to the commit message too.
OK. I will reply to this email when the benchmark is finished.
The benchmark has been completed and the table below shows that there is an average 52.14% reduction in page allocation time with these two optimizations.
+--------------+----------------+---------------+---------+ | | 64k window | 16k window | | | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 1610 | -52.14% | +--------------+----------------+---------------+---------+
Table below summarizes the results of these three benchmarks.
+--------------+----------------+----------------+---------------+---------------+ | | 64k window | 16k window | 64k window | 16k window | | | w/o GFP_NOWAIT | w/o GFP_NOWAIT | w/ GFP_NOWAIT | w/ GFP_NOWAIT | +--------------+----------------+----------------+---------------+---------------+ | Average (ms) | 3364 | 2079 | 2684 | 1610 | +--------------+----------------+----------------+---------------+---------------+ | diff | | -38.19% | -20.81% | -52.14% | +--------------+----------------+----------------+---------------+---------------+
Thanks.
Quoted 232 lines
Quoted 232 lines
Thanks,
Gao XiangQuoted 229 lines
Thanks,
Quoted 226 lines
Otherwise it looks good to me,
Thanks,
Gao XiangQuoted 221 lines
multi-app launch benchmark workload [1] on ARM64 Android devices running the 5.15 kernel with an 8-core CPU and 8GB of memory.
[1] https://lore.kernel.org/r/[email protected]
Suggested-by Gao Xiang <[email protected]>Signed-off-by Chunhai Guo <[email protected]>--- fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)fs/erofs/compress.h +2
-3@@ -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 {fs/erofs/decompressor.c +3
-2@@ -111,8 +111,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;fs/erofs/decompressor_deflate.c +13
-6@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)fs/erofs/decompressor_lzma.c +12
-5@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)fs/erofs/zdata.c +12
-4@@ -82,6 +82,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[]; };@@ -964,7 +967,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;@@ -1014,6 +1017,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/* @@ -1280,7 +1284,11 @@ 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); + pcl->besteffort = false;/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {@@ -1785,7 +1793,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }@@ -1806,7 +1814,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);@@ -1847,7 +1855,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Quoted 52 lines · Chunhai Guo
Quoted 30 lines · Chunhai Guo
Quoted 22 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 19 lines · Chunhai Guo
Quoted 8 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.Quoted 5 lines
Quoted 1 line
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
Quoted 7 lines
Quoted 5 lines
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+Did it test without the 16k sliding window change?
https://lore.kernel.org/linux-erofs/[email protected]Quoted 8 lines
The result is tested with 64k sliding window change.
Quoted 4 lines
Could you benchmark these two optimizations together to show the extreme optimized case without a global pool? With a new table if possible? I will add this to the commit message too.
OK. I will reply to this email when the benchmark is finished.
The benchmark has been completed and the table below shows that there is an average 52.14% reduction in page allocation time with these two optimizations.
+--------------+----------------+---------------+---------+ | | 64k window | 16k window | | | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 1610 | -52.14% | +--------------+----------------+---------------+---------+Table below summarizes the results of these three benchmarks.
Quoted 12 lines
+--------------+----------------+----------------+---------------+---------------+ | | 64k window | 16k window | 64k window | 16k window | | | w/o GFP_NOWAIT | w/o GFP_NOWAIT | w/ GFP_NOWAIT | w/ GFP_NOWAIT | +--------------+----------------+----------------+---------------+---------------+ | Average (ms) | 3364 | 2079 | 2684 | 1610 | +--------------+----------------+----------------+---------------+---------------+ | diff | | -38.19% | -20.81% | -52.14% | +--------------+----------------+----------------+---------------+---------------+
The tables shows in a mess, could you just list the numbers so I could refine this?
Thanks,
Gao Xiang
Quoted 66 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 50 lines · Chunhai Guo
Quoted 30 lines · Chunhai Guo
Quoted 22 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 19 lines · Chunhai Guo
Quoted 8 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.Quoted 5 lines
Quoted 1 line
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
Quoted 7 lines
Quoted 5 lines
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+Did it test without the 16k sliding window change?
https://lore.kernel.org/linux-erofs/[email protected]Quoted 7 lines
The result is tested with 64k sliding window change.
Quoted 4 lines
Could you benchmark these two optimizations together to show the extreme optimized case without a global pool? With a new table if possible? I will add this to the commit message too.
OK. I will reply to this email when the benchmark is finished.
The benchmark has been completed and the table below shows that there is an average 52.14% reduction in page allocation time with these two optimizations.
+--------------+----------------+---------------+---------+ | | 64k window | 16k window | | | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 1610 | -52.14% | +--------------+----------------+---------------+---------+Table below summarizes the results of these three benchmarks.
Quoted 12 lines
+--------------+----------------+----------------+---------------+---------------+ | | 64k window | 16k window | 64k window | 16k window | | | w/o GFP_NOWAIT | w/o GFP_NOWAIT | w/ GFP_NOWAIT | w/ GFP_NOWAIT | +--------------+----------------+----------------+---------------+---------------+ | Average (ms) | 3364 | 2079 | 2684 | 1610 | +--------------+----------------+----------------+---------------+---------------+ | diff | | -38.19% | -20.81% | -52.14% | +--------------+----------------+----------------+---------------+---------------+
Quoted 2 lines
The tables shows in a mess, could you just list the numbers so I could refine this?
Sorry that there might be some issues with my email client. Here are the numerical results below.
64k window w/o GFP_NOWAIT : 3364
16k window w/o GFP_NOWAIT : 2079, diff: -38.19%
64k window w/ GFP_NOWAIT : 2684, diff: -20.81%
16k window w/ GFP_NOWAIT : 1610, diff: -52.14%Images size comparision:
64k: 9117044 KB
16k: 9113096 KBThanks,
Quoted 3 lines
Thanks,
Gao Xiang
Quoted 72 lines · Chunhai Guo
Quoted 66 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 50 lines · Chunhai Guo
Quoted 30 lines · Chunhai Guo
Quoted 22 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 19 lines · Chunhai Guo
Quoted 8 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines · Chunhai Guo
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spent on page allocation under memory pressure.Quoted 5 lines
Quoted 1 line
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit manually.
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
Quoted 7 lines
Quoted 5 lines
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+Did it test without the 16k sliding window change?
https://lore.kernel.org/linux-erofs/[email protected]Quoted 7 lines
The result is tested with 64k sliding window change.
Quoted 4 lines
Could you benchmark these two optimizations together to show the extreme optimized case without a global pool? With a new table if possible? I will add this to the commit message too.
OK. I will reply to this email when the benchmark is finished.
The benchmark has been completed and the table below shows that there is an average 52.14% reduction in page allocation time with these two optimizations.
+--------------+----------------+---------------+---------+ | | 64k window | 16k window | | | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 1610 | -52.14% | +--------------+----------------+---------------+---------+Table below summarizes the results of these three benchmarks.
Quoted 12 lines
+--------------+----------------+----------------+---------------+---------------+ | | 64k window | 16k window | 64k window | 16k window | | | w/o GFP_NOWAIT | w/o GFP_NOWAIT | w/ GFP_NOWAIT | w/ GFP_NOWAIT | +--------------+----------------+----------------+---------------+---------------+ | Average (ms) | 3364 | 2079 | 2684 | 1610 | +--------------+----------------+----------------+---------------+---------------+ | diff | | -38.19% | -20.81% | -52.14% | +--------------+----------------+----------------+---------------+---------------+Quoted 2 lines
The tables shows in a mess, could you just list the numbers so I could refine this?
Sorry that there might be some issues with my email client. Here are the numerical results below.
Quoted 8 lines
64k window w/o GFP_NOWAIT : 3364 16k window w/o GFP_NOWAIT : 2079, diff: -38.19% 64k window w/ GFP_NOWAIT : 2684, diff: -20.81% 16k window w/ GFP_NOWAIT : 1610, diff: -52.14%Images size comparision:
64k: 9117044 KB 16k: 9113096 KB
That is with 4k pcluster, yes? I guess the overall image size won't have great impacts, but it seems even getting smaller. :-)
I think this optimization would be helpful to everyone without any extra memory reservation (which will be good too for much much low-ended devices), let me revise the commit for formal submission..
Thanks,
Gao Xiang
Quoted 8 lines
Thanks,
Quoted 3 lines
Thanks,
Gao Xiang
Quoted 117 lines
-----邮件原件-----
发件人: Gao Xiang <[email protected]>
发送时间: 2024年1月26日 11:50
收件人: Chunhai Guo <[email protected]>; [email protected]
抄送: [email protected]; [email protected]; [email protected]; [email protected]
主题: Re: [PATCH v2] erofs: relaxed temporary buffers allocation on readahead[你通常不会收到来自 [email protected] 的电子邮件。请访问
https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]Quoted 3 lines · Chunhai Guo
Quoted 2 lines · Gao Xiang
[你通常不会收到来自 [email protected] 的电子邮件。请访问
https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
Quoted 5 lines
Quoted 5 lines · Chunhai Guo
Quoted 3 lines · Chunhai Guo
Quoted 2 lines · Gao Xiang
Quoted 1 line
[你通常不会收到来自 [email protected] 的电子邮件。请访
问
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
很重要]
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines · Chunhai Guo
Quoted 2 lines · Gao Xiang
Quoted 1 line
[你通常不会收到来自 [email protected] 的电子邮件。请
访问
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
么很重要]
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Chunhai Guo
Quoted 4 lines
Even with inplace decompression, sometimes extra temporary buffers are still needed for decompression. In low-memory scenarios, it would be better to try to allocate with
GFP_NOWAITon readahead first. That can help reduce the time spenton page allocation under memory pressure.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
There is an average reduction of 21% in page allocation time under
It would be better to add a table to show the absolute numbers too (like what you did in the global pool commit.) If it's possible, there is no need to send a update version for this, just reply the updated commit message and I will update the commit
manually.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
The table below shows detailed numbers. The reduction I mentioned before was not accurate enough. Please help correct the improvement from 21% to 20.21%.
+--------------+----------------+---------------+---------+ | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Average (ms) | 3364 | 2684 | -20.21% | +--------------+----------------+---------------+---------+Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Did it test without the 16k sliding window change?
https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
lore.kernel.org%2Flinux-erofs%2F69711d55-f7a2-420b-9ba8-fa2921f66a4c%40vivo.com&data=05%7C02%7Cguochunhai%40vivo.com%7Ceadb2eb3d04 74
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
b3b905708dc1e21d8a0%7C923e42dc48d54cbeb5821a797a6412ed%7C0%7C0% 7C6
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
38418377978918986%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAi LCJQ
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
IjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=I
Quoted 45 lines
Quoted 35 lines
Quoted 21 lines
Quoted 8 lines
Quoted 1 line
QzcxbNhF8ZbG0zCnxAQTba6C3DU6tUC7bzZaISLYJE%3D&reserved=0
The result is tested with 64k sliding window change.
Quoted 4 lines
Could you benchmark these two optimizations together to show the extreme optimized case without a global pool?
With a new table if possible? I will add this to the commit message too.OK. I will reply to this email when the benchmark is finished.
The benchmark has been completed and the table below shows that there is an average 52.14% reduction in page allocation time with these two optimizations.
+--------------+----------------+---------------+---------+ | | 64k window | 16k window | | | | w/o GFP_NOWAIT | w/ GFP_NOWAIT | diff | +--------------+----------------+---------------+---------+ | Averag +--------------+----------------+---------------+---------+ | e (ms) | 3364 | 1610 | -52.14% | +--------------+----------------+---------------+---------+Table below summarizes the results of these three benchmarks.
Quoted 13 lines
+--------------+----------------+----------------+---------------+---------------+ | | 64k window | 16k window | 64k window | 16k window | | | w/o GFP_NOWAIT | w/o GFP_NOWAIT | w/ GFP_NOWAIT | | w/ GFP_NOWAIT | +--------------+----------------+----------------+---------------+---------------+ | Average (ms) | 3364 | 2079 | 2684 | 1610 | +--------------+----------------+----------------+---------------+---------------+ | diff | | -38.19% | -20.81% | -52.14% | +--------------+----------------+----------------+---------------+---------------+Quoted 2 lines
The tables shows in a mess, could you just list the numbers so I could refine this?
Sorry that there might be some issues with my email client. Here are the numerical results below.
64k window w/o GFP_NOWAIT : 3364 16k window w/o GFP_NOWAIT : 2079, diff: -38.19% 64k window w/ GFP_NOWAIT : 2684, diff: -20.81% 16k window w/ GFP_NOWAIT : 1610, diff: -52.14%
Quoted 6 lines
Quoted 3 lines
Images size comparision:
64k: 9117044 KB 16k: 9113096 KBThat is with 4k pcluster, yes? I guess the overall image size won't have great impacts, but it seems even getting smaller. :-)
Yes, this is with 4k pcluster.
Thanks,
Quoted 16 lines
I think this optimization would be helpful to everyone without any extra memory reservation (which will be good too for much much low-ended devices), let me revise the commit for formal submission..
Thanks,
Gao XiangQuoted 8 lines
Thanks,
Quoted 3 lines
Thanks,
Gao Xiang
PATCH v3 1/1 erofs: relaxed temporary buffers allocation on readahead
From: Chunhai Guo <[email protected]>
Even with inplace decompression, sometimes very few temporary buffers are 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 pcluster 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/[email protected]
---
v2: https://lore.kernel.org/r/[email protected]
change since v2:
- update commit message according to test results.
I plan to apply this version.
fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)
fs/erofs/compress.h +2 -3
@@ -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 {
fs/erofs/decompressor.c +3 -2
@@ -111,8 +111,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;
fs/erofs/decompressor_deflate.c +13 -6
@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;
@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }
@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;
@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)
fs/erofs/decompressor_lzma.c +12 -5
@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;
@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }
@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;
@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)
fs/erofs/zdata.c +12 -4
@@ -82,6 +82,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[]; };
@@ -960,7 +963,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;
@@ -1010,6 +1013,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/*
@@ -1276,7 +1280,11 @@ 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); + pcl->besteffort = false;/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {
@@ -1787,7 +1795,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }
@@ -1808,7 +1816,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);
@@ -1849,7 +1857,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Signature · 1 line
2.39.3
Yue Hu
reviewerQuoted 217 lines · On Fri, 26 Jan 2024 13:36:16 +0800 Gao Xiang <[email protected]>…
From: Chunhai Guo <[email protected]>
Even with inplace decompression, sometimes very few temporary buffers are 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_NOWAITon 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 pcluster is almost unchanged:
(64k sliding window) 9,117,044 KB
(16k sliding window) 9,113,096 KBTherefore, 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/[email protected]
Suggested-by Gao Xiang <[email protected]>Signed-off-by Chunhai Guo <[email protected]>Signed-off-by Gao Xiang <[email protected]>---
v2: https://lore.kernel.org/r/[email protected]
change since v2:
- update commit message according to test results.I plan to apply this version.
fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)fs/erofs/compress.h +2
-3@@ -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 {fs/erofs/decompressor.c +3
-2@@ -111,8 +111,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;fs/erofs/decompressor_deflate.c +13
-6@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)fs/erofs/decompressor_lzma.c +12
-5@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)fs/erofs/zdata.c +5
-1@@ -82,6 +82,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[]; };@@ -960,7 +963,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;@@ -1010,6 +1013,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/*
fs/erofs/zdata.c static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, · line 1287
Quoted 8 lines
fs/erofs/zdata.c +4
-0@@ -1276,7 +1280,11 @@ 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); + pcl->besteffort = false;
reposition it following pcl->multibases = false?
Quoted 30 lines
fs/erofs/zdata.c +3
-3/* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster (pcl)) {@@ -1787,7 +1795,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }@@ -1808,7 +1816,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);@@ -1849,7 +1857,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Hi Yue,
Quoted 3 lines · Yue Hu
On Fri, 26 Jan 2024 13:36:16 +0800
Gao Xiang <[email protected]> wrote:
...
Quoted 4 lines
Quoted 4 lines
/*
fs/erofs/zdata.c +0
-0@@ -1276,7 +1280,11 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, .inplace_io = overlapped, .partial_decoding = pcl->partial,
Quoted 8 lines
fs/erofs/zdata.c static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, · line 1287
Quoted 6 lines
fs/erofs/zdata.c +4
-0.fillgaps = pcl->multibases, + .gfp = pcl->besteffort ? +GFP_KERNEL | __GFP_NOFAIL : +GFP_NOWAIT | __GFP_NORETRY }, be->pagepool); + pcl->besteffort = false;reposition it following
pcl->multibases = false?
Good idea! Let me update this.
Thanks,
Gao Xiang
PATCH v4 1/1 erofs: relaxed temporary buffers allocation on readahead
In reply to Yue HuFrom: Chunhai Guo <[email protected]>
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/[email protected]
---
change since v3:
- reposition pcl->besteffort = false; suggested by Yue;
fs/erofs/compress.h | 5 ++--- fs/erofs/decompressor.c | 5 +++-- fs/erofs/decompressor_deflate.c | 19 +++++++++++++------ fs/erofs/decompressor_lzma.c | 17 ++++++++++++----- fs/erofs/zdata.c | 16 ++++++++++++---- 5 files changed, 42 insertions(+), 20 deletions(-)
fs/erofs/compress.h +2 -3
@@ -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 {
fs/erofs/decompressor.c +3 -2
@@ -111,8 +111,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;
fs/erofs/decompressor_deflate.c +13 -6
@@ -95,7 +95,7 @@ int z_erofs_load_deflate_config(struct super_block *sb, }int z_erofs_deflate_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 ;
@@ -158,8 +158,12 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, strm->z.avail_out =min_t (u32, outsz,PAGE_SIZE - pofs); outsz -= strm->z.avail_out;if (!rq->out[no]) { - rq->out[no] =erofs_allocpage (pagepool, -GFP_KERNEL | __GFP_NOFAIL); + rq->out[no] =erofs_allocpage (pgpl, rq->gfp); +if (!rq->out[no]) { + kout =NULL ; + err = -ENOMEM ; +break ; + }set_page_private (rq->out[no],Z_EROFS_SHORTLIVED_PAGE ); }
@@ -211,8 +215,11 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,DBG_BUGON (erofs_page_is_managed (EROFS_SB (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;
@@ -230,7 +237,7 @@ int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,break ; } } - +failed:if (zlib_inflateEnd (&strm->z) !=Z_OK && !err) err = -EIO ;if (kout)
fs/erofs/decompressor_lzma.c +12 -5
@@ -148,7 +148,7 @@ int z_erofs_load_lzma_config(struct super_block *sb, }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 ;
@@ -215,8 +215,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, 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 ); }
@@ -258,8 +261,11 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,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;
@@ -277,6 +283,7 @@ int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,break ; } } +failed:if (no < nrpages_out && strm->buf.out)kunmap (rq->out[no]);if (ni < nrpages_in)
fs/erofs/zdata.c +12 -4
@@ -82,6 +82,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[]; };
@@ -960,7 +963,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;
@@ -1010,6 +1013,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, err =z_erofs_pcluster_begin (fe);if (err) goto out; + fe->pcl->besteffort |= !ra; }/*
@@ -1276,6 +1280,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);/* must handle all compressed pages before actual file pages */
@@ -1318,6 +1325,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be, pcl->length =0 ; pcl->partial = true; pcl->multibases = false; + pcl->besteffort = false; pcl->bvset.nextpage =NULL ; pcl->vcnt =0 ;
@@ -1787,7 +1795,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,if (PageUptodate (page))unlock_page (page);else - (void )z_erofs_do_read_page (f, page); + (void )z_erofs_do_read_page (f, page, !!rac);put_page (page); }
@@ -1808,7 +1816,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio) f.headoffset = (erofs_off_t )folio->index <<PAGE_SHIFT ;z_erofs_pcluster_readmore (&f,NULL , true); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, false);z_erofs_pcluster_readmore (&f,NULL , false);z_erofs_pcluster_end (&f);
@@ -1849,7 +1857,7 @@ static void z_erofs_readahead(struct readahead_control *rac) folio = head; head =folio_get_private (folio); - err =z_erofs_do_read_page (&f, &folio->page); + err =z_erofs_do_read_page (&f, &folio->page, true);if (err && err != -EINTR )erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , folio->index,EROFS_I (inode)->nid);
Signature · 1 line
2.39.3
Quoted 30 lines · On Fri, 26 Jan 2024 22:01:42 +0800 Gao Xiang <[email protected]>…
From: Chunhai Guo <[email protected]>
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_NOWAITon 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 KBTherefore, 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.
Quoted 5 lines
[1] https://lore.kernel.org/r/[email protected]
Suggested-by Gao Xiang <[email protected]>Signed-off-by Chunhai Guo <[email protected]>Signed-off-by Gao Xiang <[email protected]>