f2fs: use vmalloc instead of kvmalloc in .init_{,de}compress_ctx
[ Upstream commit 70dd07c888451503c3e93b6821e10d1ea1ec9930 ] .init_{,de}compress_ctx uses kvmalloc() to alloc memory, it will try to allocate physically continuous page first, it may cause more memory allocation pressure, let's use vmalloc instead to mitigate it. [Test] cd /data/local/tmp touch file f2fs_io setflags compression file f2fs_io getflags file for i in $(seq 1 10); do sync; echo 3 > /proc/sys/vm/drop_caches;\ time f2fs_io write 512 0 4096 zero osync file; truncate -s 0 file;\ done [Result] Before After Delta 21.243 21.694 -2.12% For compression, we recommend to use ioctl to compress file data in background for workaround. For decompression, only zstd will be affected. Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
92dbc2a2e2
commit
61fc32485d
@@ -176,8 +176,7 @@ void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page)
|
|||||||
#ifdef CONFIG_F2FS_FS_LZO
|
#ifdef CONFIG_F2FS_FS_LZO
|
||||||
static int lzo_init_compress_ctx(struct compress_ctx *cc)
|
static int lzo_init_compress_ctx(struct compress_ctx *cc)
|
||||||
{
|
{
|
||||||
cc->private = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
|
cc->private = f2fs_vmalloc(LZO1X_MEM_COMPRESS);
|
||||||
LZO1X_MEM_COMPRESS, GFP_NOFS);
|
|
||||||
if (!cc->private)
|
if (!cc->private)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -187,7 +186,7 @@ static int lzo_init_compress_ctx(struct compress_ctx *cc)
|
|||||||
|
|
||||||
static void lzo_destroy_compress_ctx(struct compress_ctx *cc)
|
static void lzo_destroy_compress_ctx(struct compress_ctx *cc)
|
||||||
{
|
{
|
||||||
kvfree(cc->private);
|
vfree(cc->private);
|
||||||
cc->private = NULL;
|
cc->private = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +243,7 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
|
|||||||
size = LZ4HC_MEM_COMPRESS;
|
size = LZ4HC_MEM_COMPRESS;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cc->private = f2fs_kvmalloc(F2FS_I_SB(cc->inode), size, GFP_NOFS);
|
cc->private = f2fs_vmalloc(size);
|
||||||
if (!cc->private)
|
if (!cc->private)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -259,7 +258,7 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
|
|||||||
|
|
||||||
static void lz4_destroy_compress_ctx(struct compress_ctx *cc)
|
static void lz4_destroy_compress_ctx(struct compress_ctx *cc)
|
||||||
{
|
{
|
||||||
kvfree(cc->private);
|
vfree(cc->private);
|
||||||
cc->private = NULL;
|
cc->private = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,8 +339,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
|
|||||||
params = zstd_get_params(level, cc->rlen);
|
params = zstd_get_params(level, cc->rlen);
|
||||||
workspace_size = zstd_cstream_workspace_bound(¶ms.cParams);
|
workspace_size = zstd_cstream_workspace_bound(¶ms.cParams);
|
||||||
|
|
||||||
workspace = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
|
workspace = f2fs_vmalloc(workspace_size);
|
||||||
workspace_size, GFP_NOFS);
|
|
||||||
if (!workspace)
|
if (!workspace)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -349,7 +347,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
|
|||||||
if (!stream) {
|
if (!stream) {
|
||||||
f2fs_err_ratelimited(F2FS_I_SB(cc->inode),
|
f2fs_err_ratelimited(F2FS_I_SB(cc->inode),
|
||||||
"%s zstd_init_cstream failed", __func__);
|
"%s zstd_init_cstream failed", __func__);
|
||||||
kvfree(workspace);
|
vfree(workspace);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +360,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
|
|||||||
|
|
||||||
static void zstd_destroy_compress_ctx(struct compress_ctx *cc)
|
static void zstd_destroy_compress_ctx(struct compress_ctx *cc)
|
||||||
{
|
{
|
||||||
kvfree(cc->private);
|
vfree(cc->private);
|
||||||
cc->private = NULL;
|
cc->private = NULL;
|
||||||
cc->private2 = NULL;
|
cc->private2 = NULL;
|
||||||
}
|
}
|
||||||
@@ -421,8 +419,7 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
|
|||||||
|
|
||||||
workspace_size = zstd_dstream_workspace_bound(max_window_size);
|
workspace_size = zstd_dstream_workspace_bound(max_window_size);
|
||||||
|
|
||||||
workspace = f2fs_kvmalloc(F2FS_I_SB(dic->inode),
|
workspace = f2fs_vmalloc(workspace_size);
|
||||||
workspace_size, GFP_NOFS);
|
|
||||||
if (!workspace)
|
if (!workspace)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@@ -430,7 +427,7 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
|
|||||||
if (!stream) {
|
if (!stream) {
|
||||||
f2fs_err_ratelimited(F2FS_I_SB(dic->inode),
|
f2fs_err_ratelimited(F2FS_I_SB(dic->inode),
|
||||||
"%s zstd_init_dstream failed", __func__);
|
"%s zstd_init_dstream failed", __func__);
|
||||||
kvfree(workspace);
|
vfree(workspace);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,7 +439,7 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
|
|||||||
|
|
||||||
static void zstd_destroy_decompress_ctx(struct decompress_io_ctx *dic)
|
static void zstd_destroy_decompress_ctx(struct decompress_io_ctx *dic)
|
||||||
{
|
{
|
||||||
kvfree(dic->private);
|
vfree(dic->private);
|
||||||
dic->private = NULL;
|
dic->private = NULL;
|
||||||
dic->private2 = NULL;
|
dic->private2 = NULL;
|
||||||
}
|
}
|
||||||
|
@@ -3449,6 +3449,11 @@ static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
|
|||||||
return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
|
return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void *f2fs_vmalloc(size_t size)
|
||||||
|
{
|
||||||
|
return vmalloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int get_extra_isize(struct inode *inode)
|
static inline int get_extra_isize(struct inode *inode)
|
||||||
{
|
{
|
||||||
return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
|
return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
|
||||||
|
Reference in New Issue
Block a user