From patchwork Fri Aug 23 00:15:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11110255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 247E81813 for ; Fri, 23 Aug 2019 00:15:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F37A023402 for ; Fri, 23 Aug 2019 00:15:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="UW/Fu5AF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727783AbfHWAPb (ORCPT ); Thu, 22 Aug 2019 20:15:31 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:30872 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728224AbfHWAPb (ORCPT ); Thu, 22 Aug 2019 20:15:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566519331; x=1598055331; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=afa1tg1LDkqSoP1c7eXH5X/bvtdyWo7csNQ4j7EqvZo=; b=UW/Fu5AFM/l4Qw5ww12JgLyhSUcMfytgi+4TJUmwdipY9Iuf2roYBOe5 vfMLlkLf7a1MriFNl2pKt1ot8EReJosof3074bJZ+fbjHgE63fRZzpRnt gBo5QKa8lC2ZSO4BnOh+uBIPQjFSlu8tcK5ISqT9ZeViW49ow3NuNl5dA fLeFIFji6T2xORJxWP0rfMwX+ZUjwiHy3NRFh9ziilKIWjyxqLuQCdLR5 IRVw0n4hRZw48Fl73ueUoss4XN9dUoMMmtPpF34ZcskmM+od1BxB1msFo clV9u6fVRqU0w3gtv+7tU6JfJAurPYOkt7NJupaDYnrnHt9OLT4lPo345 Q==; IronPort-SDR: EIQYCN8HXo1s2f/xMykw7mFAHjvN6hOq0XOE0WFzMfDoX5sRt9JYyX9DLRGuMFMkvI115CH0dW Meq1ltr7GawhBQkWcB24wEq/hqhSmd3HZ55b0EjZtlBMElSGd47FJav8t/T5NwYmPYoMCDa9kv ACb4N0YMkuDkQ02L3zV+ccVWD4On97JjNhl+z261jVRExECFQXKDTPSheWefukoo88QD/QbxfE Zv2Glpd9LwLCVXinezVCO/k/PFdmePpJQus2hLuTXfO4UTMVR7qgPzztVHeUlnIRD5rqpFxm/W boE= X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="121063664" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Aug 2019 08:15:30 +0800 IronPort-SDR: e/7RDop+a9nVGZ8JYjaGenwXDB7Szd037//NtnKk21Dq2Wyk3wPqMmkzw/NaoHh1srta2JruNW KM2tqKvQ4aJZHwbiE5R7gUJ/liA3/wml/owQNZbDNBOVk2OTEllIwQhmhdH/vZRZEWc1E9U/6Z RyprIXgefKNYW2GbM2EIqchshHhy/+CEQ0VGbMe2SXlTeGtsS+Hv1V2rsc3Erjj5wyXWtFxf/l QrHFsuOQUHgq9Bupagwpvl1+IW4RaSVoNZ50E17fC+zZ1/32qDDTBYXWF04Tj6AM1nTVV+kbrC X7nYOca31ta1TxgvfY/34Rko Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 17:12:49 -0700 IronPort-SDR: LXUp74Oo553PSa8NWjYlE7z8x7igdHo2eV8evB2gkLF+roK5fzBbT31GqzoJ3q4XHnKizZuDfx EPUAv3sQH3YduCC7zFS6ol8/iRyOC+F/ZD49FHg2/amHPIQS0V6LHWyuQ3H8seCcmzTJ6uplLw PudSOy1zvD9HJvKUY2U5aLiPdc5/jsYfWXeV03DA8ma85UaWZHQ4eWp4GHV64jkBHIdOS3O5WS jGHhTwPOpdPJ931Abn4onkgXRkWx0KdRTgDq5WO2mcok3SXuSN2sBSScXzlY19VlCsaJgP6Ppr 0ZY= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Aug 2019 17:15:30 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 1/7] block: Cleanup elevator_init_mq() use Date: Fri, 23 Aug 2019 09:15:22 +0900 Message-Id: <20190823001528.5673-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823001528.5673-1-damien.lemoal@wdc.com> References: <20190823001528.5673-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of checking a queue tag_set BLK_MQ_F_NO_SCHED flag before calling elevator_init_mq() to make sure that the queue supports IO scheduling, use the elevator.c function elv_support_iosched() in elevator_init_mq(). This does not introduce any functional change but ensure that elevator_init_mq() does the right thing based on the queue settings. Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- block/blk-mq.c | 8 +++----- block/elevator.c | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 509f69fdfcf2..556c774a0f0d 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2908,11 +2908,9 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, blk_mq_add_queue_tag_set(set, q); blk_mq_map_swqueue(q); - if (!(set->flags & BLK_MQ_F_NO_SCHED)) { - ret = elevator_init_mq(q); - if (ret) - goto err_tag_set; - } + ret = elevator_init_mq(q); + if (ret) + goto err_tag_set; return q; diff --git a/block/elevator.c b/block/elevator.c index 2f17d66d0e61..1ed2710f1950 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -594,16 +594,26 @@ int elevator_switch_mq(struct request_queue *q, return ret; } +static inline bool elv_support_iosched(struct request_queue *q) +{ + if (q->tag_set && (q->tag_set->flags & BLK_MQ_F_NO_SCHED)) + return false; + return true; +} + /* - * For blk-mq devices, we default to using mq-deadline, if available, for single - * queue devices. If deadline isn't available OR we have multiple queues, - * default to "none". + * For blk-mq devices supporting IO scheduling, we default to using mq-deadline, + * if available, for single queue devices. If deadline isn't available OR we + * have multiple queues, default to "none". */ int elevator_init_mq(struct request_queue *q) { struct elevator_type *e; int err = 0; + if (!elv_support_iosched(q)) + return 0; + if (q->nr_hw_queues != 1) return 0; @@ -685,13 +695,6 @@ static int __elevator_change(struct request_queue *q, const char *name) return elevator_switch(q, e); } -static inline bool elv_support_iosched(struct request_queue *q) -{ - if (q->tag_set && (q->tag_set->flags & BLK_MQ_F_NO_SCHED)) - return false; - return true; -} - ssize_t elv_iosched_store(struct request_queue *q, const char *name, size_t count) { From patchwork Fri Aug 23 00:15:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11110259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A8551813 for ; Fri, 23 Aug 2019 00:15:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6689523402 for ; Fri, 23 Aug 2019 00:15:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="FQnInb4U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728263AbfHWAPc (ORCPT ); Thu, 22 Aug 2019 20:15:32 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:30872 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728262AbfHWAPc (ORCPT ); Thu, 22 Aug 2019 20:15:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566519331; x=1598055331; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=2VOOI9y5LEc9gNFG0XBbhG4PU+RZhuVcJ68XilDuZH8=; b=FQnInb4UethKEcKqW6fFEhQ2cHbNvCWR6muWlDsWD1jV2ZRQfKVUTBaz NWzpYvQGUOIiNXVFIgfKp4NM/CAslH4EVln0Xrq+lVEvJLOtBduREhSza lDigH0zLIkjWvCcE5ysqmOx71FLMcmXYIzdqw4mlMJJ7+X25JEKg+kLK7 EpFkYdnIWsbUtw9Le9ekWjZEcH/6KMUBMtwQYedNfvrSulgxl2le02m77 Cr+fMNgsa/2Rt6wL+y5dq8LzXiF5LAD1VQvVcvcQIo2oAIsk9D3cGyRjd gv2sOepPlV2C26jGkBVMl9n/cNzUYyLQQiYFD8kN+F/mF2pHlw0rbBKcx g==; IronPort-SDR: +H+DicjrgZCso2ZMERZTQL8mz3LDTqLwsf7GMRkuZb12sDfkngumVWeP20rYOQGIjq6xvu+0iD myErxpPqbcE1CeEw4mffAUQxyLboXUZpBFV5aXssHQHtPjfj3OFxpg5Y2mzYhTFQ7JCT2qpS4y 4JYwcvXeizSh/d9jfdj1AyKATxumGXZykSay4XJneT+wwi6lGEU/FSWEEtfP4idGsh4RQqZgLh kTvU+AHcWMIJeI1NFqIHfFBHFT7uDpwSMeyw/kUemRv2dugT4IMILOFr++GFcChPwK7aHvlAhS j74= X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="121063665" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Aug 2019 08:15:31 +0800 IronPort-SDR: VlikhWZdbDpAr0pgUMS8vg8wRYsdwVMfWhMgARRcSjsIHTPTk8aSaS4Oy+t4PXTpYLnLlTUZRe 7+okyaLiCrXPXEdwHjHBVMv/YUuIl5SZfgv7LU4F10Iv0U2aW+E/CcjAM2J58i83RBi+S5Joci G4c5CZmjnT/wg52kjaxYB4MWRohtK7xMR3/z8TbqhZhjma5UpmsyiIfdXRRHEq1Na76QkdRWWe zokquc8zHakrbvzJUuWbRHpaVmTVch6WZgCpzmNwVdq295TFhYq65QDBsEQ/FGkH+DO2rftg3t dp30bmdc3+zMIvZK60QxzrXl Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 17:12:50 -0700 IronPort-SDR: sBfg77FSBLsBaM3Xbw4KVf8zevcSNSrk9oFl/xiNScJuxvGHVNRJQYFjVEc2pv7JNCzpUekViu Ft2B80ktff0qYj4u0yKM5xzPsMg9hHcWALxypRwpY5IIzky2fJll63EZoUCxE7RHa3Q4wbzG4U 9vxw6Kb8bGf122VJ86Nu1IsYapeIGdfwOCE/EuNx/otNGLQ+LBvH9y9UHSFY45rOnPxahb4beL MlgNmmIrJrZTVNTIFQ7FpqKK9OUArheToRG5h1fL3PnUimbHqpXJo31eKTzJmzTE5Scjk8orpJ ioA= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Aug 2019 17:15:31 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 2/7] block: Change elevator_init_mq() to always succeed Date: Fri, 23 Aug 2019 09:15:23 +0900 Message-Id: <20190823001528.5673-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823001528.5673-1-damien.lemoal@wdc.com> References: <20190823001528.5673-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org If the default elevator chosen is mq-deadline, elevator_init_mq() may return an error if the mq-deadline initialization fails, leading to blk_mq_init_allocated_queue() returning an error, which in turn will cause the block device initialization to fail. Instead of taking such extreme measure, handle mq-deadline initialization failures in the same manner as if mq-deadline being not available (no module to load), that is, default to the "none" scheduler. With this change, elevator_init_mq() return type can be changed to void. Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- block/blk-mq.c | 8 +------- block/blk.h | 2 +- block/elevator.c | 17 ++++++++++------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 556c774a0f0d..274e168c8535 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2846,8 +2846,6 @@ static unsigned int nr_hw_queues(struct blk_mq_tag_set *set) struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, struct request_queue *q) { - int ret = -ENOMEM; - /* mark the queue as mq asap */ q->mq_ops = set->ops; @@ -2908,14 +2906,10 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, blk_mq_add_queue_tag_set(set, q); blk_mq_map_swqueue(q); - ret = elevator_init_mq(q); - if (ret) - goto err_tag_set; + elevator_init_mq(q); return q; -err_tag_set: - blk_mq_del_queue_tag_set(q); err_hctxs: kfree(q->queue_hw_ctx); q->nr_hw_queues = 0; diff --git a/block/blk.h b/block/blk.h index de6b2e146d6e..ddb292bb6caf 100644 --- a/block/blk.h +++ b/block/blk.h @@ -184,7 +184,7 @@ void blk_account_io_done(struct request *req, u64 now); void blk_insert_flush(struct request *rq); -int elevator_init_mq(struct request_queue *q); +void elevator_init_mq(struct request_queue *q); int elevator_switch_mq(struct request_queue *q, struct elevator_type *new_e); void __elevator_exit(struct request_queue *, struct elevator_queue *); diff --git a/block/elevator.c b/block/elevator.c index 1ed2710f1950..7fff06751633 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -603,19 +603,19 @@ static inline bool elv_support_iosched(struct request_queue *q) /* * For blk-mq devices supporting IO scheduling, we default to using mq-deadline, - * if available, for single queue devices. If deadline isn't available OR we - * have multiple queues, default to "none". + * if available, for single queue devices. If deadline isn't available OR + * deadline initialization fails OR we have multiple queues, default to "none". */ -int elevator_init_mq(struct request_queue *q) +void elevator_init_mq(struct request_queue *q) { struct elevator_type *e; int err = 0; if (!elv_support_iosched(q)) - return 0; + return; if (q->nr_hw_queues != 1) - return 0; + return; /* * q->sysfs_lock must be held to provide mutual exclusion between @@ -630,11 +630,14 @@ int elevator_init_mq(struct request_queue *q) goto out_unlock; err = blk_mq_init_sched(q, e); - if (err) + if (err) { + pr_warn("\"%s\" elevator initialization failed, " + "falling back to \"none\"\n", e->elevator_name); elevator_put(e); + } + out_unlock: mutex_unlock(&q->sysfs_lock); - return err; } From patchwork Fri Aug 23 00:15:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11110257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CB6F13A4 for ; Fri, 23 Aug 2019 00:15:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A5DE2173E for ; Fri, 23 Aug 2019 00:15:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Wji5OPkb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728262AbfHWAPc (ORCPT ); Thu, 22 Aug 2019 20:15:32 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:30876 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728224AbfHWAPc (ORCPT ); Thu, 22 Aug 2019 20:15:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566519332; x=1598055332; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=AZXywgRcoKRoM0uXmO6JmAnLjhTdPgMFw+Criebpuyo=; b=Wji5OPkbSO0AzlUODh9jChPiVTwvxv+KtMKJNc8jnUpmn6yhSHgYofFD nFTTXqZDgJ41d8CWokmuEYFsrT/RNlnIoc4Z+2KQdOo6SCKqv8HInSsZv FWow3p9kLs23HptjSCJzPgjiH/TJUs3N/tX/1NcNNFeDFTVmtGZmyHvbo va8zKWNUvdBz44VbKqCocmB+sWwkiy6Glkb0ijzy8Nnr5tIDyEsK4N2mz S8safjnLltPypBMRdPPkXn0HVLLsyFz/xD3HaLMiCoHeZ1UpWnZDcs/2M HvHodYMZjB2j/sS+jBGtm4u8k1iPFqXxPX53GP/FcDVt4VhTb0/ybV/ub A==; IronPort-SDR: ARk1dZoAbUhTQWtzoUfd24XIo8b5GknecReNJKGxVP1o3x1rpzpVFEYm+F94tkxpz6upo8kbHG VADnh8xQ7aeMuHXC3G1n0BrCb441w7EcFlcqxJFEan42+nSzCu3Jm9I2aAgsvlFH75pT8gXaex 7d3yMNZy547fSiOFBMmig3b0Goi4GTDP8FgwM2aOwDTlSThcjPnwOx2E8ukjku8ZHlB6G1qj+Q SxEZIp7ZEC3Kn9DgaMw4cn90m2e90Z/9NHBMGGlcRIyHWY6kaMJc+9dsUbwvDq0eqsLbf2Eyjq luw= X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="121063667" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Aug 2019 08:15:32 +0800 IronPort-SDR: BQYBqIIl0BiPFq4ABMJnmuD7jbPOpoRwN4c8DyiHbLMuTxine+Ef5e9khX9Qm8j0Ia57IvBVHB ath8YgaJS0r+IA0LIwlAw1mVFH3nM5zD5tAJg1P/UUSSVb2K7Sj2E+iHfDHfQCED8IKCjFKmsN +G4mjsiVed048qDnqgzAgW5iOwvZRWFbIB8tCx9be6lOH+JnGx1UjCmAvpFCnP8JDA4S4vn4b/ dtXfP+kdtl3uq+rK0D8Z5lz/W0zpJxMnyslzXY2UdNUt8UexH1a9uqExncxdggIvaVMx4PtZ0D 6ie4w1IEJRrHWqYUoRiRhQxh Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 17:12:51 -0700 IronPort-SDR: MobddehZuMTCSEmguSJzwirGd8SFwojqpS/Uyh8Dkn6Nz5yXIq9zoU4HZtkUJvc01331QITFGl Z76OcrVLj0cYPMr+VF3uUv3Q7g1ER3yAXvA1IdDFLMF8/tr63LtrRlreystqFE3sKBMGf+qCTg VvO0u+WvRcVVFsvlG5jm1VlFiebCAe5NX7jkaR6TcWgQcMGA+r73O/QOmiBPPVpnVEqxFet+JP xw1p/ya5F6rOMNwPhNWK6tHUT9b08nFhO/zMgTYu1e9wytPfd5PUIaW2GZSmcl5coh7C6T4jLi VVA= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Aug 2019 17:15:31 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 3/7] block: Remove sysfs lock from elevator_init_rq() Date: Fri, 23 Aug 2019 09:15:24 +0900 Message-Id: <20190823001528.5673-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823001528.5673-1-damien.lemoal@wdc.com> References: <20190823001528.5673-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Since elevator_init_rq() is called before the device queue is registered in sysfs, there is no possible conflict with elevator_switch(). Remove the unnecessary locking of q->sysfs_lock mutex. Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- block/elevator.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index 7fff06751633..6208ddc334ef 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -617,17 +617,12 @@ void elevator_init_mq(struct request_queue *q) if (q->nr_hw_queues != 1) return; - /* - * q->sysfs_lock must be held to provide mutual exclusion between - * elevator_switch() and here. - */ - mutex_lock(&q->sysfs_lock); if (unlikely(q->elevator)) - goto out_unlock; + return; e = elevator_get(q, "mq-deadline", false); if (!e) - goto out_unlock; + return; err = blk_mq_init_sched(q, e); if (err) { @@ -635,9 +630,6 @@ void elevator_init_mq(struct request_queue *q) "falling back to \"none\"\n", e->elevator_name); elevator_put(e); } - -out_unlock: - mutex_unlock(&q->sysfs_lock); } From patchwork Fri Aug 23 00:15:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11110261 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D031013A4 for ; Fri, 23 Aug 2019 00:15:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A50A523402 for ; Fri, 23 Aug 2019 00:15:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="GRvMu4vT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728282AbfHWAPe (ORCPT ); Thu, 22 Aug 2019 20:15:34 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:30877 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728224AbfHWAPd (ORCPT ); Thu, 22 Aug 2019 20:15:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566519333; x=1598055333; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=xpjoteqg3rDc7BlHZJQG638MpFm6XqRL/OCljAsusB4=; b=GRvMu4vT2vhQwk2CbJIv/bNY8n/Ozezmrp41x9cR78I6UKgn+NEIsJtR JKEpjdfWKG7rYStQYPIg85DTdL2Jy2Id1Mcqib8JQesvfERQpcFErC+ax Se1lmxeQUBUUGHuf9sKw8MnnONtCGZS7gD7dB8ORCI0IP3BlvTbyrqoe+ 7bTj+puNTk8IM50C8TomRALQ0JcNN1vlCijZg63BUhHszX0p0U9/ymIvQ o3D6VOGITFGzqJMPEwRsZo+TUea2zUCOLZUodTaNonDfRltHgp8HiFnX8 UnXCWzLuSxE9/y3PJn83nuSvQTVsdLpDpKNw7aVW2OaYFBkCYiRDGJuFI A==; IronPort-SDR: KNMRoCz4kjZ87KiB9+O3s7/qP96y/ixTNKOz7k5PATFxTNFYc//qDSyKfb0waVUOwOD5NPdj0r xoS4A8LZU+cufo2wLlqC6Nk0hVG+yBtSzhGXOHrz28jvJCXJS+uEjHSNtPEwGCBjS6oVcB1jMs gnfn1ocA0TJ9Qv4Lgi8+XHOWKxKBz25WP2GBnkRnjZJlV1WxWWjpYpgaCulzSzbxljQUrstv0y ilYgaB0OIVc5YNhmKDyIHM8FSJd8TxjSDma+i9aLQXquz/Ku2K/CfZ90Gmei+5gCWF03gxyqMo Bt4= X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="121063668" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Aug 2019 08:15:32 +0800 IronPort-SDR: GIn6QCuSSMUPbBZ8Dk7NHPVyzbK3zwNOeR0npD7KRecCRMWaCwJsHpQ60H8sfoeTjtIDJXIGrn g9+JSkU4Xpv0/KD2ATJ+0JEuX99xG0ykyNbsqaB4V2AOMe6D3Xkty38N8eZLB2K7lk5OJtGiLE gWLFX7zLp1YQYrBDmmZQnvczv17xOatvWhxFkck6apzCZ/UmccdC49/r9gESLqKlMw9qbp5C++ 7CfZjqCmJsVxXP0XkA6E8G2znENbAfP+EZc9q7C1GVMNA9v2TGLWtYKR+KPKsvo2T74iN7SLMz NBut19dcxreMqF+UfMlodPuP Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 17:12:51 -0700 IronPort-SDR: tCR9RB17Vo/gKnSBUdkLW8vSeM5eVCeKWn/cPD/a8LoBQohTQf5PENs3clxJOUuE9F9c4EFku/ s9jp2KtKfEWZQX2qljftwANldJCYtWUQUvZJo3UgZiwbF8OjZ4YId3KRm1LYnAP6sa0gjmVA3v oFsA66FZuCAaA7W3tb81b556uo64Wzq/UdnIy0T3O1o8eis4bepN27ErSIrxPS7xk06JSK3sC/ yZYmZa4Fm21PStL+axY+lcj1dAkazBKMmT9PROjZ0CDLOpMu8NRTKuX1HIMnpB9QAdtIL2Alm2 UCg= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Aug 2019 17:15:32 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 4/7] block: Introduce elevator features Date: Fri, 23 Aug 2019 09:15:25 +0900 Message-Id: <20190823001528.5673-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823001528.5673-1-damien.lemoal@wdc.com> References: <20190823001528.5673-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Introduce the elevator_features bitfield in the elevator_type structure to allow an elevator to advertize special features that it supports. Examples of such features are IO priorities, write hints, and zoned block devices sequential write constraint support (aka zone write locking). The required_elevator_features field is added to the request_queue structure to allow a device driver to specify features that an elevator must support for the correct operation of the device. An example of a typical required elevator feature is zone write locking for zoned block devices. The helper function blk_queue_required_elevator_features() is defined for setting this new new field. With these two new information in place, the elevator functions elevator_match() and elevator_find() are modified to allow a user to set only an elevator with a set of features that satisfies the device requirements. Elevators not matching the device requirements are not listed in the device sysfs queue/scheduler file to prevent their use. The "none" elevator can always be selected as before. Signed-off-by: Damien Le Moal --- block/blk-settings.c | 15 ++++++++++++ block/elevator.c | 49 +++++++++++++++++++++++++++++++--------- include/linux/blkdev.h | 4 ++++ include/linux/elevator.h | 1 + 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index 2c1831207a8f..16471bf18810 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -832,6 +832,21 @@ void blk_queue_write_cache(struct request_queue *q, bool wc, bool fua) } EXPORT_SYMBOL_GPL(blk_queue_write_cache); +/** + * blk_queue_required_elevator_features - Set queue's elevator required features + * @q: the request queue for the device + * @features: Required elevator features OR'ed together + * + * Tell the block layer that the device controlled through @q that the + * queue elevator must support all the features specified by @features. + */ +void blk_queue_required_elevator_features(struct request_queue *q, + unsigned long features) +{ + q->required_elevator_features = features; +} +EXPORT_SYMBOL_GPL(blk_queue_required_elevator_features); + static int __init blk_settings_init(void) { blk_max_low_pfn = max_low_pfn - 1; diff --git a/block/elevator.c b/block/elevator.c index 6208ddc334ef..de11beb32893 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -83,8 +83,26 @@ bool elv_bio_merge_ok(struct request *rq, struct bio *bio) } EXPORT_SYMBOL(elv_bio_merge_ok); -static bool elevator_match(const struct elevator_type *e, const char *name) +static inline bool elv_support_features(unsigned long elv_features, + unsigned long required_features) { + return (required_features & elv_features) == required_features; +} + +/** + * elevator_match - Test an elevator name and features + * @e: Scheduler to test + * @name: Elevator name to test + * @required_features: Features that the elevator must provide + * + * Return true is the elevator @e name matches @name and if @e provides all the + * the feratures spcified by @required_features. + */ +static bool elevator_match(const struct elevator_type *e, const char *name, + unsigned long required_features) +{ + if (!elv_support_features(e->elevator_features, required_features)) + return false; if (!strcmp(e->elevator_name, name)) return true; if (e->elevator_alias && !strcmp(e->elevator_alias, name)) @@ -93,15 +111,21 @@ static bool elevator_match(const struct elevator_type *e, const char *name) return false; } -/* - * Return scheduler with name 'name' +/** + * elevator_find - Find an elevator + * @name: Name of the elevator to find + * @required_features: Features that the elevator must provide + * + * Return the first registered scheduler with name @name and supporting the + * features @required_features and NULL otherwise. */ -static struct elevator_type *elevator_find(const char *name) +static struct elevator_type *elevator_find(const char *name, + unsigned long required_features) { struct elevator_type *e; list_for_each_entry(e, &elv_list, list) { - if (elevator_match(e, name)) + if (elevator_match(e, name, required_features)) return e; } @@ -120,12 +144,12 @@ static struct elevator_type *elevator_get(struct request_queue *q, spin_lock(&elv_list_lock); - e = elevator_find(name); + e = elevator_find(name, q->required_elevator_features); if (!e && try_loading) { spin_unlock(&elv_list_lock); request_module("%s-iosched", name); spin_lock(&elv_list_lock); - e = elevator_find(name); + e = elevator_find(name, q->required_elevator_features); } if (e && !try_module_get(e->elevator_owner)) @@ -526,7 +550,7 @@ int elv_register(struct elevator_type *e) /* register, don't allow duplicate names */ spin_lock(&elv_list_lock); - if (elevator_find(e->elevator_name)) { + if (elevator_find(e->elevator_name, 0)) { spin_unlock(&elv_list_lock); kmem_cache_destroy(e->icq_cache); return -EBUSY; @@ -682,7 +706,8 @@ static int __elevator_change(struct request_queue *q, const char *name) if (!e) return -EINVAL; - if (q->elevator && elevator_match(q->elevator->type, elevator_name)) { + if (q->elevator && + elevator_match(q->elevator->type, elevator_name, 0)) { elevator_put(e); return 0; } @@ -722,11 +747,13 @@ ssize_t elv_iosched_show(struct request_queue *q, char *name) spin_lock(&elv_list_lock); list_for_each_entry(__e, &elv_list, list) { - if (elv && elevator_match(elv, __e->elevator_name)) { + if (elv && elevator_match(elv, __e->elevator_name, 0)) { len += sprintf(name+len, "[%s] ", elv->elevator_name); continue; } - if (elv_support_iosched(q)) + if (elv_support_iosched(q) && + elevator_match(__e, __e->elevator_name, + q->required_elevator_features)) len += sprintf(name+len, "%s ", __e->elevator_name); } spin_unlock(&elv_list_lock); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 4798bb25f1ee..1e173273511e 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -492,6 +492,8 @@ struct request_queue { struct queue_limits limits; + unsigned long required_elevator_features; + #ifdef CONFIG_BLK_DEV_ZONED /* * Zoned block device information for request dispatch control. @@ -1084,6 +1086,8 @@ extern void blk_queue_dma_alignment(struct request_queue *, int); extern void blk_queue_update_dma_alignment(struct request_queue *, int); extern void blk_queue_rq_timeout(struct request_queue *, unsigned int); extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua); +extern void blk_queue_required_elevator_features(struct request_queue *q, + unsigned long features); /* * Number of physical segments as sent to the device. diff --git a/include/linux/elevator.h b/include/linux/elevator.h index 1dd014c9c87b..a99ca9979d71 100644 --- a/include/linux/elevator.h +++ b/include/linux/elevator.h @@ -76,6 +76,7 @@ struct elevator_type struct elv_fs_entry *elevator_attrs; const char *elevator_name; const char *elevator_alias; + const unsigned long elevator_features; struct module *elevator_owner; #ifdef CONFIG_BLK_DEBUG_FS const struct blk_mq_debugfs_attr *queue_debugfs_attrs; From patchwork Fri Aug 23 00:15:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11110263 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 013D313A4 for ; Fri, 23 Aug 2019 00:15:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D595D23402 for ; Fri, 23 Aug 2019 00:15:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="LJ33/fk3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728301AbfHWAPf (ORCPT ); Thu, 22 Aug 2019 20:15:35 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:30877 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728276AbfHWAPe (ORCPT ); Thu, 22 Aug 2019 20:15:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566519334; x=1598055334; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=Q6TmPmMv56etbAvtxMa6qD+NEnfvcD+6MpqN+p1kTrg=; b=LJ33/fk3V3yCcAknkvW6ZWhsZjxpsoFtuOmppLDzqA0U/a/nahgSkV3h XGVAfTFWfw/XDMG12yrrPcoI9P5SZrWz9Yk0Qo5WdZYs1A9t8NQVKZqqx aQ0OCj+7XakSprAft4Ut8PEFrN3ZMJfV9CXA/3C0tLWzM0BJ2ikZUknpL yor692DNL7G9Q2zOBKM9oaDfhnmv3EDggYo7HtHS6BQaTMFR6XfFyzvF9 JtbvXIJye1uSzREE7ThvyHvWbRCQiLUakTRQ3Zs+8WgM1A/YrQ77OGxJt THBJEzNMtiUsBKIoXJ4+9Bkac/P06AB/slRIA+yrkyN3KfMkEZ3OpjeIs g==; IronPort-SDR: C05wipZo27JSYASekDFvGeValGCGsjtBzH+uPuBA5AXGOYgc++Ib4YO0kYXskTZ0f6DETSI7Mb ddmvogUEzXX/VuMzdyBqGlXh7HJ8usqUo1W7qb5wCgwwYuVmRQJ+BN/+PfPKN5ILxpQ9GsdkDn Er6zuYOsfSFYC3fvmROhCnCHpPvEqfslfC5FNSFVUTaKve4QlFEUB1lgkbfN2H3/I7bvCqYhuE oX1Jb6KX12svbQvuiQtoH0ONohgPY3RpLenYdMZ7xq+Q63+pvQgGMGzuz+JdUV90vKvfamJx5r X38= X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="121063670" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Aug 2019 08:15:33 +0800 IronPort-SDR: v1VwbJmIzF8/4IqUjz43zlaHlQfPEaQQISZGhF9MVxmDMjpZod8a5UywjKOnzdIDcB2kxYEI1a jugSPr7mXQn64WJTZjM6gFycaMm4t/v2Ude05swY9aESOkhKUaEtYBnx5/o33tMquHbjcu17BY 4YqJ9rnvxzFhJdtOy0TDmADnFVRtMjwcQ1+GFl2apdqtJFP7s9StOiARTn2tbIUvrft9RONKQs 3WqkLGOwCqOg2yg0BADjOZz+7TbJ3YbIvxInRO/RX/lRRLtz9czeo71gXOz3h73sLonylUYRlq cpX/57nK0hYE/yh+1TIDHf+P Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 17:12:52 -0700 IronPort-SDR: Qwy5yDA5DDl56sdDPw76iawHJY9rUel09PbIcAHyQhbNaL7+EIUiWZLlgCWbSsktGDuHsxcmYq qvqrb+P89BDyAg699QAnSHKF6/uPaKRIBWp6c9Z6SPGJAwfMz1gMGA8PXVMRvEpGlbO8q6jkjp LJa/NqvRac1RIK9clDaffiBLBTbEbbZ/RdMCB8jUKbUWcn5/sraG4MRFJblrBV/3APps7bz8EC uPAJwpwAZDubtsZ12k06MJ7HxrzFPlVkx8vCD6oC6DQXinplGfIcAz4VZ1UnIMqzzUKv00hO4X 6aY= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Aug 2019 17:15:33 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 5/7] block: Introduce zoned block device elevator feature Date: Fri, 23 Aug 2019 09:15:26 +0900 Message-Id: <20190823001528.5673-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823001528.5673-1-damien.lemoal@wdc.com> References: <20190823001528.5673-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Introduce the elevator feature ELEVATOR_F_ZONED_BLOCK_DEV to indicate that an elevator supports zoned block device write ordering control. Mark the mq-deadline as supporting this feature which is implemented using zone write locking. SCSI zoned block device scan and null_blk device creation with zoned mode enabled are also modified to require this feature using the helper blk_queue_required_elevator_features(). This requirement can always be satisfied as the mq-deadline scheduler is always selected for in-kernel compilation when CONFIG_BLK_DEV_ZONED (zoned block device support) is enabled. Signed-off-by: Damien Le Moal --- block/mq-deadline.c | 1 + drivers/block/null_blk_main.c | 5 +++++ drivers/scsi/sd_zbc.c | 2 ++ include/linux/elevator.h | 7 +++++++ 4 files changed, 15 insertions(+) diff --git a/block/mq-deadline.c b/block/mq-deadline.c index 2a2a2e82832e..95e03408f2ac 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -795,6 +795,7 @@ static struct elevator_type mq_deadline = { .elevator_attrs = deadline_attrs, .elevator_name = "mq-deadline", .elevator_alias = "deadline", + .elevator_features = ELEVATOR_F_ZONED_BLOCK_DEV, .elevator_owner = THIS_MODULE, }; MODULE_ALIAS("mq-deadline-iosched"); diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 99c56d72ff78..253bb7b4443e 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1538,6 +1538,9 @@ static int null_gendisk_register(struct nullb *nullb) if (ret != 0) return ret; + + blk_queue_required_elevator_features(disk->queue, + ELEVATOR_F_ZONED_BLOCK_DEV); } add_disk(disk); @@ -1691,6 +1694,8 @@ static int null_add_dev(struct nullb_device *dev) blk_queue_chunk_sectors(nullb->q, dev->zone_size_sects); nullb->q->limits.zoned = BLK_ZONED_HM; blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, nullb->q); + blk_queue_required_elevator_features(nullb->q, + ELEVATOR_F_ZONED_BLOCK_DEV); } nullb->q->queuedata = nullb; diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 367614f0e34f..983f5d0be902 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -490,6 +490,8 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) goto err; /* The drive satisfies the kernel restrictions: set it up */ + blk_queue_required_elevator_features(sdkp->disk->queue, + ELEVATOR_F_ZONED_BLOCK_DEV); blk_queue_chunk_sectors(sdkp->disk->queue, logical_to_sectors(sdkp->device, zone_blocks)); blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, sdkp->disk->queue); diff --git a/include/linux/elevator.h b/include/linux/elevator.h index a99ca9979d71..2b667cb23fc0 100644 --- a/include/linux/elevator.h +++ b/include/linux/elevator.h @@ -166,5 +166,12 @@ extern struct request *elv_rb_find(struct rb_root *, sector_t); #define rq_entry_fifo(ptr) list_entry((ptr), struct request, queuelist) #define rq_fifo_clear(rq) list_del_init(&(rq)->queuelist) +/* + * Elevator features. + */ + +/* Supports zoned block devices sequential write */ +#define ELEVATOR_F_ZONED_BLOCK_DEV (1UL << 0) + #endif /* CONFIG_BLOCK */ #endif From patchwork Fri Aug 23 00:15:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11110267 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA6AF1813 for ; Fri, 23 Aug 2019 00:15:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9903A23402 for ; Fri, 23 Aug 2019 00:15:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="GYlhlWf9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728297AbfHWAPg (ORCPT ); Thu, 22 Aug 2019 20:15:36 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:30877 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728224AbfHWAPg (ORCPT ); Thu, 22 Aug 2019 20:15:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566519335; x=1598055335; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=gtr27q1T5jaqplfXgBqq2AoDZe91muleoBZ33dLpJ34=; b=GYlhlWf9hObVEJLOr+u3qThdicBn5b9hrMLHfRQxYQ+6sGUbxwldfWpR +5MLXARBYIvjbG37YutkkLu8mkYJdChjfhsYQ/PtfV8BYx1Qd/vPt3Kvu YM70btNIkRyzn2vhyRoNc9DFGAgZ0DyBmN5BY52ZjEvXnH1BZc3IvzlRz ZwEdnRoj9E14p5NBOAW+cY6EsaAE2WY4cg1gD6OTWV/deG0GQtZjeg96j MBD0fnGLxGMYeRsDajyAM07gjgy9bFU5G2wuFspMHbj0/B1GJl7gOQbwm c4ClfXb5feCnsoQqQpF3WtQmR5LW5QaCbZRhT5UPYbEVmfeijzJSjYcvn w==; IronPort-SDR: mF9kPbEBb88pRuND6oE98yWOuoqMDOOXm2/ijr296mOxg4PwjvFWDrsE/FZ5Esv+K6nT7VnP83 OoM25q7exJC1rdLNBp+6Yo3GhEKug+D8cXNH+NyazsbPK1aXRnY2e/pq7l8/I2zbtl23/b+n+Z W5UWhnwNrCJF8rS7oKeU9lxqhyMQpGu75Y+8fu1oJ//KdqhdO2OrErWoYbRyltdsOs4OWgZ3zQ 1+lIzMphm5WVk3TC/224dWidOLT/0YROKipzWdHnpxxZkd5n0l3ONkzqAMApBLK+iTy2Cn1tv0 kMg= X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="121063671" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Aug 2019 08:15:34 +0800 IronPort-SDR: zHbvVgtDShhXEAn2vXNsnwmtc5+BUT/PnUrjB7rawW9KJOJS7oshFXL69w+tW9IgnDAHqRyScV d5GAOXsR9HpzuI8lTxy+gWlYqsjABK5rDmANh23TXVMnZta0ZauYzjX2m14B/rClH9aAooCC+x SIaObDONXMT/J7gdDveCErxkdosF8CdqeVMNoYjBUMlxKmX4Min8FD5yeNT9//A7Pv2ZT+eG+K 0J3kiG0uIfUTY5aNgBrzdV0FLTt1E0EbWMIJWCTVBm4GLL43bBxBLP8QhKSyDVORMy/RtotzVa xQ/A49XPo5LTdcAWBHX8IaT0 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 17:12:53 -0700 IronPort-SDR: TDSawHVk5v+e/BdIxiCgG7NHjWRW2BqiIed+YnI4kpFP8OV9iISCK5/khNrM8ymTn2AvRxssET 443VsbVND3HjV87R9dD2yRWGaAEmnCv3zZ0QYJcoq2FmwkwvHKWSrQ1SvoX/O96z+qzoKt+qB2 dFC/jrbQoDlzXRCAmVQpRplsLPpIkt7Fwoft7VYKfzaLVZvnE78spGJvwWFwzYzsXwVoFBKmbA 4h9Tqt5iA1s9qDhMQHTbX1MvPChQLYun5rOsRxKSpnuKC3t0Oyx8w51JMwgyQjH+G7vgZLPKtK Z58= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Aug 2019 17:15:33 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 6/7] block: Improve default elevator selection Date: Fri, 23 Aug 2019 09:15:27 +0900 Message-Id: <20190823001528.5673-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823001528.5673-1-damien.lemoal@wdc.com> References: <20190823001528.5673-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org For block devices that do not specify required features, preserve the current default elevator selection (mq-deadline for single queue devices, none for multi-queue devices). For devices specifying a required feature (e.g. zoned block devices ELEVATOR_F_ZONED_BLOCK_DEV feature), select the first available elevator providing the required features. In all cases, default to "none" if no elevator is available or if the initialization of the default elevator fails. This change allows in particular the selection of the correct mq-deadline elevator for zoned block devices that are also multi-queue, such as null_blk devices with zoned mode enabled or any SMR disk connected to a smartpqi HBA (and exposed as multi-queue devices by the HBA). Signed-off-by: Damien Le Moal --- block/elevator.c | 50 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index de11beb32893..ec75dfee7e96 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -626,14 +626,51 @@ static inline bool elv_support_iosched(struct request_queue *q) } /* - * For blk-mq devices supporting IO scheduling, we default to using mq-deadline, - * if available, for single queue devices. If deadline isn't available OR - * deadline initialization fails OR we have multiple queues, default to "none". + * For single queue devices, default to using mq-deadline. If we have multiple + * queues or mq-deadline is not available, default to "none". + */ +static struct elevator_type *elevator_get_default(struct request_queue *q) +{ + if (q->nr_hw_queues != 1) + return NULL; + + return elevator_get(q, "mq-deadline", false); +} + +/* + * Get the first elevator providing the features required by the request queue. + * Default to "none" if no matching elevator is found. + */ +static struct elevator_type *elevator_get_by_features(struct request_queue *q) +{ + struct elevator_type *e; + + spin_lock(&elv_list_lock); + + list_for_each_entry(e, &elv_list, list) { + if (elv_support_features(e->elevator_features, + q->required_elevator_features)) + break; + } + + if (e && !try_module_get(e->elevator_owner)) + e = NULL; + + spin_unlock(&elv_list_lock); + + return e; +} + +/* + * For a device queue that has no required features, use the default elevator + * settings. Otherwise, use the first elevator available matching the required + * features. If no suitable elevator is find or if the chosen elevator + * initialization fails, fall back to the "none" elevator (no elevator). */ void elevator_init_mq(struct request_queue *q) { struct elevator_type *e; - int err = 0; + int err; if (!elv_support_iosched(q)) return; @@ -644,7 +681,10 @@ void elevator_init_mq(struct request_queue *q) if (unlikely(q->elevator)) return; - e = elevator_get(q, "mq-deadline", false); + if (!q->required_elevator_features) + e = elevator_get_default(q); + else + e = elevator_get_by_features(q); if (!e) return; From patchwork Fri Aug 23 00:15:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 11110265 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24B9D13A4 for ; Fri, 23 Aug 2019 00:15:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 03B9E2173E for ; Fri, 23 Aug 2019 00:15:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rIwVyH8T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728309AbfHWAPg (ORCPT ); Thu, 22 Aug 2019 20:15:36 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:30884 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728297AbfHWAPf (ORCPT ); Thu, 22 Aug 2019 20:15:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1566519335; x=1598055335; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=1/sXotb39VxftqsUW6LppcYGmJszREq2zKKiqRbq4T0=; b=rIwVyH8TVo8sm5PAtjs5bh/ObAt/Wr/vLRlZDmZEWKz9iwi7qjLdTK2w c8gvbNC3CiTd4ULhC+tNuXCzcAM9ak8IzES6TD+DMxF0N3djSbzexYGj7 EC5AT3ZAduh/dtz3LX8l66QLZNqsks86vctJpoG6K6MRoumVNQwboB25x XfjhURD3LAl29+AJ4kgXKzAXiRKcdmltEXnvyMl+YjQQYmwQMn8odkFwt tpMN8517Vgk5EL1yfOTZT40v6/ht7SLVuixoOJtsP9UvgweRuZv/TZdds nLF2AxEv5PwvA160+qE/3UwrQZEibsZPWISowgfECl5yfAC8IFD7iwEtX g==; IronPort-SDR: ur/3BZhYUbmuTH9aCMLNELu7xjfAMfsh1YJeg9k7AKtWRNO6paZc1foARjLcRm5Flxjt8A6gk3 rpNGEigT+ri/PNdHUntCaitZ+tBKXA7bQYdGG3p/JJrZmvNkW2dwK1uFyf7ehgqc3ST8q76CW5 9FzcuXrvVnL0p+Dw+XskRj7zpjq9B9b8wsKkuCDMyj96Ar/TDo08w7rfSOLlKaC6mBQS711bC3 go9ggCeMUPxUzKuAWxIWYoWZ/ZZYmE47ZeoMV7HrSxWX2eFUSRuAG/9vnNB6Lcm3OK0aZGKKdJ +P4= X-IronPort-AV: E=Sophos;i="5.64,419,1559491200"; d="scan'208";a="121063672" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Aug 2019 08:15:34 +0800 IronPort-SDR: S+VjhqF77i/bskYajMCfikb/2DoQjI83FCi84X2YPY2UV7lwud6VXmNjEr34bVzmvwZjGdCi82 yAzn8S/Ww8pCq25eG1gbNlo1gNN0Uh26KdARFbFQ0/fAeLI3TVTaVOXBNF5MV/En4EAvWq8AMZ KwvopRfjD5CcIXd3YHXegYjztxmSIko5NhUFdNISba0fgwnze816znhss3A5QN2177Kbl5k7kj 0rkY+yCZDny9exkHX4PLRNYP87C5pndO5r1v7Tncqm4kqe/xNFDeZSxbLF7Zwd/ZhWAsPUaAtj kiIQv0446VF49BRgFdjr86V9 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 17:12:53 -0700 IronPort-SDR: 6Cn9DR2qGuiJxq+052IiwcBG8ldiHkyGCFxCdsxGDK+mRb6ZqtMGEpyrEERh2AMf5MbXs/Rp7d bPU8BOJ5ScZTktiX2pA+jsCZXxk4zFvJlVSZh1KmSr2FbQHPfXgiqD6PZsGuaqewlQnZjhWZnc QZspxzuwRuqkH8nvLPH8CWFwm3qzgP1yJa97C6xM73KNawYCtFvxK5uWoMabSk3KwxLDn5bVG3 mTyVfHO2iDtpjJYmZIOHm2ht8HzXgn7ptyqkDCma4D1gbZI06wwkSzRKeClEtr1GiSd1qO3VYN j1s= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 22 Aug 2019 17:15:34 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 7/7] block: Delay default elevator initialization Date: Fri, 23 Aug 2019 09:15:28 +0900 Message-Id: <20190823001528.5673-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190823001528.5673-1-damien.lemoal@wdc.com> References: <20190823001528.5673-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org When elevator_init_mq() is called from blk_mq_init_allocated_queue(), the only information known about the device is the number of hardware queues as the block device scan by the device driver is not completed yet. The device type and the device required features are not set yet, preventing to correctly choose the default elevator most suitable for the device. This currently affects all multi-queue zoned block devices which default to the "none" elevator instead of the required "mq-deadline" elevator. These drives currently include host-managed SMR disks connected to a smartpqi HBA and null_blk block devices with zoned mode enabled. Upcoming NVMe Zoned Namespace devices will also be affected. Fix this by moving the execution of elevator_init_mq() from blk_mq_init_allocated_queue() into __device_add_disk() to allow for the device driver to probe the device characteristics and set attributes of the device request queue prior to the elevator initialization. Also to make sure that the elevator initialization is never done while requests are in-flight (there should be none when the device driver calls device_add_disk()), freeze and quiesce the device request queue before executing blk_mq_init_sched(). Signed-off-by: Damien Le Moal --- block/blk-mq.c | 2 -- block/elevator.c | 7 +++++++ block/genhd.c | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 274e168c8535..34e9541945dc 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2906,8 +2906,6 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, blk_mq_add_queue_tag_set(set, q); blk_mq_map_swqueue(q); - elevator_init_mq(q); - return q; err_hctxs: diff --git a/block/elevator.c b/block/elevator.c index ec75dfee7e96..9218bc86845f 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -688,7 +688,14 @@ void elevator_init_mq(struct request_queue *q) if (!e) return; + blk_mq_freeze_queue(q); + blk_mq_quiesce_queue(q); + err = blk_mq_init_sched(q, e); + + blk_mq_unquiesce_queue(q); + blk_mq_unfreeze_queue(q); + if (err) { pr_warn("\"%s\" elevator initialization failed, " "falling back to \"none\"\n", e->elevator_name); diff --git a/block/genhd.c b/block/genhd.c index 54f1f0d381f4..d2114c25dccd 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -734,6 +734,9 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, exact_match, exact_lock, disk); } register_disk(parent, disk, groups); + + elevator_init_mq(disk->queue); + if (register_queue) blk_register_queue(disk);