• Chao Yu's avatar
    f2fs: allocate proper size memory for zstd decompress · 0e2b7385
    Chao Yu authored
    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: default avatar5kft <5kft@5kft.org>
    Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    0e2b7385
compress.c 34.6 KB