Skip to content

Commit 6dac332

Browse files
chaseyugregkh
authored andcommitted
f2fs: allocate proper size memory for zstd decompress
[ Upstream commit 0e2b738 ] As 5kft <5kft@5kft.org> reported: kworker/u9:3: page allocation failure: order:9, mode:0x40c40(GFP_NOFS|__GFP_COMP), nodemask=(null),cpuset=/,mems_allowed=0 CPU: 3 PID: 8168 Comm: kworker/u9:3 Tainted: G C 5.8.3-sunxi #trunk Hardware name: Allwinner sun8i Family Workqueue: f2fs_post_read_wq f2fs_post_read_work [<c010d6d5>] (unwind_backtrace) from [<c0109a55>] (show_stack+0x11/0x14) [<c0109a55>] (show_stack) from [<c056d489>] (dump_stack+0x75/0x84) [<c056d489>] (dump_stack) from [<c0243b53>] (warn_alloc+0xa3/0x104) [<c0243b53>] (warn_alloc) from [<c024473b>] (__alloc_pages_nodemask+0xb87/0xc40) [<c024473b>] (__alloc_pages_nodemask) from [<c02267c5>] (kmalloc_order+0x19/0x38) [<c02267c5>] (kmalloc_order) from [<c02267fd>] (kmalloc_order_trace+0x19/0x90) [<c02267fd>] (kmalloc_order_trace) from [<c047c665>] (zstd_init_decompress_ctx+0x21/0x88) [<c047c665>] (zstd_init_decompress_ctx) from [<c047e9cf>] (f2fs_decompress_pages+0x97/0x228) [<c047e9cf>] (f2fs_decompress_pages) from [<c045d0ab>] (__read_end_io+0xfb/0x130) [<c045d0ab>] (__read_end_io) from [<c045d141>] (f2fs_post_read_work+0x61/0x84) [<c045d141>] (f2fs_post_read_work) from [<c0130b2f>] (process_one_work+0x15f/0x3b0) [<c0130b2f>] (process_one_work) from [<c0130e7b>] (worker_thread+0xfb/0x3e0) [<c0130e7b>] (worker_thread) from [<c0135c3b>] (kthread+0xeb/0x10c) [<c0135c3b>] (kthread) from [<c0100159>] zstd may allocate large size memory for {,de}compression, it may cause file copy failure on low-end device which has very few memory. For decompression, let's just allocate proper size memory based on current file's cluster size instead of max cluster size. Reported-by: 5kft <5kft@5kft.org> Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 44c1c8c commit 6dac332

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

fs/f2fs/compress.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,17 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic)
382382
ZSTD_DStream *stream;
383383
void *workspace;
384384
unsigned int workspace_size;
385+
unsigned int max_window_size =
386+
MAX_COMPRESS_WINDOW_SIZE(dic->log_cluster_size);
385387

386-
workspace_size = ZSTD_DStreamWorkspaceBound(MAX_COMPRESS_WINDOW_SIZE);
388+
workspace_size = ZSTD_DStreamWorkspaceBound(max_window_size);
387389

388390
workspace = f2fs_kvmalloc(F2FS_I_SB(dic->inode),
389391
workspace_size, GFP_NOFS);
390392
if (!workspace)
391393
return -ENOMEM;
392394

393-
stream = ZSTD_initDStream(MAX_COMPRESS_WINDOW_SIZE,
394-
workspace, workspace_size);
395+
stream = ZSTD_initDStream(max_window_size, workspace, workspace_size);
395396
if (!stream) {
396397
printk_ratelimited("%sF2FS-fs (%s): %s ZSTD_initDStream failed\n",
397398
KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id,

fs/f2fs/f2fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ struct decompress_io_ctx {
13941394
#define NULL_CLUSTER ((unsigned int)(~0))
13951395
#define MIN_COMPRESS_LOG_SIZE 2
13961396
#define MAX_COMPRESS_LOG_SIZE 8
1397-
#define MAX_COMPRESS_WINDOW_SIZE ((PAGE_SIZE) << MAX_COMPRESS_LOG_SIZE)
1397+
#define MAX_COMPRESS_WINDOW_SIZE(log_size) ((PAGE_SIZE) << (log_size))
13981398

13991399
struct f2fs_sb_info {
14001400
struct super_block *sb; /* pointer to VFS super block */

0 commit comments

Comments
 (0)