[RFC PATCH 1/2] erofs: support on-disk offset for shifted decompression
From: Yue Hu
Date: Mon Aug 22 2022 - 01:53:38 EST
From: Yue Hu <huyue2@xxxxxxxxxxx>
Currently, there is no start offset when writing uncompressed data to
disk blocks for compressed files. However, we are using in-place I/O
which will decrease the number of memory copies a lot if we write it
just from an offset of 'pageofs_out'. So, let's support it.
Signed-off-by: Yue Hu <huyue2@xxxxxxxxxxx>
---
fs/erofs/decompressor.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 2d55569f96ac..dc02d95b52d7 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -326,6 +326,7 @@ static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
PAGE_SIZE - rq->pageofs_out);
const unsigned int lefthalf = rq->outputsize - righthalf;
unsigned char *src, *dst;
+ unsigned int headofs_in;
if (nrpages_out > 2) {
DBG_BUGON(1);
@@ -337,21 +338,25 @@ static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
return 0;
}
+ /* set it to pageofs_out if fragments feature is used */
+ headofs_in = 0;
+
src = kmap_atomic(*rq->in) + rq->pageofs_in;
if (rq->out[0]) {
dst = kmap_atomic(rq->out[0]);
- memcpy(dst + rq->pageofs_out, src, righthalf);
+ memcpy(dst + rq->pageofs_out, src + headofs_in, righthalf);
kunmap_atomic(dst);
}
if (nrpages_out == 2) {
DBG_BUGON(!rq->out[1]);
- if (rq->out[1] == *rq->in) {
- memmove(src, src + righthalf, lefthalf);
- } else {
+ if (rq->out[1] != *rq->in) {
dst = kmap_atomic(rq->out[1]);
- memcpy(dst, src + righthalf, lefthalf);
+ memcpy(dst, src + (headofs_in ? 0 : righthalf),
+ lefthalf);
kunmap_atomic(dst);
+ } else if (!headofs_in) {
+ memmove(src, src + righthalf, lefthalf);
}
}
kunmap_atomic(src);
--
2.17.1