Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1171426lqb; Thu, 30 May 2024 02:23:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVn9Sl6ZqllHfMCkYOTdFHEO+lBaUk96w2+gRfy/UsbmZ8rsXYzk0Dkqfxc49KY26nJGdLI1WR559yPqwOmc0yGsX/mTLjGYPubfsFQaQ== X-Google-Smtp-Source: AGHT+IGDI9g1AxFHQXdWUTUTwW9IWMLEwmhNfAIYayn7ob51nMMEtPT4itQcypxb4KlOd6kVch/2 X-Received: by 2002:a05:6214:3991:b0:6ae:1051:40d8 with SMTP id 6a1803df08f44-6ae10514116mr16778626d6.6.1717061018356; Thu, 30 May 2024 02:23:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717061018; cv=pass; d=google.com; s=arc-20160816; b=tg8wy5LkTRYmnx1COlvVX64TDINTxK5OWwyK/ToA37WZUOxeDdWkkackzZnGI3gYCr kNfh4uxAXf0QcwXZKNZ0aOrtODwIVURofY3w/pohrS06S4lNPS8wlR8iinDKJTCxEELL m0WjmMoYNV9/RDl91X5h0oTRXER5wXQPq6Rai4dbJRYcz86jEyVnHLNQO0X5AoZgrvsa wZFKimFdmiv9W2ks9dSrlIOp7fAOluqVpsc9IxIbdShsQ+m8b6eMd+9VglU5krBv+0Yr 4jPTneKYouXcjqH+/O4GWKeuvWnXtt6ZeeuTfMzcKSyK946vaq4+FyqpeMgRivC025Oz kytA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=HC3QeNIhf5e5Wu+RbydEahoJp6GbOb1Ol6v/8D88RQI=; fh=d5RNBTGH+8NLy8IkaJakkFJ05GBmRAoAt0jVG0pBMUA=; b=WvsSXyp3/tRh/0WWqQghqfyggSA/7XOAXgFW9/8zo+TbQauCaU50zSJqrhl0/ulJyx cRBtE8P+VxLskGytD4jq75teefqzF60embQysYbpJrBQS8WVaXNT6hGPaJb2k5SCKODs V0T08kMm8LRlH0UHfcoI0N12iy2MsGxnmDXtBFMfWnIPDkAam/Dufrl+PXJaHjMyFWyS qB5JhJ6bLZFwHqTI+5gKbOqpMUeIX06VkFKHHzGMCYzDehg8um/Txjo6qtj8OplPE9wU S9Yz6n4SfLaMpRbOAHyY8PZH+KKu7mM7kme073iQPu1fD9IsoQIKhDxK4YRAjYV1Zc++ AvNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=q3eJfNJ4; 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-195161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195161-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 ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ad79d142bcsi1713756d6.306.2024.05.30.02.23.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 02:23:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=q3eJfNJ4; 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-195161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195161-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 08E9A1C21A2E for ; Thu, 30 May 2024 09:23:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61BA217C7B6; Thu, 30 May 2024 09:22:19 +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="q3eJfNJ4" 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 25A0F15251B; Thu, 30 May 2024 09:22:14 +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=1717060938; cv=none; b=jcFs0UX0Pq7BUqWvG5CGnurKqD1IVBVohEJTVAhCq5biuCfD1y2oZAV6CqqLP6JHZN0cklFsQ2fBHnrGT/9RG+fmLUIuH4+l6YL6AySM3cBka9fWR2aZWpqARK9liKNvK1a4BP/7U0NFYGQMPPMjYwci7MFGl4Z1t+0YRk+ru+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717060938; c=relaxed/simple; bh=MlA3azACbrwom+C84GC0LOLxTP/lEriaHVGtrpci8Ig=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=p6qdlkOIhs8tc5Jauh0/r8xXrEGHDfQ77YvyRxvapJIcMv2SeJYg0s4X7byOEAi2ndTmuAOKXTlhtUb173ebRqxTaOvsMcQlTN/HfCOJIOeWXFEE5IiKNfF1Yft6YjT0YIzFkKPI66w9Sem+Ww/+E4jfL86xf3Ii6QaAanzD3Ks= 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=q3eJfNJ4; 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=1717060927; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=HC3QeNIhf5e5Wu+RbydEahoJp6GbOb1Ol6v/8D88RQI=; b=q3eJfNJ4QPFmKhQfQNhmpLQC/kHyzN5fJzBnaMFRqbcLFemGrpytXWenGTXowFOhwLPCB5QGVWviFXFj7Bfgpny6VLgA0nGaV+LKKfRt8GROnP1LVIuNe+0bW/liJ3KeRRyDcly1bMADgtU84F7DINT9FOZFn5gqKcG1pBA9y/k= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R881e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067112;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0W7WbjK6_1717060922; Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0W7WbjK6_1717060922) by smtp.aliyun-inc.com; Thu, 30 May 2024 17:22:06 +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.9.y] erofs: avoid allocating DEFLATE streams before mounting Date: Thu, 30 May 2024 17:21:59 +0800 Message-Id: <20240530092201.16873-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 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 81e65c453ef0..3a3461561a3c 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