Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1171636lqb; Thu, 30 May 2024 02:24:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRAprEJsXr81S9Q05hL9Ic2l/ErMXJYokD8ucLQjTBDU+rZPzqq4uAogbZ/2g4fpzHYYR6CgC9xCBDzKnad5z0owbkuoM2giBi95Ilgg== X-Google-Smtp-Source: AGHT+IGGwkV46ECfUwAP2PsvY/+BDEdFdgLwrJLrwL/SE9rBXuIMQswp08LiuvVE2fXFFU+uIOlc X-Received: by 2002:a17:907:780a:b0:a62:1503:d0ac with SMTP id a640c23a62f3a-a65e8e720a3mr98798766b.41.1717061056841; Thu, 30 May 2024 02:24:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717061056; cv=pass; d=google.com; s=arc-20160816; b=M/W0I3m0u4jqJ8IKsSw0PI1M0htZxPDAgAJQJvGcMkm1EvLJdEA/GdTz3GtLYmVLSb GRx+Ikfc3ggmOTpye/2onx73lb7/O8yYfiFPXRxRSE3xp0OwY7fRTCxG/E+dmbBQPLZI zMVIQT+BlSmUdNck29CpOTv38owBc5/wQ9+D0swpWcJAiHoMVWIIbaazhE3jf7Z4ZLR6 KHKcTb30Z+RifhUQzY/X9+oRveI2oBIrb3r6IKbtxMqCQJhtSvnMSulXRKO+/YVxl79V Cw/cKCIpj7+xbpsfBTJ4P1yKzreNApHDQGkAm+FRD2KPtjT19F1sJRgXgL0Zy+pr0twJ 96Rw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LAV4iRoaUKQi+wmPNV5IZ7VOkrMEu/ZXWD6411daKG0=; fh=d5RNBTGH+8NLy8IkaJakkFJ05GBmRAoAt0jVG0pBMUA=; b=V59ShrEkBVA+7N8zRNl3EkloaL4sDJFp94jwzhRgT3hHvkGbQU0O8/1tW8Ru/Z59OB p8P6pIfKox3Hf693x8r5WyA36Bfl2Tk4Vp8ew3/w8KIF7JFmNX5CjWbCD54zYLKHqRFG zh2kg2EwcN3OiHnlNV9nJnU8ScVqYifIOydOXfAYITa1O0fuu2lDr4uKS2M4UmkPX8SE aVGgH7c5hkyE0k54iSAWDhXw7nomOEoZqxlaeRnM6EXGZTHcPjmDocxiH3Le6SDgbIib LIqPRfFIwcOjQTfFmDu6UDBRj7ETTJrBPEm+hrm+bkE3NJGyWtAPvSlECNTjR8DrHiGk 7RFA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=T4QUN0Kd; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-195162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195162-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c7ff1dasi733180566b.112.2024.05.30.02.24.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 02:24:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=T4QUN0Kd; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-195162-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195162-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 74E971F240B1 for ; Thu, 30 May 2024 09:24:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A2E1617D35F; Thu, 30 May 2024 09:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="T4QUN0Kd" Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66187153569; Thu, 30 May 2024 09:22:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717060940; cv=none; b=YAAf9+iCZIdsA1Pn2wcwUy9DN/WXDryNjFzTWRXFSCgtU6z0RRlD7Ao88svcM3kgXhGfj2t2B0lpNacV1zjdfC9/Wac1530seTgvdzD8vOsuOcwYLBGsSXaZNExZwsYwgJ3DKtgOVR9A5CAr+Wcl+Ox3qpVEUwhIaF5HSvy+QiY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717060940; c=relaxed/simple; bh=+zmJTiEoepzzsi7E0uJSLhN2mlDIWTQJnSX1CLeHCew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IVSrXSvfMvUfjknNC8tUurtnXu54Sztr6NEa4E8EChA9K67U99n5xbusl0XfB3w/KL4ftHxEE53J+m5cJacRZoB/ooyc/cq+XOS84zVLm1gvkTmGJ4VD9D6KLWpEDGoIvP7rhL6aiLGcpdSp6Fkq86g/cPpyB0xForVt7X1H4JI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=T4QUN0Kd; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717060930; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=LAV4iRoaUKQi+wmPNV5IZ7VOkrMEu/ZXWD6411daKG0=; b=T4QUN0Kd4pGWqUMnLyQ1uSaUUCBbFeJaBGCsmaaaXXjcQTKDZmD7l5g3BhzM0frlz52aqDzuL88G3kY5MOy9eqn9pV76Tn16LhOfLnVZ/DrchZOLjaRJXhJ7WfLdHas6ieTVp0XWIAZpfNembHQn9qe8d1S+szoI0wpqe+agtFc= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033068173054;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0W7WbjN._1717060927; Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0W7WbjN._1717060927) by smtp.aliyun-inc.com; Thu, 30 May 2024 17:22:09 +0800 From: Gao Xiang To: stable@vger.kernel.org, Greg Kroah-Hartman Cc: linux-erofs@lists.ozlabs.org, Baokun Li , LKML , Gao Xiang , Sandeep Dhavale Subject: [PATCH 6.8.y] erofs: avoid allocating DEFLATE streams before mounting Date: Thu, 30 May 2024 17:22:00 +0800 Message-Id: <20240530092201.16873-2-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240530092201.16873-1-hsiangkao@linux.alibaba.com> References: <20240530092201.16873-1-hsiangkao@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit commit 80eb4f62056d6ae709bdd0636ab96ce660f494b2 upstream. Currently, each DEFLATE stream takes one 32 KiB permanent internal window buffer even if there is no running instance which uses DEFLATE algorithm. It's unexpected and wasteful on embedded devices with limited resources and servers with hundreds of CPU cores if DEFLATE is enabled but unused. Fixes: ffa09b3bd024 ("erofs: DEFLATE compression support") Cc: # 6.6+ Reviewed-by: Sandeep Dhavale Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20240520090106.2898681-1-hsiangkao@linux.alibaba.com --- fs/erofs/decompressor_deflate.c | 55 +++++++++++++++++---------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/fs/erofs/decompressor_deflate.c b/fs/erofs/decompressor_deflate.c index b98872058abe..26350c5b040e 100644 --- a/fs/erofs/decompressor_deflate.c +++ b/fs/erofs/decompressor_deflate.c @@ -46,39 +46,15 @@ int __init z_erofs_deflate_init(void) /* by default, use # of possible CPUs instead */ if (!z_erofs_deflate_nstrms) z_erofs_deflate_nstrms = num_possible_cpus(); - - for (; z_erofs_deflate_avail_strms < z_erofs_deflate_nstrms; - ++z_erofs_deflate_avail_strms) { - struct z_erofs_deflate *strm; - - strm = kzalloc(sizeof(*strm), GFP_KERNEL); - if (!strm) - goto out_failed; - - /* XXX: in-kernel zlib cannot shrink windowbits currently */ - strm->z.workspace = vmalloc(zlib_inflate_workspacesize()); - if (!strm->z.workspace) { - kfree(strm); - goto out_failed; - } - - spin_lock(&z_erofs_deflate_lock); - strm->next = z_erofs_deflate_head; - z_erofs_deflate_head = strm; - spin_unlock(&z_erofs_deflate_lock); - } return 0; - -out_failed: - erofs_err(NULL, "failed to allocate zlib workspace"); - z_erofs_deflate_exit(); - return -ENOMEM; } int z_erofs_load_deflate_config(struct super_block *sb, struct erofs_super_block *dsb, void *data, int size) { struct z_erofs_deflate_cfgs *dfl = data; + static DEFINE_MUTEX(deflate_resize_mutex); + static bool inited; if (!dfl || size < sizeof(struct z_erofs_deflate_cfgs)) { erofs_err(sb, "invalid deflate cfgs, size=%u", size); @@ -89,9 +65,36 @@ int z_erofs_load_deflate_config(struct super_block *sb, erofs_err(sb, "unsupported windowbits %u", dfl->windowbits); return -EOPNOTSUPP; } + mutex_lock(&deflate_resize_mutex); + if (!inited) { + for (; z_erofs_deflate_avail_strms < z_erofs_deflate_nstrms; + ++z_erofs_deflate_avail_strms) { + struct z_erofs_deflate *strm; + + strm = kzalloc(sizeof(*strm), GFP_KERNEL); + if (!strm) + goto failed; + /* XXX: in-kernel zlib cannot customize windowbits */ + strm->z.workspace = vmalloc(zlib_inflate_workspacesize()); + if (!strm->z.workspace) { + kfree(strm); + goto failed; + } + spin_lock(&z_erofs_deflate_lock); + strm->next = z_erofs_deflate_head; + z_erofs_deflate_head = strm; + spin_unlock(&z_erofs_deflate_lock); + } + inited = true; + } + mutex_unlock(&deflate_resize_mutex); erofs_info(sb, "EXPERIMENTAL DEFLATE feature in use. Use at your own risk!"); return 0; +failed: + mutex_unlock(&deflate_resize_mutex); + z_erofs_deflate_exit(); + return -ENOMEM; } int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, -- 2.39.3