> 2021年06月22日 14:55,Christoph Hellwig <hch@xxxxxx> 写道: > > On Wed, Jun 09, 2021 at 08:45:56AM +0800, Ming Lei wrote: >> diff --git a/block/blk-merge.c b/block/blk-merge.c >> index bcdff1879c34..65210e9a8efa 100644 >> --- a/block/blk-merge.c >> +++ b/block/blk-merge.c >> @@ -724,10 +724,10 @@ static inline bool blk_discard_mergable(struct request *req) >> static enum elv_merge blk_try_req_merge(struct request *req, >> struct request *next) >> { >> - if (blk_discard_mergable(req)) >> - return ELEVATOR_DISCARD_MERGE; >> - else if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next)) >> + if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next)) >> return ELEVATOR_BACK_MERGE; > > Oh well, this breaks my previous suggestions. > >> + struct req_discard_range r; >> + >> + rq_for_each_discard_range(r, req) { > > ... and I can't say I like this rather complex iterator. > > What is the problem of just fixing the raid code to not submit stupidly > small discard requests instead? Yes, raid code should indeed be fixed. However, the way discard requests are getting merged is not correct. I understand your concern about complex iterator. I believe it is because the difference between discard requests and normal read/write requests. Discard requests are without data and allowed to be non-contiguous, while normal requests, which blk-merge was originally dealing with, are with data buffers and should be contiguous. Actually, correct me if wrong, the current request struct lacks the ability to express non-contiguous bio's. Ming's patch, by introducing the rq_for_each_discard_range iterator, partially enables the request struct to express non-contiguous bio's. Cheers, Miao Wang