[RFC PATCH v2 05/13] zram: Remove PAGE_SIZE use in preprocessor conditionals
From: Eric Curtin
Date: Tue Dec 01 2026 - 22:18:16 EST
From: Eric Curtin <eric.curtin@xxxxxxxxxx>
With arm64 boot-time page size selection PAGE_SIZE and PAGE_SHIFT are
not compile-time constants, so they cannot be used in #if or to size
arrays.
Turn the "#if PAGE_SIZE != 4096" is_partial_io() and the
ZRAM_PARTIAL_IO define into ordinary C conditions on PAGE_SIZE, and set
max_write_zeroes_sectors with a conditional expression instead of
#if. Size the pp_buckets array with a new NUM_PP_BUCKETS_MAX based on
PAGE_SIZE_MAX, and base ZRAM_FLAG_SHIFT on PAGE_SHIFT_MAX so that the
flag bits do not overlap the size bits for any page size.
The compiler still folds the conditions when the page size is fixed, so
there is no functional change for compile-time page sizes.
Signed-off-by: Eric Curtin <eric.curtin@xxxxxxxxxx>
---
drivers/block/zram/zram_drv.c | 20 ++++++--------------
drivers/block/zram/zram_drv.h | 2 +-
2 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index ab064c84b092..11a2341a0764 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -209,18 +209,10 @@ static bool zram_can_store_page(struct zram *zram)
return !zram->limit_pages || alloced_pages <= zram->limit_pages;
}
-#if PAGE_SIZE != 4096
static inline bool is_partial_io(struct bio_vec *bvec)
{
- return bvec->bv_len != PAGE_SIZE;
+ return PAGE_SIZE != 4096 && bvec->bv_len != PAGE_SIZE;
}
-#define ZRAM_PARTIAL_IO 1
-#else
-static inline bool is_partial_io(struct bio_vec *bvec)
-{
- return false;
-}
-#endif
#if defined CONFIG_ZRAM_WRITEBACK || defined CONFIG_ZRAM_MULTI_COMP
struct zram_pp_slot {
@@ -234,9 +226,10 @@ struct zram_pp_slot {
*/
#define PP_BUCKET_SIZE_RANGE 64
#define NUM_PP_BUCKETS ((PAGE_SIZE / PP_BUCKET_SIZE_RANGE) + 1)
+#define NUM_PP_BUCKETS_MAX ((PAGE_SIZE_MAX / PP_BUCKET_SIZE_RANGE) + 1)
struct zram_pp_ctl {
- struct list_head pp_buckets[NUM_PP_BUCKETS];
+ struct list_head pp_buckets[NUM_PP_BUCKETS_MAX];
};
static struct zram_pp_ctl *init_pp_ctl(void)
@@ -1519,7 +1512,7 @@ static int read_from_bdev(struct zram *zram, struct page *page,
{
atomic64_inc(&zram->stats.bd_reads);
if (!parent) {
- if (WARN_ON_ONCE(!IS_ENABLED(ZRAM_PARTIAL_IO)))
+ if (WARN_ON_ONCE(PAGE_SIZE == 4096))
return -EIO;
return read_from_bdev_sync(zram, page, index, blk_idx);
}
@@ -3078,9 +3071,8 @@ static int zram_add(void)
* aligned to physical block size. So we can't ensure that all
* discarded logical blocks are zeroed.
*/
-#if ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE
- .max_write_zeroes_sectors = UINT_MAX,
-#endif
+ .max_write_zeroes_sectors =
+ ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE ? UINT_MAX : 0,
.features = BLK_FEAT_STABLE_WRITES |
BLK_FEAT_SYNCHRONOUS,
};
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 7a55d751417e..b92d81fafd3f 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -37,7 +37,7 @@
*
* We use BUILD_BUG_ON() to make sure that zram pageflags don't overflow.
*/
-#define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1)
+#define ZRAM_FLAG_SHIFT (PAGE_SHIFT_MAX + 1)
/* Only 2 bits are allowed for comp priority index */
#define ZRAM_COMP_PRIORITY_MASK 0x3