Linux bcache driver list
 help / color / mirror / Atom feed
* [RFC PATCH v2 04/13] md: Remove compile-time PAGE_SIZE use in md, dm and bcache
       [not found] <20261202031647.1690622-1-ericcurtin17@gmail.com>
@ 2026-12-02  3:16 ` Eric Curtin
  0 siblings, 0 replies; only message in thread
From: Eric Curtin @ 2026-12-02  3:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Eric Curtin, Coly Li, Kent Overstreet, Alasdair Kergon,
	Mike Snitzer, Mikulas Patocka, Benjamin Marzinski, Matthew Sakai,
	Song Liu, Yu Kuai, Li Nan, Xiao Ni, linux-bcache, dm-devel,
	linux-raid

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 size arrays, appear in #if
or initialise static const data.

- raid1/raid10: add RESYNC_PAGES_MAX, based on PAGE_SIZE_MIN, and use it
  for struct resync_pages and the page_len array in process_checks().
- raid5: introduce RAID5_VAR_STRIPE_SIZE, defined unless both
  PAGE_SIZE_MIN and PAGE_SIZE_MAX equal DEFAULT_STRIPE_SIZE, and use it
  in place of "PAGE_SIZE != DEFAULT_STRIPE_SIZE" in the #if checks.
- bcache: make the dump_iterator buffer a flexible array and allocate a
  full PAGE_SIZE for it.
- dm-switch: the argument limits depend on KMALLOC_MAX_SIZE, so the
  dm_arg array in switch_ctr() can no longer be static const.
- dm-writecache: compute BITMAP_GRANULARITY with max_t() instead of #if.
- dm-vdo: make MAX_BLOCKS_PER_VIO a macro rather than an enum member and
  check VDO_BLOCK_SIZE against PAGE_SIZE_MIN.

No functional change for compile-time page sizes.

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
---
 drivers/md/bcache/debug.c    |  4 ++--
 drivers/md/dm-switch.c       |  2 +-
 drivers/md/dm-vdo/data-vio.c |  2 +-
 drivers/md/dm-vdo/vio.h      |  4 +---
 drivers/md/dm-writecache.c   |  6 +-----
 drivers/md/raid1-10.c        |  3 ++-
 drivers/md/raid1.c           |  2 +-
 drivers/md/raid5.c           | 18 +++++++++---------
 drivers/md/raid5.h           | 13 ++++++++-----
 9 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c
index 2691a5da3368..4c8668a701e5 100644
--- a/drivers/md/bcache/debug.c
+++ b/drivers/md/bcache/debug.c
@@ -157,10 +157,10 @@ void bch_data_verify(struct cached_dev *dc, struct bio *bio)
 /* XXX: cache set refcounting */
 
 struct dump_iterator {
-	char			buf[PAGE_SIZE];
 	size_t			bytes;
 	struct cache_set	*c;
 	struct keybuf		keys;
+	char			buf[];
 };
 
 static bool dump_pred(struct keybuf *buf, struct bkey *k)
@@ -208,7 +208,7 @@ static int bch_dump_open(struct inode *inode, struct file *file)
 	struct cache_set *c = inode->i_private;
 	struct dump_iterator *i;
 
-	i = kzalloc_obj(struct dump_iterator);
+	i = kzalloc_flex(*i, buf, PAGE_SIZE);
 	if (!i)
 		return -ENOMEM;
 
diff --git a/drivers/md/dm-switch.c b/drivers/md/dm-switch.c
index e5b507b4fa7b..9eed3f3a4db2 100644
--- a/drivers/md/dm-switch.c
+++ b/drivers/md/dm-switch.c
@@ -252,7 +252,7 @@ static void switch_dtr(struct dm_target *ti)
  */
 static int switch_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 {
-	static const struct dm_arg _args[] = {
+	const struct dm_arg _args[] = {
 		{1, (KMALLOC_MAX_SIZE - sizeof(struct switch_ctx)) / sizeof(struct switch_path), "Invalid number of paths"},
 		{1, UINT_MAX, "Invalid region size"},
 		{0, 0, "Invalid number of optional args"},
diff --git a/drivers/md/dm-vdo/data-vio.c b/drivers/md/dm-vdo/data-vio.c
index 370d4239ba31..fe0329354cfb 100644
--- a/drivers/md/dm-vdo/data-vio.c
+++ b/drivers/md/dm-vdo/data-vio.c
@@ -785,7 +785,7 @@ static int initialize_data_vio(struct data_vio *data_vio, struct vdo *vdo)
 	struct bio *bio;
 	int result;
 
-	BUILD_BUG_ON(VDO_BLOCK_SIZE > PAGE_SIZE);
+	BUILD_BUG_ON(VDO_BLOCK_SIZE > PAGE_SIZE_MIN);
 	result = vdo_allocate_memory(VDO_BLOCK_SIZE, 0, "data_vio data",
 				     &data_vio->vio.data);
 	if (result != VDO_SUCCESS)
diff --git a/drivers/md/dm-vdo/vio.h b/drivers/md/dm-vdo/vio.h
index 7a8a6819aec4..2beedaba89e5 100644
--- a/drivers/md/dm-vdo/vio.h
+++ b/drivers/md/dm-vdo/vio.h
@@ -17,9 +17,7 @@
 #include "types.h"
 #include "vdo.h"
 
-enum {
-	MAX_BLOCKS_PER_VIO = (BIO_MAX_VECS << PAGE_SHIFT) / VDO_BLOCK_SIZE,
-};
+#define MAX_BLOCKS_PER_VIO ((BIO_MAX_VECS << PAGE_SHIFT) / VDO_BLOCK_SIZE)
 
 struct pooled_vio {
 	/* The underlying vio */
diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
index 6f977fb8c939..40643f982b94 100644
--- a/drivers/md/dm-writecache.c
+++ b/drivers/md/dm-writecache.c
@@ -31,11 +31,7 @@
 #define MAX_AGE_UNSPECIFIED		-1UL
 #define PAUSE_WRITEBACK			(HZ * 3)
 
-#define BITMAP_GRANULARITY	65536
-#if BITMAP_GRANULARITY < PAGE_SIZE
-#undef BITMAP_GRANULARITY
-#define BITMAP_GRANULARITY	PAGE_SIZE
-#endif
+#define BITMAP_GRANULARITY	max_t(int, 65536, PAGE_SIZE)
 
 #if IS_ENABLED(CONFIG_ARCH_HAS_PMEM_API) && IS_ENABLED(CONFIG_FS_DAX)
 #define DM_WRITECACHE_HAS_PMEM
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index 341a9785e3f2..919de6611ee3 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -2,6 +2,7 @@
 /* Maximum size of each resync request */
 #define RESYNC_BLOCK_SIZE (64*1024)
 #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
+#define RESYNC_PAGES_MAX ((RESYNC_BLOCK_SIZE + PAGE_SIZE_MIN-1) / PAGE_SIZE_MIN)
 
 /* when we get a read error on a read-only array, we redirect to another
  * device without failing the first device, or trying to over-write to
@@ -21,7 +22,7 @@
 /* for managing resync I/O pages */
 struct resync_pages {
 	void		*raid_bio;
-	struct page	*pages[RESYNC_PAGES];
+	struct page	*pages[RESYNC_PAGES_MAX];
 };
 
 struct raid1_plug_cb {
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 894efb50c6d5..9cd66dbee221 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2252,7 +2252,7 @@ static void process_checks(struct r1bio *r1_bio)
 		struct page **ppages = get_resync_pages(pbio)->pages;
 		struct page **spages = get_resync_pages(sbio)->pages;
 		struct bio_vec *bi;
-		int page_len[RESYNC_PAGES] = { 0 };
+		int page_len[RESYNC_PAGES_MAX] = { 0 };
 		struct bvec_iter_all iter_all;
 
 		if (sbio->bi_end_io != end_sync_read)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index d52adf81065a..0bbdd786b196 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -463,7 +463,7 @@ static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash)
 	return sh;
 }
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 static void free_stripe_pages(struct stripe_head *sh)
 {
 	int i;
@@ -527,7 +527,7 @@ static void shrink_buffers(struct stripe_head *sh)
 	int i;
 	int num = sh->raid_conf->pool_size;
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 	for (i = 0; i < num ; i++) {
 		struct page *p;
 
@@ -550,7 +550,7 @@ static int grow_buffers(struct stripe_head *sh, gfp_t gfp)
 	int i;
 	int num = sh->raid_conf->pool_size;
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 	for (i = 0; i < num; i++) {
 		struct page *page;
 
@@ -2353,7 +2353,7 @@ static void raid_run_ops(struct stripe_head *sh, unsigned long ops_request)
 
 static void free_stripe(struct kmem_cache *sc, struct stripe_head *sh)
 {
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	kfree(sh->pages);
 #endif
 	if (sh->ppl_page)
@@ -2385,7 +2385,7 @@ static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp,
 				return NULL;
 			}
 		}
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 		if (init_stripe_shared_pages(sh, conf, disks)) {
 			free_stripe(sc, sh);
 			return NULL;
@@ -2596,7 +2596,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
 		osh = get_free_stripe(conf, hash);
 		unlock_device_hash_lock(conf, hash);
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	for (i = 0; i < osh->nr_pages; i++) {
 		nsh->pages[i] = osh->pages[i];
 		osh->pages[i] = NULL;
@@ -2655,7 +2655,7 @@ static int resize_stripes(struct r5conf *conf, int newsize)
 		nsh = list_entry(newstripes.next, struct stripe_head, lru);
 		list_del_init(&nsh->lru);
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 		for (i = 0; i < nsh->nr_pages; i++) {
 			if (nsh->pages[i])
 				continue;
@@ -7173,7 +7173,7 @@ raid5_show_stripe_size(struct mddev  *mddev, char *page)
 	return ret;
 }
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 static ssize_t
 raid5_store_stripe_size(struct mddev  *mddev, const char *page, size_t len)
 {
@@ -7711,7 +7711,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
 		goto abort;
 
 	conf->mddev = mddev;
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	conf->stripe_size = DEFAULT_STRIPE_SIZE;
 	conf->stripe_shift = ilog2(DEFAULT_STRIPE_SIZE) - 9;
 	conf->stripe_sectors = DEFAULT_STRIPE_SIZE >> 9;
diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h
index 94b3e2c947ba..0f87b58a9a61 100644
--- a/drivers/md/raid5.h
+++ b/drivers/md/raid5.h
@@ -197,6 +197,9 @@ enum reconstruct_states {
 };
 
 #define DEFAULT_STRIPE_SIZE	4096
+#if PAGE_SIZE_MIN != DEFAULT_STRIPE_SIZE || PAGE_SIZE_MAX != DEFAULT_STRIPE_SIZE
+#define RAID5_VAR_STRIPE_SIZE
+#endif
 struct stripe_head {
 	struct hlist_node	hash;
 	struct list_head	lru;	      /* inactive_list or handle_list */
@@ -249,7 +252,7 @@ struct stripe_head {
 		enum sum_check_flags zero_sum_result;
 	} ops;
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	/* These pages will be used by bios in dev[i] */
 	struct page	**pages;
 	int	nr_pages;	/* page array size */
@@ -480,7 +483,7 @@ struct disk_info {
 
 #define NR_STRIPES		256
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 #define STRIPE_SIZE		PAGE_SIZE
 #define STRIPE_SHIFT		(PAGE_SHIFT - 9)
 #define STRIPE_SECTORS		(STRIPE_SIZE>>9)
@@ -578,7 +581,7 @@ struct r5conf {
 	int			raid_disks;
 	int			max_nr_stripes;
 	int			min_nr_stripes;
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 	unsigned long	stripe_size;
 	unsigned int	stripe_shift;
 	unsigned long	stripe_sectors;
@@ -696,7 +699,7 @@ struct r5conf {
 	int			ctx_size;
 };
 
-#if PAGE_SIZE == DEFAULT_STRIPE_SIZE
+#ifndef RAID5_VAR_STRIPE_SIZE
 #define RAID5_STRIPE_SIZE(conf)	STRIPE_SIZE
 #define RAID5_STRIPE_SHIFT(conf)	STRIPE_SHIFT
 #define RAID5_STRIPE_SECTORS(conf)	STRIPE_SECTORS
@@ -784,7 +787,7 @@ static inline int algorithm_is_DDF(int layout)
 	return layout >= 8 && layout <= 10;
 }
 
-#if PAGE_SIZE != DEFAULT_STRIPE_SIZE
+#ifdef RAID5_VAR_STRIPE_SIZE
 /*
  * Return offset of the corresponding page for r5dev.
  */

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02  3:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261202031647.1690622-1-ericcurtin17@gmail.com>
2026-12-02  3:16 ` [RFC PATCH v2 04/13] md: Remove compile-time PAGE_SIZE use in md, dm and bcache Eric Curtin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox