Skip to content

Commit 70dd07c

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: use vmalloc instead of kvmalloc in .init_{,de}compress_ctx
.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>
1 parent 5827e3c commit 70dd07c

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

fs/f2fs/compress.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct folio *folio)
180180
#ifdef CONFIG_F2FS_FS_LZO
181181
static int lzo_init_compress_ctx(struct compress_ctx *cc)
182182
{
183-
cc->private = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
184-
LZO1X_MEM_COMPRESS, GFP_NOFS);
183+
cc->private = f2fs_vmalloc(LZO1X_MEM_COMPRESS);
185184
if (!cc->private)
186185
return -ENOMEM;
187186

@@ -191,7 +190,7 @@ static int lzo_init_compress_ctx(struct compress_ctx *cc)
191190

192191
static void lzo_destroy_compress_ctx(struct compress_ctx *cc)
193192
{
194-
kvfree(cc->private);
193+
vfree(cc->private);
195194
cc->private = NULL;
196195
}
197196

@@ -248,7 +247,7 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
248247
size = LZ4HC_MEM_COMPRESS;
249248
#endif
250249

251-
cc->private = f2fs_kvmalloc(F2FS_I_SB(cc->inode), size, GFP_NOFS);
250+
cc->private = f2fs_vmalloc(size);
252251
if (!cc->private)
253252
return -ENOMEM;
254253

@@ -263,7 +262,7 @@ static int lz4_init_compress_ctx(struct compress_ctx *cc)
263262

264263
static void lz4_destroy_compress_ctx(struct compress_ctx *cc)
265264
{
266-
kvfree(cc->private);
265+
vfree(cc->private);
267266
cc->private = NULL;
268267
}
269268

@@ -344,16 +343,15 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
344343
params = zstd_get_params(level, cc->rlen);
345344
workspace_size = zstd_cstream_workspace_bound(&params.cParams);
346345

347-
workspace = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
348-
workspace_size, GFP_NOFS);
346+
workspace = f2fs_vmalloc(workspace_size);
349347
if (!workspace)
350348
return -ENOMEM;
351349

352350
stream = zstd_init_cstream(&params, 0, workspace, workspace_size);
353351
if (!stream) {
354352
f2fs_err_ratelimited(F2FS_I_SB(cc->inode),
355353
"%s zstd_init_cstream failed", __func__);
356-
kvfree(workspace);
354+
vfree(workspace);
357355
return -EIO;
358356
}
359357

@@ -366,7 +364,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
366364

367365
static void zstd_destroy_compress_ctx(struct compress_ctx *cc)
368366
{
369-
kvfree(cc->private);
367+
vfree(cc->private);
370368
cc->private = NULL;
371369
cc->private2 = NULL;
372370
}
@@ -425,16 +423,15 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
425423

426424
workspace_size = zstd_dstream_workspace_bound(max_window_size);
427425

428-
workspace = f2fs_kvmalloc(F2FS_I_SB(dic->inode),
429-
workspace_size, GFP_NOFS);
426+
workspace = f2fs_vmalloc(workspace_size);
430427
if (!workspace)
431428
return -ENOMEM;
432429

433430
stream = zstd_init_dstream(max_window_size, workspace, workspace_size);
434431
if (!stream) {
435432
f2fs_err_ratelimited(F2FS_I_SB(dic->inode),
436433
"%s zstd_init_dstream failed", __func__);
437-
kvfree(workspace);
434+
vfree(workspace);
438435
return -EIO;
439436
}
440437

@@ -446,7 +443,7 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
446443

447444
static void zstd_destroy_decompress_ctx(struct decompress_io_ctx *dic)
448445
{
449-
kvfree(dic->private);
446+
vfree(dic->private);
450447
dic->private = NULL;
451448
dic->private2 = NULL;
452449
}

fs/f2fs/f2fs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,11 @@ static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
35323532
return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
35333533
}
35343534

3535+
static inline void *f2fs_vmalloc(size_t size)
3536+
{
3537+
return vmalloc(size);
3538+
}
3539+
35353540
static inline int get_extra_isize(struct inode *inode)
35363541
{
35373542
return F2FS_I(inode)->i_extra_isize / sizeof(__le32);

0 commit comments

Comments
 (0)