Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp264458pxk; Wed, 2 Sep 2020 00:04:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkrALBWWe55zfxGqjrdyE60+nJoInquq8/mp0ONcMZe0KWsaeuh4YuKH56a+XgFm/JmTbL X-Received: by 2002:aa7:c394:: with SMTP id k20mr4821684edq.279.1599030250329; Wed, 02 Sep 2020 00:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599030250; cv=none; d=google.com; s=arc-20160816; b=AUJomP2jLZ+p56SpweGPuYRK+H2zJDa43R1gY5zFMPYkbTRzRWDOZ0/UdJ2Kcaa0YP np4jQAb7B8YRcZZOR2h8KtSnhzccEhQ3bM6JBBY+eKK5UVmCZ8CJqohCIh0511iQ6QEs im0uIqjpIEc78KIY6dhCptG7gf0uW1m5/pD6y7d2ZUlce8hlaKMIZ8T0yV6n+lQgs6mj K7hElW2Y8jveZe6r5vPpv1HJkIausWK3/Njw3B3AvQ68RR3ny/roi/MSVQzPh7z65E0H LExWYefFjWlRjagMk55Dw7KS07pPNp6SW3VBHHm7CCerDCVcgvy6SmZicxwbghKyCv48 eziQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=ffse53ZhLuCFCPkTYEslm6bWikTpzGNyB5qfZ85VwSA=; b=nlz2k5xBD2msVYE7jeRhZ9wgnn4zY+FQUlUJ21oryl7cKR3meEteH8POb1CCRNL5WB dU4uqBscJRSs7dtlUc6NU2CjqSAhXidDjDujlerpMGVW6fjX2pgA2Q3KHrh1cf83PpoF dGA/7GafAI6aUeuxsepYVLev73G0RucRY75RMMuh0OpaRvTfZ4VDn2ihweshpLxofIMi ZtXMmvbgY5Nlkokp85aXEXKtohZ0Etn0xyPcwgidmn1R0P2c19d5IQXvrqO/Eq6tV7g/ ZuNGtTSYFA70i1sqWGpeoGYN3+9IqO54uKVog1h9Ghl/5m905Prt7QKd5IplH9gQVgXX TLDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n13si1955012edq.92.2020.09.02.00.03.46; Wed, 02 Sep 2020 00:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726493AbgIBHC3 (ORCPT + 99 others); Wed, 2 Sep 2020 03:02:29 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:42488 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726130AbgIBHCZ (ORCPT ); Wed, 2 Sep 2020 03:02:25 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 320F5AC2FA410F4E76A5; Wed, 2 Sep 2020 15:02:22 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Wed, 2 Sep 2020 15:02:12 +0800 From: Chao Yu To: CC: , , , Chao Yu , 5kft <5kft@5kft.org> Subject: [PATCH] f2fs: allocate proper size memory for zstd decompress Date: Wed, 2 Sep 2020 15:01:52 +0800 Message-ID: <20200902070152.67032-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x75/0x84) [] (dump_stack) from [] (warn_alloc+0xa3/0x104) [] (warn_alloc) from [] (__alloc_pages_nodemask+0xb87/0xc40) [] (__alloc_pages_nodemask) from [] (kmalloc_order+0x19/0x38) [] (kmalloc_order) from [] (kmalloc_order_trace+0x19/0x90) [] (kmalloc_order_trace) from [] (zstd_init_decompress_ctx+0x21/0x88) [] (zstd_init_decompress_ctx) from [] (f2fs_decompress_pages+0x97/0x228) [] (f2fs_decompress_pages) from [] (__read_end_io+0xfb/0x130) [] (__read_end_io) from [] (f2fs_post_read_work+0x61/0x84) [] (f2fs_post_read_work) from [] (process_one_work+0x15f/0x3b0) [] (process_one_work) from [] (worker_thread+0xfb/0x3e0) [] (worker_thread) from [] (kthread+0xeb/0x10c) [] (kthread) from [] 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 --- fs/f2fs/compress.c | 7 ++++--- fs/f2fs/f2fs.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index df097c4a71e1..357303d8514b 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -382,16 +382,17 @@ static int zstd_init_decompress_ctx(struct decompress_io_ctx *dic) ZSTD_DStream *stream; void *workspace; unsigned int workspace_size; + unsigned int max_window_size = + MAX_COMPRESS_WINDOW_SIZE(dic->log_cluster_size); - workspace_size = ZSTD_DStreamWorkspaceBound(MAX_COMPRESS_WINDOW_SIZE); + workspace_size = ZSTD_DStreamWorkspaceBound(max_window_size); workspace = f2fs_kvmalloc(F2FS_I_SB(dic->inode), workspace_size, GFP_NOFS); if (!workspace) return -ENOMEM; - stream = ZSTD_initDStream(MAX_COMPRESS_WINDOW_SIZE, - workspace, workspace_size); + stream = ZSTD_initDStream(max_window_size, workspace, workspace_size); if (!stream) { printk_ratelimited("%sF2FS-fs (%s): %s ZSTD_initDStream failed\n", KERN_ERR, F2FS_I_SB(dic->inode)->sb->s_id, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 21f86001bb3a..d210809292f9 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1419,7 +1419,7 @@ struct decompress_io_ctx { #define NULL_CLUSTER ((unsigned int)(~0)) #define MIN_COMPRESS_LOG_SIZE 2 #define MAX_COMPRESS_LOG_SIZE 8 -#define MAX_COMPRESS_WINDOW_SIZE ((PAGE_SIZE) << MAX_COMPRESS_LOG_SIZE) +#define MAX_COMPRESS_WINDOW_SIZE(log_size) ((PAGE_SIZE) << (log_size)) struct f2fs_sb_info { struct super_block *sb; /* pointer to VFS super block */ -- 2.26.2