From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D991B246BCD for ; Tue, 28 Jul 2026 02:18:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785205124; cv=none; b=lvrREf92Qe0BLJoWU4EpLDKl0m5aOA5pdU54jhEnSkR1YcjWrIVR5daxvmjHJqoAOibDu7csoC8delCL/NOqOxvazCQ+69aEPqfv8/ryX48SFfQtJXcjPwrLmxWAg2Rv/fxem17ANXLAeapc2bybQQ4RvVJeFiCcYrUaZUT2gwE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785205124; c=relaxed/simple; bh=Ky4pN3RNHN2vEh16ag9GFgLuTUpLnufJ25jI5XCotKc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=J5Bjtq7YjUysw6m/hmLv9Dg+4wIhF+f9kbbSi0VeVzRGuYGA0QqmGVj7a6agi0Jw5j7Pgu/B4aegC8dYZ6BxwwEdmIcUxIKl/wjfmdhJBfh1EruIh0eg4NFeIPCNMQe+P4kQsei8fRhHB0g7lp7wmUVVinqWMRHviXKPRjnl570= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZbXXr7GH; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZbXXr7GH" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-9305a2121a1so283587485a.2 for ; Mon, 27 Jul 2026 19:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785205122; x=1785809922; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=ZVyf1iyJaAiVVkRPJ40VHPyg9CuIf4ZNPax+DqMD7t8=; b=ZbXXr7GH0JEOLmOY0GMvI4t/J1GZfaXUyfTgaIFvSYHPJyUuqe74pDTCnfsl/a2Llc isZHO6VGF/sDRWD8VPv3MuSDPIFDAJ8JZzKAFa7BcL0vWKLhiPfw5JG2y5/yZxv5o2Nz 4zWHY7Yj0pQLUD82DP5rY0zbcz2Kvy/zN5sGi2BX7nXy5TH+/jbeqR0c2y25EV2gcKSp u9AjBE+NjzvmdtXqbCbOPaxA4yjwB2fb8hrTo3UBkZAlmuDwWuFnBMHDnwzshDw/U4Q2 q++QcyCJFhmWl/MomzJD2WM7Ni323d6UwGCMLtJB+884SBx9WXjX7OyEo6CsIPGCxd8e nMbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785205122; x=1785809922; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ZVyf1iyJaAiVVkRPJ40VHPyg9CuIf4ZNPax+DqMD7t8=; b=ZW6d4v9JHkgeLDrTxTwE6gcQRn9UJ7NAVGYmEeXLU68xYmDzObKuZj1J5N3fllsTQo sng/KcvmXf2bnbUai3F0oNWoFDdywVWagHbEUJIbkcOxEbJq9PxgQERBAI7mhMvxBM/w LPV0GXPnflVuhGxzOX2+NTEYEmaEPldJflLFI0LNG1231FCo/wAIHJqmfYTfFfrd7eSM 7iPiEydcZBUrHwiDnb1+JdMA8U6v8e7JDmvti/JjJLKLYVp40G7Sil4XlfaWxnFybdZB cdh09+DVkPKqn5DuCCvS8SC98ASzJX+A+WDZfqwcUrrmQg8EChBfnFGuAcRYvzPgiVGt DH+Q== X-Forwarded-Encrypted: i=1; AHgh+Ro5MhRG/cg1Pvl/16vlikD18kuWLF9jqyRAuL3QiVD2n0kC6bUI7KbMLoqa+r7fC3MxRU+48SivWju+TP8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxvs/auwtqHrxA6aWq8NGNrY1auafiBz5XeJrL0P2pFsDZ5lmrm ZF6PyBbYBDIE47IzdmJqsdat7zI7A6UTp5P2ZQb2Y6sY+URAoQEHmXl1 X-Gm-Gg: AR+sD11bnb2Yn74CuBrK9pO4bAg8DgSZaIgs2V1TnZ3ZRQW0M7GgMRy17mdbcR4YvKF 0vGo9slvjVPu3jp1ubkiejzW/F7dED+raLjqkVsgnkTTS7gWS78R1DT4CapPaCzUed6fd6Pr+u6 O3dxoDt+8NFhomAWF7jtYjtwlUo5tgn39fYkP5Hf4TMN8XJnyVjyiglrODY2whr9XiyImcK2+t1 IfyJVkmxtbeQtReo2aLtH3awDTPqH+aL1Zw2zl0eI8QtPXOESiuKOPlUcXNiJaMEo6Mh23qHE0s BOxExDQtB5oReBLJVVPLJyr4GiyB2t33MstlsirnhMEUBFhXCiJDaO7U0kBzCsPush/n9VEJRIk lfE4tq5rhE7+ljLaTeFDwCABtAwr9Mz9KR2QPt5RN4qNSLzd9cJruq7GyKulSFg5Yjr6sWuWxAZ UX1XedoAtrnwxXSYaHNw== X-Received: by 2002:a05:620a:458a:b0:930:f129:1a45 with SMTP id af79cd13be357-93302658626mr42048185a.30.1785205121627; Mon, 27 Jul 2026 19:18:41 -0700 (PDT) Received: from osman.mioffice.cn ([43.224.245.178]) by smtp.gmail.com with ESMTPSA id af79cd13be357-932de655676sm758546685a.37.2026.07.27.19.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 19:18:40 -0700 (PDT) From: Zhan Xusheng To: Gao Xiang , Chao Yu Cc: Yue Hu , Jeffle Xu , Sandeep Dhavale , Hongbo Li , Chunhai Guo , Nick Terrell , David Sterba , linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Zhan Xusheng Subject: [PATCH] erofs: cap Zstandard stream pool size Date: Tue, 28 Jul 2026 10:18:31 +0800 Message-ID: <20260728021831.1532541-1-zhanxusheng1024@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zhan Xusheng fs/erofs/decompressor_zstd.c sizes the module-global Zstandard stream pool from num_possible_cpus() when the zstd_streams module parameter is unset, and z_erofs_load_zstd_config() then preallocates one workspace per stream, grown to the largest dictionary of any mounted image (up to Z_EROFS_ZSTD_MAX_DICT_SIZE, i.e. Z_EROFS_PCLUSTER_MAX_SIZE). On high-CPU systems this can pin a large amount of vmalloc-backed decoder state until the erofs module is unloaded, mirroring the LZMA case fixed in commit c9b47e6b2311 ("erofs: cap LZMA stream pool size"). Bound the default stream count by a new CONFIG_EROFS_FS_ZIP_ZSTD_DEFAULT_MAX_STREAMS option, default 16, while preserving the per-image workspace sizing. An explicit zstd_streams module parameter is still honoured as-is. Fixes: 7c35de4df105 ("erofs: Zstandard compression support") Signed-off-by: Zhan Xusheng --- fs/erofs/Kconfig | 14 ++++++++++++++ fs/erofs/decompressor_zstd.c | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/erofs/Kconfig b/fs/erofs/Kconfig index 8ca1767dafb6..a27114d3c82f 100644 --- a/fs/erofs/Kconfig +++ b/fs/erofs/Kconfig @@ -167,6 +167,20 @@ config EROFS_FS_ZIP_ZSTD If unsure, say N. +config EROFS_FS_ZIP_ZSTD_DEFAULT_MAX_STREAMS + int "EROFS Zstandard default maximum decompression streams" + depends on EROFS_FS_ZIP_ZSTD + range 1 NR_CPUS + default 16 + help + By default EROFS allocates one Zstandard decompression stream per + CPU. Each stream preallocates a workspace sized for the largest + dictionary of any mounted image (up to 1 MiB), so on systems with + many CPUs this can reserve a lot of memory. This caps the default; + the zstd_streams module parameter still overrides it. + + If unsure, keep the default of 16. + config EROFS_FS_ZIP_ACCEL bool "EROFS hardware decompression support" depends on EROFS_FS_ZIP diff --git a/fs/erofs/decompressor_zstd.c b/fs/erofs/decompressor_zstd.c index ab318a2400f9..44f9d89674e3 100644 --- a/fs/erofs/decompressor_zstd.c +++ b/fs/erofs/decompressor_zstd.c @@ -53,7 +53,8 @@ static int __init z_erofs_zstd_init(void) { /* by default, use # of possible CPUs instead */ if (!z_erofs_zstd_nstrms) - z_erofs_zstd_nstrms = num_possible_cpus(); + z_erofs_zstd_nstrms = min_t(unsigned int, num_possible_cpus(), + CONFIG_EROFS_FS_ZIP_ZSTD_DEFAULT_MAX_STREAMS); for (; z_erofs_zstd_avail_strms < z_erofs_zstd_nstrms; ++z_erofs_zstd_avail_strms) { -- 2.43.0