Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: cleanup and fix batch completion adding conditions

The conditions for whether or not a request is allowed adding to a
completion batch are a bit hard to read, and they also have a few
issues. One is that ioerror may indeed be a random value on passthrough,
and it's being checked unconditionally of whether or not the given
request is a passthrough request or not.

Rewrite the conditions to be separate for easier reading, and only check
ioerror for non-passthrough requests. This fixes an issue with bio
unmapping on passthrough, where it fails getting added to a batch. This
both leads to suboptimal performance, and may trigger a potential
schedule-under-atomic condition for polled passthrough IO.

Fixes: f794f3351f26 ("block: add support for blk_mq_end_request_batch()")
Link: https://lore.kernel.org/r/20575f0a-656e-4bb3-9d82-dec6c7e3a35c@kernel.dk
Signed-off-by: Jens Axboe <axboe@kernel.dk>

+14 -4
+14 -4
include/linux/blk-mq.h
··· 861 861 void (*complete)(struct io_comp_batch *)) 862 862 { 863 863 /* 864 - * blk_mq_end_request_batch() can't end request allocated from 865 - * sched tags 864 + * Check various conditions that exclude batch processing: 865 + * 1) No batch container 866 + * 2) Has scheduler data attached 867 + * 3) Not a passthrough request and end_io set 868 + * 4) Not a passthrough request and an ioerror 866 869 */ 867 - if (!iob || (req->rq_flags & RQF_SCHED_TAGS) || ioerror || 868 - (req->end_io && !blk_rq_is_passthrough(req))) 870 + if (!iob) 869 871 return false; 872 + if (req->rq_flags & RQF_SCHED_TAGS) 873 + return false; 874 + if (!blk_rq_is_passthrough(req)) { 875 + if (req->end_io) 876 + return false; 877 + if (ioerror < 0) 878 + return false; 879 + } 870 880 871 881 if (!iob->complete) 872 882 iob->complete = complete;