Re: [RFC PATCH v2 19/22] btrfs: Use PAGE_SIZE_MAX and PAGE_SIZE_MIN for compile-time checks
From: Qu Wenruo
Date: Wed Dec 02 2026 - 03:54:05 EST
在 2026/12/2 13:45, Eric Curtin 写道:
From: Ryan Roberts <ryan.roberts@xxxxxxx>
With boot-time page size selection PAGE_SIZE is not a compile-time
constant, so it cannot be used in static assertions or to size arrays.
Check alignment against PAGE_SIZE_MAX in the static_assert()s for
BTRFS_MAX_COMPRESSED, the defrag CLUSTER_SIZE, and BTRFS_STRIPE_LEN in
scrub. A size aligned to PAGE_SIZE_MAX is also aligned to any smaller
page size.
Compute INLINE_EXTENT_BUFFER_PAGES with PAGE_SIZE_MIN, which gives the
largest number of pages per extent buffer and so is the worst case for
the inline pages[] array.
No functional change for compile-time page sizes.
Co-developed-by: Petr Tesarik <ptesarik@xxxxxxxx>
Signed-off-by: Petr Tesarik <ptesarik@xxxxxxxx>
Signed-off-by: Ryan Roberts <ryan.roberts@xxxxxxx>
Signed-off-by: Eric Curtin <eric.curtin@xxxxxxxxxx>
I guess as long as the PAGE_SIZE_MAX on arm64 is still no larger than 64K, it would be fine for btrfs.
But if one day it's going to support 128K page size, then btrfs will have a lot of extra work to adapt for that...
Thanks,
Qu
---
fs/btrfs/compression.h | 2 +-
fs/btrfs/defrag.c | 2 +-
fs/btrfs/extent_io.h | 2 +-
fs/btrfs/scrub.c | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index 1022dc53ec51..7b3506d4202f 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -34,7 +34,7 @@ struct btrfs_ordered_extent;
/* Maximum length of compressed data stored on disk */
#define BTRFS_MAX_COMPRESSED (SZ_128K)
#define BTRFS_MAX_COMPRESSED_PAGES (BTRFS_MAX_COMPRESSED / PAGE_SIZE)
-static_assert((BTRFS_MAX_COMPRESSED % PAGE_SIZE) == 0);
+static_assert((BTRFS_MAX_COMPRESSED % PAGE_SIZE_MAX) == 0);
/* The max size for a single worker to compress. */
#define BTRFS_COMPRESSION_CHUNK_SIZE (SZ_512K)
diff --git a/fs/btrfs/defrag.c b/fs/btrfs/defrag.c
index cbc532b49c67..9795a612e3c9 100644
--- a/fs/btrfs/defrag.c
+++ b/fs/btrfs/defrag.c
@@ -1117,7 +1117,7 @@ static int defrag_collect_targets(struct btrfs_inode *inode,
}
#define CLUSTER_SIZE (SZ_256K)
-static_assert(PAGE_ALIGNED(CLUSTER_SIZE));
+static_assert(IS_ALIGNED(CLUSTER_SIZE, PAGE_SIZE_MAX));
/*
* Defrag one contiguous target range.
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index c55b37cb24b7..ca86d619dfaa 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -81,7 +81,7 @@ enum {
int __init extent_buffer_init_cachep(void);
void __cold extent_buffer_free_cachep(void);
-#define INLINE_EXTENT_BUFFER_PAGES (BTRFS_MAX_METADATA_BLOCKSIZE / PAGE_SIZE)
+#define INLINE_EXTENT_BUFFER_PAGES (BTRFS_MAX_METADATA_BLOCKSIZE / PAGE_SIZE_MIN)
struct extent_buffer {
u64 start;
u32 len;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index bbe74af3506c..426e00c1d59e 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -219,8 +219,8 @@ struct scrub_ctx {
refcount_t refs;
};
-static_assert(BTRFS_STRIPE_LEN >= PAGE_SIZE);
-static_assert(IS_ALIGNED(BTRFS_STRIPE_LEN, PAGE_SIZE));
+static_assert(BTRFS_STRIPE_LEN >= PAGE_SIZE_MAX);
+static_assert(IS_ALIGNED(BTRFS_STRIPE_LEN, PAGE_SIZE_MAX));
#define scrub_calc_start_bit(stripe, name, block_nr) \
({ \