Re: [PATCH] block: fix bio splitting on max sectors

From: Linus Torvalds
Date: Fri Jan 22 2016 - 13:44:06 EST


On Fri, Jan 22, 2016 at 10:29 AM, Ming Lei <tom.leiming@xxxxxxxxx> wrote:
>
> This patch fixes the issue by making the max io size aligned
> to logical block size.

Looks better, thanks.

I'd suggest also moving the "max_sectors" variable into the
bio_for_each_segment() loop too just to keep variables with minimal
scope, but at least this is fairly legible.

Also:

> +static inline unsigned get_max_io_size(struct request_queue *q,
> + struct bio *bio)
> +{
> + unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector);
> + unsigned mask = ~(queue_logical_block_size(q) - 1);
> +
> + /* aligned to logical block size */
> + sectors = ((sectors << 9) & mask) >> 9;

this could be written as

unsigned mask = queue_logical_block_size(q) - 1;

sectors = sectors & ~(mask >> 9);

avoiding the extra shift. That also avoids the possible overflow that
that extra left-shift introduces. Hmm?

Linus