Re: [PATCH v8 4/4] md: allow configuring logical block size

From: Li Nan
Date: Mon Nov 03 2025 - 08:11:22 EST




在 2025/11/3 11:11, Xiao Ni 写道:
On Thu, Oct 30, 2025 at 2:36 PM <linan666@xxxxxxxxxxxxxxx> wrote:

From: Li Nan <linan122@xxxxxxxxxx>

Previously, raid array used the maximum logical block size (LBS)
of all member disks. Adding a larger LBS disk at runtime could
unexpectedly increase RAID's LBS, risking corruption of existing
partitions. This can be reproduced by:

```
# LBS of sd[de] is 512 bytes, sdf is 4096 bytes.
mdadm -CRq /dev/md0 -l1 -n3 /dev/sd[de] missing --assume-clean

# LBS is 512
cat /sys/block/md0/queue/logical_block_size

# create partition md0p1
parted -s /dev/md0 mklabel gpt mkpart primary 1MiB 100%
lsblk | grep md0p1

# LBS becomes 4096 after adding sdf
mdadm --add -q /dev/md0 /dev/sdf
cat /sys/block/md0/queue/logical_block_size

# partition lost
partprobe /dev/md0
lsblk | grep md0p1
```

Simply restricting larger-LBS disks is inflexible. In some scenarios,
only disks with 512 bytes LBS are available currently, but later, disks
with 4KB LBS may be added to the array.

Making LBS configurable is the best way to solve this scenario.
After this patch, the raid will:
- store LBS in disk metadata
- add a read-write sysfs 'mdX/logical_block_size'

Future mdadm should support setting LBS via metadata field during RAID
creation and the new sysfs. Though the kernel allows runtime LBS changes,
users should avoid modifying it after creating partitions or filesystems
to prevent compatibility issues.

Only 1.x metadata supports configurable LBS. 0.90 metadata inits all
fields to default values at auto-detect. Supporting 0.90 would require
more extensive changes and no such use case has been observed.

Note that many RAID paths rely on PAGE_SIZE alignment, including for
metadata I/O. A larger LBS than PAGE_SIZE will result in metadata
read/write failures. So this config should be prevented.

Signed-off-by: Li Nan <linan122@xxxxxxxxxx >
Hi Li Nan


Hi Xiao,

Thanks for your review.

The problem can't be fixed if there is no user space (mdadm) patch, right?


Yeah, mdadm should update same time. And Guanghao will send a mdadm patch
later.

The patch Looks good to me.
Reviewed-by: Xiao Ni <xni@xxxxxxxxxx>


Sorry for the trouble. I sent the v9 with some changes to the
Documentation. Could you please review v9 patch when you have time?


.


--
Thanks,
Nan