mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Eric Curtin <eric.curtin@docker.com>,
	Gao Xiang <xiang@kernel.org>, Chao Yu <chao@kernel.org>,
	Yue Hu <zbestahu@gmail.com>, Jingbo Xu <jefflexu@163.com>,
	Sandeep Dhavale <dhavale@google.com>,
	Hongbo Li <hongbohbli@tencent.com>,
	Chunhai Guo <guochunhai@vivo.com>, Nick Terrell <terrelln@fb.com>,
	David Sterba <dsterba@suse.com>,
	linux-erofs@lists.ozlabs.org
Subject: [RFC PATCH v2 11/22] erofs: Make the decompressor bounce buffers flexible arrays
Date: Wed,  2 Dec 2026 03:15:14 +0000	[thread overview]
Message-ID: <20261202031533.1665444-12-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261202031533.1665444-1-ericcurtin17@gmail.com>

From: Eric Curtin <eric.curtin@docker.com>

With arm64 boot-time page size selection PAGE_SIZE is not a compile-time
constant, so it cannot be used as the size of the bounce[] member in the
deflate, lzma and zstd stream structures.

Turn bounce[] into a flexible array member in struct z_erofs_deflate,
z_erofs_lzma and z_erofs_zstd, move it to the end of struct
z_erofs_zstd, and allocate the structures with kzalloc_flex(*strm,
bounce, PAGE_SIZE) so that the run-time page size sets the buffer size.

In zdata.c, compute Z_EROFS_PCLUSTER_MAX_PAGES with PAGE_SIZE_MIN. It is
used as an upper bound and must be constant.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 fs/erofs/decompressor_deflate.c | 4 ++--
 fs/erofs/decompressor_lzma.c    | 4 ++--
 fs/erofs/decompressor_zstd.c    | 4 ++--
 fs/erofs/zdata.c                | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/erofs/decompressor_deflate.c b/fs/erofs/decompressor_deflate.c
index 6167af1ffeb9..4cd441cb9070 100644
--- a/fs/erofs/decompressor_deflate.c
+++ b/fs/erofs/decompressor_deflate.c
@@ -5,7 +5,7 @@
 struct z_erofs_deflate {
 	struct z_erofs_deflate *next;
 	struct z_stream_s z;
-	u8 bounce[PAGE_SIZE];
+	u8 bounce[];
 };
 
 static DEFINE_SPINLOCK(z_erofs_deflate_lock);
@@ -71,7 +71,7 @@ static int z_erofs_load_deflate_config(struct super_block *sb,
 		     ++z_erofs_deflate_avail_strms) {
 			struct z_erofs_deflate *strm;
 
-			strm = kzalloc_obj(*strm);
+			strm = kzalloc_flex(*strm, bounce, PAGE_SIZE);
 			if (!strm)
 				goto failed;
 			/* XXX: in-kernel zlib cannot customize windowbits */
diff --git a/fs/erofs/decompressor_lzma.c b/fs/erofs/decompressor_lzma.c
index 9d15f94cbee1..5a5897b12f83 100644
--- a/fs/erofs/decompressor_lzma.c
+++ b/fs/erofs/decompressor_lzma.c
@@ -6,7 +6,7 @@ struct z_erofs_lzma {
 	struct z_erofs_lzma *next;
 	struct xz_dec_microlzma *state;
 	unsigned int dict_size;
-	u8 bounce[PAGE_SIZE];
+	u8 bounce[];
 };
 
 /* considering the LZMA performance, no need to use a lockless list for now */
@@ -56,7 +56,7 @@ static int __init z_erofs_lzma_init(void)
 				CONFIG_EROFS_FS_ZIP_LZMA_DEFAULT_MAX_STREAMS);
 
 	for (i = 0; i < z_erofs_lzma_nstrms; ++i) {
-		struct z_erofs_lzma *strm = kzalloc_obj(*strm);
+		struct z_erofs_lzma *strm = kzalloc_flex(*strm, bounce, PAGE_SIZE);
 
 		if (!strm) {
 			z_erofs_lzma_exit();
diff --git a/fs/erofs/decompressor_zstd.c b/fs/erofs/decompressor_zstd.c
index ab318a2400f9..e9dc6eb67561 100644
--- a/fs/erofs/decompressor_zstd.c
+++ b/fs/erofs/decompressor_zstd.c
@@ -4,9 +4,9 @@
 
 struct z_erofs_zstd {
 	struct z_erofs_zstd *next;
-	u8 bounce[PAGE_SIZE];
 	void *wksp;
 	unsigned int wkspsz;
+	u8 bounce[];
 };
 
 static DEFINE_SPINLOCK(z_erofs_zstd_lock);
@@ -59,7 +59,7 @@ static int __init z_erofs_zstd_init(void)
 	     ++z_erofs_zstd_avail_strms) {
 		struct z_erofs_zstd *strm;
 
-		strm = kzalloc_obj(*strm);
+		strm = kzalloc_flex(*strm, bounce, PAGE_SIZE);
 		if (!strm) {
 			z_erofs_zstd_exit();
 			return -ENOMEM;
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index e981e371d6c2..bc4a7133a097 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -10,7 +10,7 @@
 #include <trace/events/erofs.h>
 
 #define Z_EROFS_MAX_SYNC_DECOMPRESS_BYTES	12288
-#define Z_EROFS_PCLUSTER_MAX_PAGES	(Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE)
+#define Z_EROFS_PCLUSTER_MAX_PAGES	(Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE_MIN)
 #define Z_EROFS_INLINE_BVECS		2
 
 struct z_erofs_bvec {

  parent reply	other threads:[~2026-12-02  3:16 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  3:15 [RFC PATCH v2 00/22] fs: Prepare for boot-time page size selection on arm64 Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 01/22] smb: client: Use PAGE_SIZE_MIN in the lock element build checks Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 02/22] fs/resctrl: Define the kernfs_ops as page-size variables Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 03/22] ocfs2: Use PAGE_SIZE_MIN/MAX for the page-count limits Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 04/22] ntfs3: Use MAX_BUF_PER_PAGE_SIZE_MAX for struct ntfs_buffers Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 05/22] ntfs: Use PAGE_SIZE_MIN in NTFS_WOF_MAX_PAGES Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 06/22] nilfs2: Test PAGE_SIZE at run time in the rec_len conversions Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 07/22] jfs: Use PAGE_SIZE_MAX to size the metapage anchor arrays Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 08/22] isofs: Use PAGE_SIZE_MAX for zisofs_sink_page Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 09/22] ext4: Use PAGE_SIZE_MAX for the inline KUnit test data buffer Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 10/22] ext2: Test PAGE_SIZE at run time in the rec_len conversions Eric Curtin
2026-12-02  3:15 ` Eric Curtin [this message]
2026-12-02  3:15 ` [RFC PATCH v2 12/22] ecryptfs: Resolve the PAGE_SIZE cache sizes at cache creation time Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 13/22] dlm: Use PAGE_SIZE_MIN in the lowcomms buffer size build check Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 14/22] cramfs: Allocate the read buffers at init time Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 15/22] ceph: Use PAGE_SHIFT_MIN in the ceph_fscrypt_blocks() build check Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 16/22] btrfs: Use PAGE_SIZE_MAX in a static_assert and min_t() for PAGE_SHIFT Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 17/22] afs: Use PAGE_SIZE_MAX to size struct afs_xdr_dir_page Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 18/22] fuse: Check CUSE and ioctl buffer sizes against PAGE_SIZE_MIN Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 19/22] btrfs: Use PAGE_SIZE_MAX and PAGE_SIZE_MIN for compile-time checks Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 20/22] NFSv4: Use PAGE_SIZE_MIN to size ACL and xattr page arrays Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 21/22] coredump: Use PAGE_SIZE_MIN for the zero-fill buffer Eric Curtin
2026-12-02  3:15 ` [RFC PATCH v2 22/22] fat: Use MAX_BUF_PER_PAGE_SIZE_MAX to size buffer_head arrays Eric Curtin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202031533.1665444-12-ericcurtin17@gmail.com \
    --to=ericcurtin17@gmail.com \
    --cc=chao@kernel.org \
    --cc=dhavale@google.com \
    --cc=dsterba@suse.com \
    --cc=eric.curtin@docker.com \
    --cc=guochunhai@vivo.com \
    --cc=hongbohbli@tencent.com \
    --cc=jefflexu@163.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=terrelln@fb.com \
    --cc=xiang@kernel.org \
    --cc=zbestahu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®