On 04/19, Pankaj Raghav wrote:
> On 2022-04-13 21:45, Jaegeuk Kim wrote:>> As I explained in the v1
> thread, zoned support for f2fs assumes po2 zone
> >> sizes. For e.g.,
> >> static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
> >>            struct block_device *bdev, block_t blkstart, block_t blklen)
> >> {
> >>    sector_t sector, nr_sects;
> >>    block_t lblkstart = blkstart;
> >>    int devi = 0;
> >> ...
> >> ...
> >>            // Assumes zone sectors to be po2
> s/Assumes zone sectors to be po2/Works correctly only if the base
> alignment is a power of 2 value./
> 
> Taken from align.h:
> /* @a is a power of 2 value */
> ...
> #define IS_ALIGNED(x, a)    (((x) & ((typeof(x))(a) - 1)) == 0)
> 
> > 
> > Well, I think this will be aligned to 2MB, if the device gives NPO2? IOWs, 
> > this
> Could you elaborate what you mean by `this will be aligned to 2MB`?
> > is just checking the granularity, not PO2.
> Yeah, so whenever we send a discard or a zone reset, the block zoned
> device expects the `sector` to be the start of a device zone. The check
> below essentially checks if the `sector` aligns with the `zone size
> sector` of the device. But to check for alignment using this `sector &
> (bdev_zone_sectors(bdev) - 1)` will only work if
> `bdev_zone_sectors(bdev)` is a power of 2.
> 
> Even if the device zone size is a multiple of 2MB, these checks will
> fail for a non power of 2 zone size device. The solution is simple, it
> is to make this alignment check generic but until this is done in the
> kernel, mkfs.f2fs should fail to mount for a non power of 2 device.
> > 
> >>            if (sector & (bdev_zone_sectors(bdev) - 1) ||
> >>                            nr_sects != bdev_zone_sectors(bdev)) {
> >>                    f2fs_err(sbi, "(%d) %s: Unaligned zone reset attempted 
> >> (block %x + %x)",
> >>                             devi, sbi->s_ndevs ? FDEV(devi).path : "",
> >>                             blkstart, blklen);
> I tried it locally in QEMU along with my local changes to remove power
> of 2 constraint in the block layer and zns device, and indeed the
> `Unaligned zone reset attempted` error popped up for a zns drive with a
> zone size 96MB.
> 
> When I changed the condition from `sector & (bdev_zone_sectors(bdev) -
> 1)` to `sector % bdev_zone_sectors(bdev)`, the error went away because
> the calculation doesn't depend on the alignment base to be a power of 2.
> 
> 
> TL;DR until we change some calculations in f2fs for zoned device to be
> generic, we need to bail out during mkfs time for non power of 2 zone
> size devices.

Ah, I see. Yeah, that in f2fs is actually PO2. Let me merge this patch to
force it before getting that relax. Thanks,



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to