f2fs: compress: let lz4 compressor handle output buffer budget properly

Commonly, in order to handle lz4 worst compress case, caller should
allocate buffer with size of LZ4_compressBound(inputsize) for target
compressed data storing, however in this case, if caller didn't
allocate enough space, lz4 compressor still can handle output buffer
budget properly, and end up compressing when left space in output
buffer is not enough.

So we don't have to allocate buffer with size for worst case, then
we can avoid 2 * 4KB size intermediate buffer allocation when
log_cluster_size is 2, and avoid unnecessary compressing work of
compressor if we can not save at least 4KB space.

Suggested-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chao Yu 2020-05-09 15:01:04 +08:00 committed by Jaegeuk Kim
parent 1f5f11a3c4
commit f6644143c6
1 changed files with 9 additions and 6 deletions

View File

@ -227,7 +227,12 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
if (!cc->private) if (!cc->private)
return -ENOMEM; return -ENOMEM;
cc->clen = LZ4_compressBound(PAGE_SIZE << cc->log_cluster_size); /*
* we do not change cc->clen to LZ4_compressBound(inputsize) to
* adapt worst compress case, because lz4 compressor can handle
* output budget properly.
*/
cc->clen = cc->rlen - PAGE_SIZE - COMPRESS_HEADER_SIZE;
return 0; return 0;
} }
@ -243,11 +248,9 @@ static int lz4_compress_pages(struct compress_ctx *cc)
len = LZ4_compress_default(cc->rbuf, cc->cbuf->cdata, cc->rlen, len = LZ4_compress_default(cc->rbuf, cc->cbuf->cdata, cc->rlen,
cc->clen, cc->private); cc->clen, cc->private);
if (!len) { if (!len)
printk_ratelimited("%sF2FS-fs (%s): lz4 compress failed\n", return -EAGAIN;
KERN_ERR, F2FS_I_SB(cc->inode)->sb->s_id);
return -EIO;
}
cc->clen = len; cc->clen = len;
return 0; return 0;
} }