On Thu, Apr 13, 2017 at 04:22:22PM +0000, Bart Van Assche wrote: > On Fri, 2017-04-14 at 00:06 +0800, Ming Lei wrote: > > But if one rq starts with non-aligned buffer(the 1st bvec's > > bv_offset isn't zero) and if we allow to merge, it is quite > > difficult to respect sg gap limit, especially the segment > > can't be at maximum segment size, otherwise the segment > > ends in unaligned virt boundary. This patch trys to avoid the > > issue by not allowing to merge if the req starts with non-aligned > > buffer. > > Hello Ming, > > Why is it considered difficult to detect whether or not a gap exists if > the offset of the first bio is non-zero? Please note that a thoroughly > tested version of gap detection code that supports non-zero offsets for > the first element is already upstream. See also ib_map_mr_sg() and > ib_sg_to_pages() in drivers/infiniband/core/verbs.c. I don't know infiniband much, but from the code, it is just about sg, and looks not same with block's sg gap limit. The sg gap limit in block layer actually means: - except for last segment, every segment has to end in aligned virt boundary - from the 2nd segment, offset of the segment has to be zero But we don't store main segment info(start, size) in bio/req, all the segments are basically computed in the flight, so it isn't easy to check/handle sg gap. Also IMO segment handling of block layer is quite fragile, and hope multi-page bvec can improve the case much. We relax check for sg gap for allowing merging tons of small bios, if these bios are physically contiguous. But if offset of the 1st bio in the merged req isn't zero, current segment compution in __blk_segment_map_sg() doesn't consider sg gap, so one segment may ends in unaligned virt boundary. Given it is late in v4.11 cycle, this patch doesn't want to touch __blk_segment_map_sg() for avoiding regression risk, instead just changing bio_will_gap() for avoding the case with minimized risk, because the change is quite simple. Thanks, Ming