From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bart Van Assche Subject: [PATCH 1/2] block: Avoid invoking blk_run_queue() recursively Date: Fri, 22 Feb 2013 11:46:14 +0100 Message-ID: <51274C76.8080007@acm.org> References: <51274C2F.6070500@acm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <51274C2F.6070500@acm.org> Sender: linux-scsi-owner@vger.kernel.org To: device-mapper development Cc: linux-scsi , Alasdair G Kergon , Jens Axboe , Mike Snitzer , Tejun Heo , James Bottomley List-Id: dm-devel.ids Some block drivers, e.g. dm and SCSI, need to trigger a queue run from inside functions that may be invoked by their request_fn() implementation. Make sure that invoking blk_run_queue() instead of blk_run_queue_async() from such functions does not trigger recursion. Making blk_run_queue() skip queue processing when invoked recursively is safe because the only two affected request_fn() implementations (dm and SCSI) guarantee that the request queue will be reexamined sooner or later before returning from their request_fn() implementation. Signed-off-by: Bart Van Assche Cc: Jens Axboe Cc: Tejun Heo Cc: James Bottomley Cc: Alasdair G Kergon Cc: Mike Snitzer Cc: --- block/blk-core.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index c973249..cf26e3a 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -304,19 +304,24 @@ EXPORT_SYMBOL(blk_sync_queue); * This variant runs the queue whether or not the queue has been * stopped. Must be called with the queue lock held and interrupts * disabled. See also @blk_run_queue. + * + * Note: + * Request handling functions are allowed to invoke __blk_run_queue() or + * blk_run_queue() directly or indirectly. This will not result in a + * recursive call of the request handler. However, such request handling + * functions must, before they return, either reexamine the request queue + * or invoke blk_delay_queue() to avoid that queue processing stops. + * + * Some request handler implementations, e.g. scsi_request_fn() and + * dm_request_fn(), unlock the queue lock internally. Returning immediately + * if q->request_fn_active > 0 avoids that for the same queue multiple + * threads execute the request handling function concurrently. */ inline void __blk_run_queue_uncond(struct request_queue *q) { - if (unlikely(blk_queue_dead(q))) + if (unlikely(blk_queue_dead(q) || q->request_fn_active)) return; - /* - * Some request_fn implementations, e.g. scsi_request_fn(), unlock - * the queue lock internally. As a result multiple threads may be - * running such a request function concurrently. Keep track of the - * number of active request_fn invocations such that blk_drain_queue() - * can wait until all these request_fn calls have finished. - */ q->request_fn_active++; q->request_fn(q); q->request_fn_active--; -- 1.7.10.4