On 7/26/23 09:57, Bart Van Assche wrote: > Measurements have shown that limiting the queue depth to one for zoned > writes has a significant negative performance impact on zoned UFS devices. > Hence this patch that disables zone locking by the mq-deadline scheduler > if zoned writes are submitted in order and if the storage controller > preserves the command order. This patch is based on the following > assumptions: if zoned writes are submitted in order and if the storage... -> if the storage controller preserves... > - It happens infrequently that zoned write requests are reordered by the > block layer. > - The I/O priority of all write requests is the same per zone. > - Either no I/O scheduler is used or an I/O scheduler is used that > submits write requests per zone in LBA order. > > Cc: Christoph Hellwig <hch@xxxxxx> > Cc: Damien Le Moal <damien.lemoal@xxxxxxxxxxxxxxxxxx> Please use dlemoal@xxxxxxxxxx > Cc: Ming Lei <ming.lei@xxxxxxxxxx> > Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx> > --- > block/mq-deadline.c | 28 ++++++++++++++++++++++------ > 1 file changed, 22 insertions(+), 6 deletions(-) > > diff --git a/block/mq-deadline.c b/block/mq-deadline.c > index 02a916ba62ee..ce5b5048935e 100644 > --- a/block/mq-deadline.c > +++ b/block/mq-deadline.c > @@ -338,6 +338,18 @@ static struct request *deadline_skip_seq_writes(struct deadline_data *dd, > return rq; > } > > +/* > + * Use write locking if either QUEUE_FLAG_NO_ZONE_WRITE_LOCK or > + * REQ_NO_ZONE_WRITE_LOCK has not been set. Not using zone write locking is > + * only safe if the submitter allocates and submit requests in LBA order per > + * zone and if the block driver preserves the request order. > + */ > +static bool dd_use_write_locking(struct request *rq) > +{ > + return !blk_queue_no_zone_write_lock(rq->q) || > + !(rq->cmd_flags & REQ_NO_ZONE_WRITE_LOCK); > +} > + > /* > * For the specified data direction, return the next request to > * dispatch using arrival ordered lists. > @@ -353,7 +365,8 @@ deadline_fifo_request(struct deadline_data *dd, struct dd_per_prio *per_prio, > return NULL; > > rq = rq_entry_fifo(per_prio->fifo_list[data_dir].next); > - if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q)) > + if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q) || > + !dd_use_write_locking(rq)) The test for !blk_queue_is_zoned(rq->q) can be moved inside dd_use_write_locking() I think. That will avoid repeating it again below. > return rq; > > /* > @@ -398,7 +411,8 @@ deadline_next_request(struct deadline_data *dd, struct dd_per_prio *per_prio, > if (!rq) > return NULL; > > - if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q)) > + if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q) || > + !dd_use_write_locking(rq)) > return rq; > > /* > @@ -526,8 +540,9 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd, > } > > /* > - * For a zoned block device, if we only have writes queued and none of > - * them can be dispatched, rq will be NULL. > + * For a zoned block device that requires write serialization, if we > + * only have writes queued and none of them can be dispatched, rq will > + * be NULL. > */ > if (!rq) > return NULL; > @@ -552,7 +567,8 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd, > /* > * If the request needs its target zone locked, do it. > */ > - blk_req_zone_write_lock(rq); > + if (dd_use_write_locking(rq)) > + blk_req_zone_write_lock(rq); > rq->rq_flags |= RQF_STARTED; > return rq; > } > @@ -933,7 +949,7 @@ static void dd_finish_request(struct request *rq) > > atomic_inc(&per_prio->stats.completed); > > - if (blk_queue_is_zoned(q)) { > + if (blk_queue_is_zoned(rq->q) && dd_use_write_locking(rq)) { > unsigned long flags; > > spin_lock_irqsave(&dd->zone_lock, flags); -- Damien Le Moal Western Digital Research