On Fri, Mar 27, 2026 at 02:36:19PM -0600, Keith Busch wrote:
> On Fri, Mar 27, 2026 at 03:41:50PM -0400, Benjamin Marzinski wrote:
> > > @@ -4047,9 +4047,15 @@ static void dm_integrity_io_hints(struct dm_target 
> > > *ti, struct queue_limits *lim
> > >   struct dm_integrity_c *ic = ti->private;
> > >  
> > >   if (ic->sectors_per_block > 1) {
> > > -         limits->logical_block_size = ic->sectors_per_block << 
> > > SECTOR_SHIFT;
> > > -         limits->physical_block_size = ic->sectors_per_block << 
> > > SECTOR_SHIFT;
> > > -         limits->io_min = ic->sectors_per_block << SECTOR_SHIFT;
> > > +         limits->logical_block_size =
> > > +                         max(limits->logical_block_size,
> > > +                             ic->sectors_per_block << SECTOR_SHIFT);
> > > +         limits->physical_block_size =
> > > +                         max(limits->physical_block_size,
> > > +                             ic->sectors_per_block << SECTOR_SHIFT);
> > > +         limits->io_min =
> > > +                         max(limits->io_min,
> > > +                             ic->sectors_per_block << SECTOR_SHIFT);
> > >           limits->dma_alignment = limits->logical_block_size - 1;
> > >           limits->discard_granularity = ic->sectors_per_block << 
> > > SECTOR_SHIFT;
> > 
> > Shouldn't this also respect the underlying device's discard_granularity?
> 
> It doesn't appear to. I left it unchanged as I'm not very familiar with
> this device mapper, so that seemed safer. But I thought it was fine as
> is: this dm doesn't appear to forward discards, so the underlying
> device's constraints aren't brought into the operation. It looks like it
> just sets a "DISCARD_FILLER" pattern into metadata.

If you set allow discards, dm-intergrity should pass them down.

For example:

VALID:
# modprobe scsi_debug dev_size_mb=1024 lbpu=1
# integritysetup format -s 1024 /dev/sda
# integritysetup open --allow-discards /dev/sda integrity-test
# cat /sys/block/sda/queue/discard_granularity                  
512
# cat /sys/block/dm-1/queue/discard_granularity
1024
# blkdiscard -o 1024 -l 16384 /dev/mapper/integrity-test
# echo $?
0

perf trace:
      blkdiscard   11852 [000] 256486.743981:    block:block_bio_queue: 253,1 
DS 0 + 2 [blkdiscard]
 kworker/0:1-eve   11763 [000] 256486.744063:    block:block_bio_queue: 8,0 DS 
16504 + 2 [kworker/0:1]
 kworker/0:1-eve   11763 [000] 256486.744076:     block:block_rq_issue: 8,0 DS 
1024 () 16504 + 2 0x2,0,4 [kworker/0:1]
         swapper       0 [000] 256486.745099:  block:block_rq_complete: 8,0 DS 
() 16504 + 2 0x2,0,4 [0]
         swapper       0 [000] 256486.745104: block:block_bio_complete: 253,1 
DS 0 + 2 [0]


INVALID:
# modprobe scsi_debug dev_size_mb=1024 lbpu=1 sector_size=4096
# integritysetup format -s 1024 /dev/sda
# integritysetup open --allow-discards /dev/sda integrity-test
# cat /sys/block/sda/queue/discard_granularity
2048
# cat /sys/block/dm-1/queue/discard_granularity
1024
# blkdiscard -o 1024 -l 16384 /dev/mapper/integrity-test
blkdiscard: BLKDISCARD: /dev/mapper/integrity-test ioctl failed: Input/output 
error
# echo $?
1

perf trace:
      blkdiscard   12191 [000] 257234.995337:    block:block_bio_queue: 253,1 
DS 0 + 2 [blkdiscard]
 kworker/0:1-eve   11763 [000] 257235.046620:    block:block_bio_queue: 8,0 DS 
16504 + 2 [kworker/0:1]
 kworker/0:1-eve   11763 [000] 257235.046623: block:block_bio_complete: 8,0 DS 
16504 + 2 [-5]
 kworker/0:1-eve   11763 [000] 257235.046629: block:block_bio_complete: 253,1 
DS 0 + 2 [-5]

-Ben


Reply via email to