On 2020/7/14 00:47, Martin K. Petersen wrote: > > Hi Coly! > >> This patch improves discard bio split for address and size alignment >> in __blkdev_issue_discard(). The aligned discard bio may help >> underlying device controller to perform better discard and internal >> garbage collection, and avoid unnecessary internal fragment. > Hi Martin, > If the aim is to guarantee that all discard requests, except for head > and tail, are aligned multiples of the discard_granularity, you also > need to take the discard_alignment queue limit and the partition offset > into consideration. > The discard_granularity was considered and my though is, discard_alignment normally is multiples of discard granularity, if the discard bio bi_sector and bi_size are aligned to discard granularity, when underlying driver splits its discard bio by discard_alignment, the split bio bi_sector and bi_size can still be aligned to discard granularity. Another reason I don't handle discard_alignment alignment in __blkdev_issue_discard() is performance. Handling discard_alignment bio split in driver's split loop may call blk_next_bio() much less in __blkdev_issue_discard(), and be more friendly for memory and cache footprint. For the partition offset, my original idea was to suggest the partition or dm target starts on offset 2048 sectors. But your opinion sound better, if considering partition or target offset maybe users misconfigured the partition offset may also gain the benefit of discard alignment. Let me try to improve a v3 patch to handle the partition offset too. Thanks for the cool idea :-) Coly Li