Linux block layer
 help / color / mirror / Atom feed
From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Eric Curtin <eric.curtin@docker.com>,
	Minchan Kim <minchan@kernel.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org
Subject: [RFC PATCH v2 05/13] zram: Remove PAGE_SIZE use in preprocessor conditionals
Date: Wed,  2 Dec 2026 03:16:26 +0000	[thread overview]
Message-ID: <20261202031647.1690622-6-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261202031647.1690622-1-ericcurtin17@gmail.com>

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

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@docker.com>
---
 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

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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  3:16 [RFC PATCH v2 00/13] block/storage: Prepare for boot-time page size selection on arm64 Eric Curtin
2026-12-02  3:16 ` Eric Curtin [this message]
2026-12-02  3:16 ` [RFC PATCH v2 06/13] xen/blkback: Size indirect_pages for the largest page size Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 07/13] null_blk: Size the nullb_page bitmap for PAGE_SIZE_MAX Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 08/13] drbd: Use PAGE_SHIFT_MIN in preprocessor checks Eric Curtin
2026-12-02  3:16 ` [RFC PATCH v2 11/13] virtio: Handle boot-time PAGE_SIZE in balloon, blk and 9p transport 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=20261202031647.1690622-6-ericcurtin17@gmail.com \
    --to=ericcurtin17@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=eric.curtin@docker.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=senozhatsky@chromium.org \
    /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