block: optimize flush for non-queueable flush drive
Subsystems (2)
v2 cover block: optimize flush for non-queueable flush drive
Flush request isn't queueable. When it's running, other request can't. We can optimize flush performance according to this knowledge In my test, I got about 20% performance boost.
PATCH v2 1/3 block: add a non-queueable flush flag
flush request isn't queueable in some drives. Add a flag to let driver notify block layer about this. We can optimize flush performance with the knowledge.
--- include/linux/blkdev.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/linux/blkdev.h +11 -0
@@ -364,6 +364,7 @@ struct request_queue* for flush operations */ unsigned int flush_flags; + unsigned int flush_not_queueable:1; unsigned int flush_pending_idx:1; unsigned int flush_running_idx:1;unsigned long flush_pending_since;
@@ -549,6 +550,16 @@ static inline void blk_clear_queue_full(queue_flag_clear (QUEUE_FLAG_ASYNCFULL , q); } +static inline void blk_set_queue_flush_queueable (struct request_queue *q, +bool queueable) +{ + q->flush_not_queueable = !queueable; +} + +static inline bool blk_queue_flush_queueable (struct request_queue *q) +{ +return !q->flush_not_queueable; +}/* * mergeable request must not have _NOMERGE or _BARRIER bit set, nor may
PATCH v2 3/3 SATA: enable non-queueable flush flag
In reply to [email protected]Enable non-queueable flush flag for SATA.
--- drivers/ata/libata-scsi.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/ata/libata-scsi.c +2 -0
@@ -3424,7 +3424,9 @@ void ata_scsi_scan_host(struct ata_port sdev =__scsi_add_device (ap->scsi_host, channel, id,0 ,NULL );if (!IS_ERR (sdev)) { +struct request_queue *q = sdev->request_queue; dev->sdev = sdev; +blk_set_queue_flush_queueable (q, false);scsi_device_put (sdev); }else { dev->sdev =NULL ;
PATCH v2 2/3 block: hold queue if flush is running for non-queueable flush drive
In reply to [email protected]In some drives, flush requests are non-queueable. When flush request is running, normal read/write requests can't run. If block layer dispatches such request, driver can't handle it and requeue it.
Tejun suggested we can hold the queue when flush is running. This can avoid unnecessary requeue.
Also this can improve performance. Say we have requests f1, w1, f2 (f is flush request, and w is write request). When f1 is running, queue will be hold, so w1 will not be added to queue list. Just after f1 is finished, f2 will be dispatched. Since f1 already flushs cache out, f2 can be finished very quickly. In my test, the queue holding completely solves a regression introduced by commit 53d63e6b0dfb9588, which is about 20% regression running a sysbench fileio workload.
--- block/blk-flush.c | 3 +++ block/blk.h | 12 +++++++++++- include/linux/blkdev.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-)
block/blk-flush.c +3 -0
@@ -199,6 +199,9 @@ static void flush_end_io(struct requestBUG_ON (q->flush_pending_idx == q->flush_running_idx); + queued |= q->flush_queue_delayed; + q->flush_queue_delayed =0 ; +/* account completion of the flush request */ q->flush_running_idx ^=1 ;elv_completed_request (q, flush_rq);
include/linux/blkdev.h +1 -0
@@ -365,6 +365,7 @@ struct request_queue*/ unsigned int flush_flags; unsigned int flush_not_queueable:1; + unsigned int flush_queue_delayed:1; unsigned int flush_pending_idx:1; unsigned int flush_running_idx:1;unsigned long flush_pending_since;
block/blk.h +11 -1
@@ -61,7 +61,17 @@ static inline struct request *__elv_next rq =list_entry_rq (q->queue_head.next);return rq; } - +/* +* Flush request is running and flush request isn't queeueable +* in the drive, we can hold the queue till flush request is +* finished. Even we don't do this, driver can't dispatch next +* requests and will requeue them. +*/ +if (q->flush_pending_idx != q->flush_running_idx && + !blk_queue_flush_queueable (q)) { + q->flush_queue_delayed =1 ; +return NULL ; + }if (!q->elevator->ops->elevator_dispatch_fn (q,0 ))return NULL ; }
Re: [patch v2 3/3] SATA: enable non-queueable flush flag
In reply to [email protected]Quoted 12 lines · On Wed, May 04, 2011 at 04:17:28PM +0800, [email protected] wrote:
Enable non-queueable flush flag for SATA.
Signed-off-by Shaohua Li <[email protected]>--- drivers/ata/libata-scsi.c | 2 ++ 1 file changed, 2 insertions(+)Index:
linux/drivers/ata/libata-scsi.c
===================================================================
drivers/ata/libata-scsi.c void ata_scsi_scan_host(struct ata_port · line 3432
Quoted 9 lines
drivers/ata/libata-scsi.c +2
-0@@ -3424,7 +3424,9 @@ void ata_scsi_scan_host(struct ata_port sdev =__scsi_add_device (ap->scsi_host, channel, id,0 ,NULL );if (!IS_ERR (sdev)) { +struct request_queue *q = sdev->request_queue; dev->sdev = sdev; +blk_set_queue_flush_queueable (q, false);scsi_device_put (sdev); }else { dev->sdev =NULL ;
Isn't ata_scsi_dev_config() better place for this?
Thakns.
Signature · 1 line
tejun
Re: [patch v2 1/3] block: add a non-queueable flush flag
In reply to [email protected]Hello,
Quoted 25 lines · On Wed, May 04, 2011 at 04:17:26PM +0800, [email protected] wrote:
flush request isn't queueable in some drives. Add a flag to let driver notify block layer about this. We can optimize flush performance with the knowledge.
Signed-off-by Shaohua Li <[email protected]>--- include/linux/blkdev.h | 11 +++++++++++ 1 file changed, 11 insertions(+)Index:
linux/include/linux/blkdev.h
===================================================================include/linux/blkdev.h +1
-0@@ -364,6 +364,7 @@ struct request_queue* for flush operations */ unsigned int flush_flags; + unsigned int flush_not_queueable:1; unsigned int flush_pending_idx:1; unsigned int flush_running_idx:1;unsigned long flush_pending_since;@@ -549,6 +550,16 @@ static inline void blk_clear_queue_full(queue_flag_clear (QUEUE_FLAG_ASYNCFULL , q); }
include/linux/blkdev.h static inline void blk_clear_queue_full( · line 562
Quoted 10 lines
include/linux/blkdev.h +10
-0+static inline void blk_set_queue_flush_queueable (struct request_queue *q, +bool queueable) +{ + q->flush_not_queueable = !queueable; +} + +static inline bool blk_queue_flush_queueable (struct request_queue *q) +{ +return !q->flush_not_queueable; +}
In the block layer, these setters live in block/blk-settings.c and usually don't have _set in their names.
Also, negation in the interface is slightly bothering but I can't think of better name meaning !queueable either, so unless someone can come up with better name, it should do, I think.
Thank you.
Signature · 1 line
tejun
Re: [patch v2 2/3] block: hold queue if flush is running for non-queueable flush drive
In reply to [email protected]Hello,
Quoted 13 lines · On Wed, May 04, 2011 at 04:17:27PM +0800, [email protected] wrote:
In some drives, flush requests are non-queueable. When flush request is running, normal read/write requests can't run. If block layer dispatches such request, driver can't handle it and requeue it.
Tejun suggested we can hold the queue when flush is running. This can avoid unnecessary requeue.
Also this can improve performance. Say we have requests f1, w1, f2 (f is flush request, and w is write request). When f1 is running, queue will be hold, so w1 will not be added to queue list. Just after f1 is finished, f2 will be dispatched. Since f1 already flushs cache out, f2 can be finished very quickly. In my test, the queue holding completely solves a regression introduced by commit53d63e6b0dfb9588, which is about 20% regression running a sysbench fileio workload.
Quoted 1 line
Signed-off-by Shaohua Li <[email protected]>
It looks good to me now, but some nitpicks.
Quoted 5 lines
Index:
linux/block/blk-flush.c
===================================================================
block/blk-flush.c static void flush_end_io(struct request · line 207
Quoted 9 lines
block/blk-flush.c +3
-0@@ -199,6 +199,9 @@ static void flush_end_io(struct requestBUG_ON (q->flush_pending_idx == q->flush_running_idx); + queued |= q->flush_queue_delayed; + q->flush_queue_delayed =0 ; +/* account completion of the flush request */ q->flush_running_idx ^=1 ;elv_completed_request (q, flush_rq);
Can you please do if (queued || q->flush_queue_delayed) instead of setting queued? And please also update the comment above the if statement so that it explains the flush_queue_delayed case too.
Quoted 5 lines
Index:
linux/block/blk.h
===================================================================
block/blk.h static inline struct request *__elv_next · line 69
Quoted 10 lines
block/blk.h +6
-1@@ -61,7 +61,17 @@ static inline struct request *__elv_next rq =list_entry_rq (q->queue_head.next);return rq; } - +/* +* Flush request is running and flush request isn't queeueable +* in the drive, we can hold the queue till flush request is +* finished. Even we don't do this, driver can't dispatch next +* requests and will requeue them. +*/
Please explain the f1, w1, f2 case here as that's the biggest reason this optimization is implemented and also explain the use of flush_queue_delayed (just explain briefly and refer to flush_end_io()).
Thank you.
Signature · 1 line
tejun
Re: [patch v2 3/3] SATA: enable non-queueable flush flag
In reply to Tejun HeoQuoted 13 lines · Tejun Heo
drivers/ata/libata-scsi.c void ata_scsi_scan_host(struct ata_port · line 3432
Quoted 10 lines · On Wed, May 04, 2011 at 04:17:28PM +0800, [email protected] wrote:
drivers/ata/libata-scsi.c +2
-0@@ -3424,7 +3424,9 @@ void ata_scsi_scan_host(struct ata_port sdev =__scsi_add_device (ap->scsi_host, channel, id,0 ,NULL );if (!IS_ERR (sdev)) { +struct request_queue *q = sdev->request_queue; dev->sdev = sdev; +blk_set_queue_flush_queueable (q, false);scsi_device_put (sdev); }else { dev->sdev =NULL ;Isn't
ata_scsi_dev_config()better place for this?
Yes :)
Re: [patch v2 2/3] block: hold queue if flush is running for non-queueable flush drive
In reply to [email protected]Hello.
Quoted 11 lines · On 04-05-2011 12:17, [email protected] wrote:
In some drives, flush requests are non-queueable. When flush request is running, normal read/write requests can't run. If block layer dispatches such request, driver can't handle it and requeue it.
Tejun suggested we can hold the queue when flush is running. This can avoid unnecessary requeue.
Also this can improve performance. Say we have requests f1, w1, f2 (f is flush request, and w is write request). When f1 is running, queue will be hold, so w1 will not be added to queue list. Just after f1 is finished, f2 will be dispatched. Since f1 already flushs cache out, f2 can be finished very quickly. In my test, the queue holding completely solves a regression introduced by commit53d63e6b0dfb9588, which is about 20% regression running a sysbench fileio
Please specify that commit's summary -- for human readers. The ID is only
immediately usable to gitweb.
Quoted 3 lines
workload.
Signed-off-by Shaohua Li <[email protected]>
[...]
block/blk.h static inline struct request *__elv_next · line 65
Quoted 11 lines
Index:
linux/block/blk.h
===================================================================block/blk.h +2
-1@@ -61,7 +61,17 @@ static inline struct request *__elv_next rq =list_entry_rq (q->queue_head.next);return rq; } - +/* +* Flush request is running and flush request isn't queeueable
Queueable.
WBR, Sergei