From patchwork Thu Sep 5 09:51:29 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: 11132541 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 5A8531813 for ; Thu, 5 Sep 2019 09:51:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3908B21743 for ; Thu, 5 Sep 2019 09:51:51 +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="b2ivoE6J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387528AbfIEJvu (ORCPT ); Thu, 5 Sep 2019 05:51:50 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25315 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730769AbfIEJvu (ORCPT ); Thu, 5 Sep 2019 05:51:50 -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=1567677110; x=1599213110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qtVWwALxJeFLEm5MyqWAjj8rH1FAELNGevTMV0H6ZXk=; b=b2ivoE6JWhfGnOHr6d/xSlb2ccAcj4qRm5YjFWn/Wzpa0Hfo6t0AzXUP niPghRlWYmLaKllGY5KDQzIVVphYtDPo4pRuDCzXOrpyc6g9kUojmstuC 7qNX1r3wQDJ8IQ1B1jx7rc2qgffY/JVP11yJrtWiZa12Q/9CXwvo2h0NV 5GEUuCcVN2f401Ad7MgVYaeSbw0OnnvWBnd9QPFB0wjm2aV0deh4iRr/j Ucft3Ar/j1HQ8D+iY3DCeX9ezo9ARgSTnlh11ko9k1JKz2d+3et12Luyi SIngGnMCXC8p4zhiBpuMbRIjsQMkcp4/ZUbA2TL79dYoR8wLAkoHXhweR Q==; IronPort-SDR: PmhJRti+Y36/IaUsPv4EGRFoRFBnFzHFQS60LQTWdTXSx1CDaQR7n3GdzEHp09bO7VkYJbr7ZX FCt6d08B5VCenzpgtOh3oyGcV0Bnae7Qk3kbAzIN4ewfEtnjynzd/OkHR78j2ryDVZXgXdB9vw 0lPqWR7XTGuq42Z0IOD32J32DBZbAlQM2s+R1Vne5CBBW3ei5P9+/cBzWFgpbcK9RARPxU4EN1 ddP+t4l2KhxLVUhFdtPWiDV2wLEbhIiKVyDTrRQSd+OEEW5r/wretX762h14UISYW4xHldDBCC gvs= X-IronPort-AV: E=Sophos;i="5.64,470,1559491200"; d="scan'208";a="119106244" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 17:51:39 +0800 IronPort-SDR: vNc6YPislMAS9M09vn3uaRzkNH1KfwKVXjDMEbYFgbiMOZtOZfJDna4a2SkuSsr5aLicJ/as7t sxApaOHEOLAiVuSmsNi+iHdtJoj4HVMibbcBI2Omo6CJUre8UdzbQKO4dHJBxbgkM3KBKt9ccg qGGFDbRnzicV3TUD0nyOb8g0ZHC/vSp4CwlbR6Pk+NVWaL9syi1Sf67DF/prskP3h4zun3M0fb eS8uSocXJBC/7/te5zrIp9WnLDz7cHmX+Ml3KfSSGEVgzDIDnLv+s+OaGmdGUemG/iND6u8Hkl 107s/UapZFCOY8f5eIu5WFWf Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 02:48:34 -0700 IronPort-SDR: a1602K9Xn5CMGYi4tWl9GfmJctXCTvgg9oOLhQh2hZXPZidyOEm0kgYUMAP7D5yngTAM/SXCXo R8TNXefFDNmQMEFZMjt1vvGY6smMg5m2ZEac3gi/nEdfdlRvKIY3XHzSrUcrZyvZz0Hk0/TNTF usVvTu1I5y5EdpIQEHMvHPCjQYboeyqZiy0sXeIKs7KDA5lKLsD/8/d3wH5yE0wdxa/VXdHALY kDdW38JPIFKQnssywVfp67mCEjcL0+SGTETYQJ83aU4f/FEWPLZ/ze+rbE5ilanMkz3xWMvhKB AF0= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Sep 2019 02:51:38 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Ming Lei Subject: [PATCH v5 1/7] block: Cleanup elevator_init_mq() use Date: Thu, 5 Sep 2019 18:51:29 +0900 Message-Id: <20190905095135.26026-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905095135.26026-1-damien.lemoal@wdc.com> References: <20190905095135.26026-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 Reviewed-by: Christoph Hellwig --- 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 b622029b19ea..13923630e00a 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2904,11 +2904,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 86100de88883..4721834815bb 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -619,16 +619,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; @@ -706,13 +716,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 Thu Sep 5 09:51:30 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: 11132545 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 EDA631709 for ; Thu, 5 Sep 2019 09:51:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC4A122CEC for ; Thu, 5 Sep 2019 09:51:52 +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="kKUHWvTO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387577AbfIEJvw (ORCPT ); Thu, 5 Sep 2019 05:51:52 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25315 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730769AbfIEJvv (ORCPT ); Thu, 5 Sep 2019 05:51:51 -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=1567677112; x=1599213112; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4es099Tzn+1lybmV19FyhcM0o6YKAGlTweyIXLI8G2M=; b=kKUHWvTOqf4keCOLA/R4zVJv6YvIVtv24qqMYzOgVnOdwAWwhuZSvRU9 nKzzsLgrvrZHdw+teHW9T4a/o/6wGxto5/5fvlRuBVrHQv0GAbkNuqQGp cTpykmkbwf0S0n4vip7KozqCmgaulIt8kMrWjQdtlizAzYgjpgULVWJB6 Q0OQyJkOMQMG/+2yvziMOZiK/R9/zqoCH2o+72l3/oRfKm/PBYLcBi43j HS4QofJD+7bxELH+OC5RAHgs1tvUrj6ohAMI+Ox6Kko0m2zEIgVy7JBqY aVK4MgEQtizf6ETtr5i74P1MfIgGh15gXjYcaJKDrz6fumuPsUNaxbxuL w==; IronPort-SDR: 7B0/A2pSyixCBNOWNMQ1ipoKXh1ftqtmDI6QKZmOFA6EfUvviWv9P8caZQGCcFBvldI6sgETj9 GGHnh6PCZ5quHqAYqfDCQqltk5SnF3nI5FhB1YP3p/WhFTdCc6Refzn6tHw8UXrJf0NJkzECNo grCYSt069biPM97pe922wSUbL54HIz/FM4YhvAwpruo+ov5nZPZWF9RGmr/fKEcQH1PKAMaYNc rACT7dkQo/YudRm2ZLaN6YE4R1z8PCp0ksffa/mxyeACgN0DwE9vNfKJuj/zqOtZpWtOzEM4oK rzg= X-IronPort-AV: E=Sophos;i="5.64,470,1559491200"; d="scan'208";a="119106254" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 17:51:40 +0800 IronPort-SDR: EPMWaudBJ+KmFjaumjnBOBdTYZ0Z+J2xH8hGlBCVtisnKVuglTxosOGcRK+PMKBsSAu8kX5+WS QPkqnrziAmfFus29o6NdIJTIshZgSJKNoqt6c4hrYoy+fi/MSJHFV7YPSpmypbP4LWlsOGH1o6 3gHJ6FyQbae7dMoDc7rcdmZaAVfU6Wb1gvdoKwFJ1uFXwaxzTINjinoOXud8QezA/pUEKJSR46 itoJzgpARWb8bmH/iOzW6KkjejgyWfKFEq3ackyHdUPv0+qUGgdIc5udAqa+OulzN6QOb8RON0 m9wrMpHwp5YHmRz/qiWwr55y Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 02:48:35 -0700 IronPort-SDR: zZEakMvskMlFNIDvSV9wxiBRD4mLO9VxhlarUpSqpeHQc9cpzF2ItrDi6grb6pXxAIrLz/PrNY 5p7ZXCUwzzVNAVxwN84zKR6rqp/zYsNwjf6HN/LBJ49MZMNz08COVy3+JvOIZEJ8dZfT/Syw7r 1NPIdlgd3F1/uQvRYUPXMKrK1KjY9vjx9MvChzyj0wr+iQmVU2eZUwuny/og6DaOVr3ZOxl92l T24+RRZEAoLIvHPf+vWIY41WW2e6gd9onB59X/s7rOwvWy/KJnE7XzOfZRSWQtdfs7qe4n1C7J 50U= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Sep 2019 02:51:39 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Ming Lei Subject: [PATCH v5 2/7] block: Change elevator_init_mq() to always succeed Date: Thu, 5 Sep 2019 18:51:30 +0900 Message-Id: <20190905095135.26026-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905095135.26026-1-damien.lemoal@wdc.com> References: <20190905095135.26026-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 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 and the device not being exposed. Instead of taking such extreme measure, handle mq-deadline initialization failures in the same manner as when mq-deadline is 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 Reviewed-by: Christoph Hellwig --- block/blk-mq.c | 8 +------- block/blk.h | 2 +- block/elevator.c | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 13923630e00a..ee4caf0c0807 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2842,8 +2842,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; @@ -2904,14 +2902,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 e4619fc5c99a..ed347f7a97b1 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 4721834815bb..2944c129760c 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -628,34 +628,35 @@ 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; + int err; if (!elv_support_iosched(q)) - return 0; + return; if (q->nr_hw_queues != 1) - return 0; + return; WARN_ON_ONCE(test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags)); if (unlikely(q->elevator)) - goto out; + return; e = elevator_get(q, "mq-deadline", false); if (!e) - goto out; + return; 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: - return err; + } } From patchwork Thu Sep 5 09:51:31 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: 11132549 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 03EF117EF for ; Thu, 5 Sep 2019 09:51:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CFF4B22CEC for ; Thu, 5 Sep 2019 09:51:53 +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="KXQnxiyc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387595AbfIEJvw (ORCPT ); Thu, 5 Sep 2019 05:51:52 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25326 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387564AbfIEJvw (ORCPT ); Thu, 5 Sep 2019 05:51:52 -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=1567677112; x=1599213112; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lXmNGw+0DXKWd3/CW5QfLTARK01VfROVWdtvZQJsTFQ=; b=KXQnxiycu/YuCU/ER4aVBOV7VwobSmpOG8hbqnppzwP6U9SWO4YavO7e UOMY3YSPZlxvVm8rHqvIGtKoc19zTy7issQ97BHgwc4z7xUgVTu7C1ZEk Ir8zsPytOoTTvOOtZ7t5QmM/4I5JKnaR30f5Bq9/VQkTz8GITkg9cuhM1 EWwli/snhBwE9uXKGke7SoQMWl8G0qRSagCJ6gslIiZH72bjnPpRftLPD bBlgqWU3fezVeGyaKhkPe6/ZAFYWUDMuDLSmRBSncHGC5AW8vIuz2G20S ZaagFD7IIDAHGu/l+Txul7X/o+xqEEeyeyAasuTSrVGz07stMJa9XfXTP Q==; IronPort-SDR: p2bLDDYRmQ1oFZtnuc4dz4cO1/9ep2nXnyEx1TYTSIOj+LRPu/ywFtay52VF0kQ4SKGn5QGdRr 8FwQ1p0sApX0AGhb/lBpLBRs69Z4lUcb0fZhEwo9QV6Cw96ALBjkpC6bbdJnYxalZeeGL4gZDa rf81xYTAj+drNPNeAEpzO1mD1sqCD+N4AvFRSmVirCMKrsigGx5yu/9a7Rqb94T+fXdVp1QGml qB4Y1KHpjvygjpT9jP1nLrFOcqhOzVkoXHGZrUPmFg2InLzvJVjEY2O++36T+4Zd4viMa+EK5f AeA= X-IronPort-AV: E=Sophos;i="5.64,470,1559491200"; d="scan'208";a="119106260" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 17:51:41 +0800 IronPort-SDR: US/8LjkpZQ9uu7JCbv6Ut6o7sOvCRF7keEywiaXUthoDafTarFY7GIkG7qGFdSAFa+A3tk2l/L GKZ2UfgkWEjaolJjpS+IE9ZQyqxby5hNRNUfeGp4GqqPVy3lVlxDqAc4l0dMt5+gwq5/O2zba5 1kugFbeRaUWFJGgLZEn04g9puEwwM/24W5frsW/salJxXKl5W3pxm0EGpY/Ufy19OkOma/uJj3 Nz+dCgU0nDa7rR1ks+fbY43AUQnUqgT+TgwzXeF9psNybvW/h7qjWTnCxTej8taaAevTK0LGnO 2RmqIz99sHdly6i7I4xDCp3K Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 02:48:37 -0700 IronPort-SDR: BXnLMIJWTPTDJVKVkqGiX3Pm3W77w+cFRGiV5qS407CiAIIkRQA1tMvRvO1XpK11Bt3xNmaAIA c8RT+WpHE6bP2OzfH1zYR7gKFWmwpYX1UWQtjTfgOSQKqpsUgZohHZUAYBWkjwP3f6+ZYmIGQi mwKAPH7HeQTeLYAns0GXWA75IKPKVtZvW6ivsaM0qG3BVWJIU182LGfhScGC2AKh3++p2rlwb8 VQtmZ2n/DsgxyasQlIO3OYeiWKC+jTQd6pSIDwf4MDsVFB+3FzS8LAds+5cROStM0xhO+2OjDR apI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Sep 2019 02:51:41 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Ming Lei Subject: [PATCH v5 3/7] block: Introduce elevator features Date: Thu, 5 Sep 2019 18:51:31 +0900 Message-Id: <20190905095135.26026-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905095135.26026-1-damien.lemoal@wdc.com> References: <20190905095135.26026-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 definition of elevator features through the elevator_features flags in the elevator_type structure. Each flag can represent a feature supported by an elevator. The first feature defined by this patch is support for zoned block device sequential write constraint with the flag ELEVATOR_F_ZBD_SEQ_WRITE, which is implemented by the mq-deadline elevator using zone write locking. Other possible features are IO priorities, write hints, latency targets or single-LUN dual-actuator disks (for which the elevator could maintain one LBA ordered list per actuator). The required_elevator_features field is also added to the request_queue structure to allow a device driver to specify elevator feature flags that an elevator must support for the correct operation of the device (e.g. device drivers for zoned block devices can have the ELEVATOR_F_ZBD_SEQ_WRITE flag as a required feature). The helper function blk_queue_required_elevator_features() is defined for setting this new field. With these two new fields 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 required features. Elevators not matching the device requirements are not shown 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 Reviewed-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- block/blk-settings.c | 16 +++++++++++++ block/elevator.c | 49 +++++++++++++++++++++++++++++++--------- block/mq-deadline.c | 1 + include/linux/blkdev.h | 4 ++++ include/linux/elevator.h | 8 +++++++ 5 files changed, 67 insertions(+), 11 deletions(-) diff --git a/block/blk-settings.c b/block/blk-settings.c index a058997b9cce..6bd1e3b082d8 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -832,6 +832,22 @@ 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 a queue required elevator features + * @q: the request queue for the target device + * @features: Required elevator features OR'ed together + * + * Tell the block layer that for the device controlled through @q, only the + * only elevators that can be used are those that implement at least the set of + * features specified by @features. + */ +void blk_queue_required_elevator_features(struct request_queue *q, + unsigned int 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 2944c129760c..ac7c8ad580ba 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 int elv_features, + unsigned int 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 int 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 int 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)) @@ -525,7 +549,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; @@ -709,7 +733,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; } @@ -749,11 +774,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/block/mq-deadline.c b/block/mq-deadline.c index 35e84bc0ec8c..b490f47fd553 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -794,6 +794,7 @@ static struct elevator_type mq_deadline = { .elevator_attrs = deadline_attrs, .elevator_name = "mq-deadline", .elevator_alias = "deadline", + .elevator_features = ELEVATOR_F_ZBD_SEQ_WRITE, .elevator_owner = THIS_MODULE, }; MODULE_ALIAS("mq-deadline-iosched"); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d0ad21e4771b..b196124e3240 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -496,6 +496,8 @@ struct request_queue { struct queue_limits limits; + unsigned int required_elevator_features; + #ifdef CONFIG_BLK_DEV_ZONED /* * Zoned block device information for request dispatch control. @@ -1097,6 +1099,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 int features); /* * Number of physical segments as sent to the device. diff --git a/include/linux/elevator.h b/include/linux/elevator.h index 1dd014c9c87b..901bda352dcb 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 int elevator_features; struct module *elevator_owner; #ifdef CONFIG_BLK_DEBUG_FS const struct blk_mq_debugfs_attr *queue_debugfs_attrs; @@ -165,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 constraint */ +#define ELEVATOR_F_ZBD_SEQ_WRITE (1U << 0) + #endif /* CONFIG_BLOCK */ #endif From patchwork Thu Sep 5 09:51:32 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: 11132567 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 D3C761813 for ; Thu, 5 Sep 2019 09:51:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B326E21743 for ; Thu, 5 Sep 2019 09:51:58 +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="QVGCwdO8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387619AbfIEJv4 (ORCPT ); Thu, 5 Sep 2019 05:51:56 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25326 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730769AbfIEJvw (ORCPT ); Thu, 5 Sep 2019 05:51:52 -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=1567677113; x=1599213113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q/G6ummKELIlmalkh9GPUWsUwphqsgUz0VruqeowzEs=; b=QVGCwdO82v6WXGi2Q5lIWrnkIsRlUG5/nBZ7Lj9cUts4tM67nBrAc9EJ 3/faBocA4zSzM251rEg9h9LypqYAdL+al5eu1JE02dF/JgYVwsmA02gTL i8nOBYvcIs2kQNe2FSzMKy9HDxkB2demguGsM0c4PZIuf0Tz6ty8gfkty tbA5AYR5yc0wSKjHu9O/tQTeXEQUJWVL83LbVHisycB7P6lPSTL3Y8jAN 21lvMOn6qay37IgmKPVU/9sj1yMgxj3ZqeP7OkqNX6ouX5wlawpbPV9QP 0IpMUCt3kR6di4PBMKi4ziF4gvB/YUqI2F9JkbyXlzDPtGU0lv+r3rrP7 g==; IronPort-SDR: EUKwRgaAgN2AFdZ14klUwvkMnx6BDI3NlyOkvnYg2TACQB6vHDrhmuWUfCZM0vYhtGqX1+YK3s Wo5Yk3vANy1lNCUjyDfajzAe71yoDUm2YE+z2LwnLpF7MRlOF6xW/pKM2o2DmvqZXbNhdxhz1e Pd4LUwMoOyFI8yoQNRG8bLopOsemdff39j6YL/4XnDC3oE9Q4WjIBcVIfOHjHKh2aK9Z6kYa/m +EAc5IPQp4DKngcN1WSsJuqPQWDuTghZwtcA4KMWIcDU/Jnhz/kj4CEgHWQcNj86YnawWE0zyM 10U= X-IronPort-AV: E=Sophos;i="5.64,470,1559491200"; d="scan'208";a="119106265" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 17:51:43 +0800 IronPort-SDR: 93u8f2l+jwlw36uwinAPZbgj7WSwOuTtKTkvIiNA6ZJwGMLJiaHcew4dEliozZKD1z8tu8eb2o UiGdyW7PcdWE6x1RPsBY3MzMEADRfxx+AjYwDctzBA8MbI8JYhYDGz2DnOjiNi9lWsurXTPw/c OZcQ3dnQdPW3OUpEDNHLNZNs6UTFRagnymsPP3UQL/SlcDyVy7URfNL52ClTM5ls7kFcrcnXjI Uu9giyiyRkZMU/eaArjgfo41//ziew/dOBlwsrfLa5j9MwCDTS+B6KAmNuriT5SQsE9QwF/mPy 733tmE2PY1cv+zzMuGpdyLcZ Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 02:48:38 -0700 IronPort-SDR: K1Ex14M6z8Ubl9VJIjS/Kv0LAFi/XUeURed2Nlsc0HXRxx6xbqs0ezsNxLfm51qmj288kf7U/T e1fpJUE3BpYNEHrHiM0ykEUIRJ8W4FlcPT0pgMszxKLoxNDnNa5MKO/X+RULqk0NmBwp1dMqSE EfMKRX5u8UsG6ZzyAxs5xSsNYRyUlmtMMtsVdK3vkAb2707oRzJT4snUEglwHgpX/n+uG3rAhY 2rnhvhhrILPr+qPNpN5U2VwjTVXv6jPR9cMzmR0HChFqJR28vwz+btMmGlftTmkbtU3+6L+90U OVs= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Sep 2019 02:51:42 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Ming Lei Subject: [PATCH v5 4/7] block: Improve default elevator selection Date: Thu, 5 Sep 2019 18:51:32 +0900 Message-Id: <20190905095135.26026-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905095135.26026-1-damien.lemoal@wdc.com> References: <20190905095135.26026-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). However, for devices specifying required features (e.g. zoned block devices ELEVATOR_F_ZBD_SEQ_WRITE 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. Signed-off-by: Damien Le Moal Reviewed-by: Johannes Thumshirn --- block/elevator.c | 51 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/block/elevator.c b/block/elevator.c index ac7c8ad580ba..520d6b224b74 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -651,9 +651,46 @@ 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) { @@ -663,15 +700,15 @@ void elevator_init_mq(struct request_queue *q) if (!elv_support_iosched(q)) return; - if (q->nr_hw_queues != 1) - return; - WARN_ON_ONCE(test_bit(QUEUE_FLAG_REGISTERED, &q->queue_flags)); 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 Thu Sep 5 09:51:33 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: 11132553 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 A86D71709 for ; Thu, 5 Sep 2019 09:51:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8787722CF7 for ; Thu, 5 Sep 2019 09:51:54 +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="o54BQ3W7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387611AbfIEJvx (ORCPT ); Thu, 5 Sep 2019 05:51:53 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25315 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732595AbfIEJvw (ORCPT ); Thu, 5 Sep 2019 05:51:52 -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=1567677113; x=1599213113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PErFhJdbRHZCrM47arWeyOIBOCDRRRHkAOiFwGGBAlU=; b=o54BQ3W7VYrJ3RCAcZOMze7AbqtmACBP4Ec2f4Gpzj/yfI38xBnhELnx AMAdDN2AQAc2UaEObMB5zSDTGAotpbOJyPGAWyQd89AwNMLUWyoGHKzAP XsomAtSqvOyiNp/p47+fTTIXh5uCylIYf4CFbZLS79SIQL9pdswFkdcU0 kppTZ69ie6VEO86xyG2eLBRi/rJU7wdSHEMBe0sfaul7JZb0VQvDlnq/8 4pZmo+yjWpk2IcG5/6yHGVlRLjaXfvTVPi0cPyh+NX0y2n87SFHDt6Vgg /NoxT5L3ujgzVqH2BffE09peW4m2XL5VutvCABvz9riFnZxQJYqRE9dZG A==; IronPort-SDR: VORp8KgBhVUf4CaQDt8+BsCxPR8qaE6Rb1J3YjLjBnvetyefg368Mtb9N7eOv64zAibWQ7S47A s1Y1Q9o1C0AwH1MuoRPQyTPKN5mx3J9kxhjOUNUBiOSuqFOUDeWKBGTWL/83n3IHEBVTSewVb8 4desonFD7KCpyJFPrwFoWPhNl7l3ggu1dw++5tDS1CNYjV+VockUiP2owTWyBzT2hKmLHvBk96 dkijyikRlFXZngWiEcz01+bpUTAFzicH+fS0cOq4wAXsvRgJLdIkO3zr670d5s2hZ0l36Inrbh zUw= X-IronPort-AV: E=Sophos;i="5.64,470,1559491200"; d="scan'208";a="119106271" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 17:51:44 +0800 IronPort-SDR: 5kxLtwjt7oPvjOFujmrtL+RvvVYl9vOBE//8LtGRjH+nRtOWP2/9W5ILarabby0njSWLxS5ers V+6O/yFpVO+lrU3Kt+k4RWCeugjJi41gWweiA5/fC/3xJ15PH2ZCL18QzdmVkg5RzEOXB8et72 zUtefc9CZo+e5a5khcuyzv+umxPUd+8FIbvejIuHusKAeMdstRUgZXHXDlk2cycg+88nOWZQEi YJTcaNZE8AKWJgCSEULPIpMBjJzYbJWpR6BwOJz/AdkoCtDJiMbs095CdFWQum/Y0CTaMwIiEx IJuA2+TJJT9RDpZ03ADinD/y Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 02:48:39 -0700 IronPort-SDR: W0iMItwJl+ZikypMnIqWii/vG5T4FLldmcZVG8h+aJmUfwZSH5seHXYPjySsjO8bbPIwhTCv8A jBPS2uYscziQRnY/8tUEr6LFBJOimsCeqXo38Vi6EvPWy1zMmMxPmU3ex8kS2IdK1tmGl3hEiF SF4vhznaXt90rqZhneKKcGV6S1lvHDY++qEYrDwgpKiyQLIu7fR5bF7E66myaA9iTYa+BkZo65 Ve6wCjshlslQTpYuPDPGS70VniGp/DSlrfep05asPiF5JsY0hM2N96rkf4yRRRRzRqIgvHhcz5 zKA= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Sep 2019 02:51:43 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Ming Lei Subject: [PATCH v5 5/7] block: Delay default elevator initialization Date: Thu, 5 Sep 2019 18:51:33 +0900 Message-Id: <20190905095135.26026-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905095135.26026-1-damien.lemoal@wdc.com> References: <20190905095135.26026-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 for most drivers. The device type and elevator required features are not set yet, preventing to correctly select 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 adding the boolean elevator_init argument to blk_mq_init_allocated_queue() to control the execution of elevator_init_mq(). Two cases exist: 1) elevator_init = false is used for calls to blk_mq_init_allocated_queue() within blk_mq_init_queue(). In this case, a call to elevator_init_mq() is added to __device_add_disk(), resulting in the delayed initialization of the queue elevator after the device driver finished probing the device information. This effectively allows elevator_init_mq() access to more information about the device. 2) elevator_init = true preserves the current behavior of initializing the elevator directly from blk_mq_init_allocated_queue(). This case is used for the special request based DM devices where the device gendisk is created before the queue initialization and device information (e.g. queue limits) is already known when the queue initialization is executed. Additionally, 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 calling blk_mq_init_sched() in elevator_init_mq(). Signed-off-by: Damien Le Moal --- block/blk-mq.c | 12 +++++++++--- block/elevator.c | 7 +++++++ block/genhd.c | 9 +++++++++ drivers/md/dm-rq.c | 2 +- include/linux/blk-mq.h | 3 ++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index ee4caf0c0807..240416057f28 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2689,7 +2689,11 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set) if (!uninit_q) return ERR_PTR(-ENOMEM); - q = blk_mq_init_allocated_queue(set, uninit_q); + /* + * Initialize the queue without an elevator. device_add_disk() will do + * the initialization. + */ + q = blk_mq_init_allocated_queue(set, uninit_q, false); if (IS_ERR(q)) blk_cleanup_queue(uninit_q); @@ -2840,7 +2844,8 @@ 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) + struct request_queue *q, + bool elevator_init) { /* mark the queue as mq asap */ q->mq_ops = set->ops; @@ -2902,7 +2907,8 @@ 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); + if (elevator_init) + elevator_init_mq(q); return q; diff --git a/block/elevator.c b/block/elevator.c index 520d6b224b74..096a670d22d7 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -712,7 +712,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..26b31fcae217 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -695,6 +695,15 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, dev_t devt; int retval; + /* + * The disk queue should now be all set with enough information about + * the device for the elevator code to pick an adequate default + * elevator if one is needed, that is, for devices requesting queue + * registration. + */ + if (register_queue) + elevator_init_mq(disk->queue); + /* minors == 0 indicates to use ext devt from part0 and should * be accompanied with EXT_DEVT flag. Make sure all * parameters make sense. diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c index 21d5c1784d0c..3f8577e2c13b 100644 --- a/drivers/md/dm-rq.c +++ b/drivers/md/dm-rq.c @@ -563,7 +563,7 @@ int dm_mq_init_request_queue(struct mapped_device *md, struct dm_table *t) if (err) goto out_kfree_tag_set; - q = blk_mq_init_allocated_queue(md->tag_set, md->queue); + q = blk_mq_init_allocated_queue(md->tag_set, md->queue, true); if (IS_ERR(q)) { err = PTR_ERR(q); goto out_tag_set; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 62a3bb715899..0bf056de5cc3 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -248,7 +248,8 @@ enum { struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *); struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, - struct request_queue *q); + struct request_queue *q, + bool elevator_init); struct request_queue *blk_mq_init_sq_queue(struct blk_mq_tag_set *set, const struct blk_mq_ops *ops, unsigned int queue_depth, From patchwork Thu Sep 5 09:51:34 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: 11132563 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 8D3F218A6 for ; Thu, 5 Sep 2019 09:51:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CD2321743 for ; Thu, 5 Sep 2019 09:51:57 +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="IyE8U2Tn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730769AbfIEJv4 (ORCPT ); Thu, 5 Sep 2019 05:51:56 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25315 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387607AbfIEJvx (ORCPT ); Thu, 5 Sep 2019 05:51:53 -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=1567677113; x=1599213113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+BoXKBI8NPREtCwEN8cyWiTl5gToB5DcHyIz5CI6+dg=; b=IyE8U2TnHaj/SO182xF8jTnU6cllqZ4hzkd/J9M5mhTzXw0qRJzicyNm 8iiUjVdbcKiMmn5lQ599UL875IF8IIEwsZ40GPpJvM/xrrvq2y1ii1h0r GjPRT8BAgC3pZbYiXjNk11T00oucDaKzsiC+Omi15uZmg/Tl07NxS8LbE Xlwdpy4iQ3z2IuAPl4giL00tW24fDLhJaYMyV4pukNY8T2pKe0d0O8Wmy A9x1LKnGLLjMvFCVDzEaNhBEoRRJ0ujhhX5VZxMPgOMsWM5lVQGVFGPei c4e77MMExRrK6vRNChIdHClgWJa2x4bE4Rq+KnNWXtg4SXPzE01VnbmR8 Q==; IronPort-SDR: ZBSUJ9PdxT5HhlFOZlLQtTzhRuCVA6744fzrJHazdbHyv+uphG8GOOso+LyjxCuSxPmifY96rK 7GxjgciPofij9CeUnpM496Ul0yxbsf6pXvm5zdm93mpDaw5h5HKqSGp9rTghDOXNq7y/Cy6kpY USNVmSVWD5oHNKW6ciClquXXgJp+Qe7Fw+pZUIayahDWSR2sHkLwhb+n6R6erBj/5jxciQTog9 1siD7SvXS/4R0CctccT+9k3tAgeyt7mUHHuw4NBUw6dH+LK4wCYCl86s29cMaOQSzCyh/wAMCY pxw= X-IronPort-AV: E=Sophos;i="5.64,470,1559491200"; d="scan'208";a="119106279" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 17:51:45 +0800 IronPort-SDR: DBMZ8xCL01vkbdFnc3A27SMhxRcyWMwtRv+IGzJiQXP5Na+MXGEiww8Vwxa437GWwHNA3rjLo0 11HKYvWIe/5SjmqHc8uttg3AI3tTGYaLPn3ScWr1gZQuyFyIsXqlwPrgb6DJSCqO1to0xZJX62 /vFfylOoLdI1S2GLrRgK2uJ/ZOjYrLQSK1sG49I+paA8x4Qkmhrd9gy/MWlGB11F62Mdam6iuw epBbC+B8sPldPA0xcm4Q2/ufOcQ7SMkov4tVmInbrMaCGU0VR+fLBZwoLwMaynS2cAtnyj7wyr Tq2feeV/cNM+gaG5nYppJa1v Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 02:48:41 -0700 IronPort-SDR: Lfq6lKAztSB3r+9NM2ybsRXa847PgYMz1cpkVkbcK/5O6l3KjTn47sJkjX5sYzZqM87vEd1H6B sG9XxTFxstHIIo72pzsTUpcc6Fhx7YeajeAOQ5LKHGg/dFXkMzxS37QPdMEsu3t7TGfpLSo1DW wj2SxRsBLQmESwEevJYsqoPyBT1lpzoHfiV+OlSiIXWo+/k3kXIziEVFAacN61BY6o58Vuo+4R I8n4EuROm7l/RIY2WszBVXC0p6ySS4motlLqbWs+K95qbP1LvMlIGUPC4mcVGFhpzlf4aTPCXs Fis= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Sep 2019 02:51:44 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Ming Lei Subject: [PATCH v5 6/7] block: Set ELEVATOR_F_ZBD_SEQ_WRITE for nullblk zoned disks Date: Thu, 5 Sep 2019 18:51:34 +0900 Message-Id: <20190905095135.26026-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905095135.26026-1-damien.lemoal@wdc.com> References: <20190905095135.26026-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 Using the helper blk_queue_required_elevator_features(), set the elevator feature ELEVATOR_F_ZBD_SEQ_WRITE as required for the request queue of null_blk devices created with zoned mode enabled. This feature requirement can always be satisfied as the mq-deadline elevator is always selected for in-kernel compilation when CONFIG_BLK_DEV_ZONED (zoned block device support) is enabled. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- drivers/block/null_blk_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index b26a178d064d..b29b273690b0 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1695,6 +1695,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_ZBD_SEQ_WRITE); } nullb->q->queuedata = nullb; From patchwork Thu Sep 5 09:51:35 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: 11132559 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 2AB471813 for ; Thu, 5 Sep 2019 09:51:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A7F422CEC for ; Thu, 5 Sep 2019 09:51:57 +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="ZaFrLXNa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732595AbfIEJv4 (ORCPT ); Thu, 5 Sep 2019 05:51:56 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:25332 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387610AbfIEJvx (ORCPT ); Thu, 5 Sep 2019 05:51:53 -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=1567677113; x=1599213113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/XtlwHOsIPicnyo2flJ5KzL1vmCB4hpFdRCl5+DsDD4=; b=ZaFrLXNajUGEKwPIdZg601bnVY55rqLkeuSUuKJpqBGybaR9Z+k1Cnkg KhhiWkh0A9n2Hvi6tnQd+D1NBfI0DM9qTNzJfxpds06IAm6jnuECbgms4 E05j5jaT6Cj23p7lsIO4gqz2S1cf5rPo42bM5ecREvxZk73J+fGHZexfW FJCG8tDwGnPa/Qr2yJ19XjjtNtMwSs6XL1xLeT1VdRt9Rn2TyqzToZgvU 0PEwau2OcMWzBEr3xcA2oYxeTS66ip7q93CqySBx2r7J8RahNW14c2yUw lMhr6FAITONSsk8zQ6MUuqrxZB96w1sp0u6+Zhosgez6p/RFGF+kNmM7k w==; IronPort-SDR: v4cAabHgIJyO4MVWVb2B1zhADh4GTxSoy/ug9c/XTQM6gYIBbMFuQpYu+lqXExik3XXZDVOJ3t jqiAsoWYTk7zaju5zsORHH+vftot3gE2l8/J5O92cSjJrdXbS2iDFGtLi5Ervu5y/FojQudlY3 udYrfdU0IzJGuTsTnDtpXw3X/ohWJ4LVAwX4cEOPkR9DNAdwZIfXPRfZhmTfccovVaIZHt526E BI48QKt3Wmb9EDiasz4DrCGYcolGlorWbotgHk8C1PtXHN0MVOOFeGBe3pL2W1pMsvXEL9L11t EDA= X-IronPort-AV: E=Sophos;i="5.64,470,1559491200"; d="scan'208";a="119106283" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Sep 2019 17:51:46 +0800 IronPort-SDR: hUlJUPcK66iQjuFAMR8oNMTDPNNpzVHWFHmLlYjeEG5foXKgwZPV2ygUWr9Nn2pzRHx/CtKT4l 66t7sRUmIBZOu1jrRVZYBvwm6itE23RNSItS70Z7v7iMi7bxWlRrz1T+6f1YoW4J9WmZnvajG2 ZJsyHEFv8eWX3cX2rXPfA7xlnsrX9SKsG7hgW1ly4WG1d9Qv5Nue7JHb7j//xU9q7JRBJgUYAE MJSnMdCEb5vv4REsv42rV/HIxU2L3jMSSjMfGXIo3UIhdEri4bFx1c39HvNAjAQwQPV3imAWsk zzGkzLsTCSlhhP51G1FcZIZS Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 02:48:42 -0700 IronPort-SDR: PMcqYEJtk0jNIxalMYnj1tGVSoFhITi6da+9KU/BbwBavagIEJVYSrRDsTM+vRMVIhqb4doxaC kWs/cbz3itasjn4XhJExza74T8zJXrlVKgF16N2qLo9ED5Gpr/LnPa/himSsRWGYLYDjGCFtv0 STrpHKMJiJS84SBMdTyKHRZHqd0C7HlprXT0V8ZnoE67PHSxG/6lbaaVjVLJ+ptkqjkjnY4g8Z ROg1ezQjpPJmmoeUX4o/5AB0aEA6jPX1G8VKMCa/3b1V6N5RrYlOG27+l4NgXPoMxhbwWl3Cag fWc= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 05 Sep 2019 02:51:46 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Ming Lei Subject: [PATCH v5 7/7] sd: Set ELEVATOR_F_ZBD_SEQ_WRITE for ZBC disks Date: Thu, 5 Sep 2019 18:51:35 +0900 Message-Id: <20190905095135.26026-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190905095135.26026-1-damien.lemoal@wdc.com> References: <20190905095135.26026-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 Using the helper blk_queue_required_elevator_features(), set the elevator feature ELEVATOR_F_ZBD_SEQ_WRITE as required for the request queue of SCSI ZBC disks. This feature requirement can always be satisfied as the mq-deadline elevator is always selected for in-kernel compilation when CONFIG_BLK_DEV_ZONED (zoned block device support) is enabled. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- drivers/scsi/sd_zbc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 367614f0e34f..de4019dc0f0b 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -493,6 +493,8 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) 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); + blk_queue_required_elevator_features(sdkp->disk->queue, + ELEVATOR_F_ZBD_SEQ_WRITE); nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks); /* READ16/WRITE16 is mandatory for ZBC disks */