From patchwork Wed May 3 19:58:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9710351 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2805E6021C for ; Wed, 3 May 2017 19:59:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1978328423 for ; Wed, 3 May 2017 19:59:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E3B72845D; Wed, 3 May 2017 19:59:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96F9528423 for ; Wed, 3 May 2017 19:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757710AbdECT7d (ORCPT ); Wed, 3 May 2017 15:59:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52176 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757671AbdECT73 (ORCPT ); Wed, 3 May 2017 15:59:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D94D80F9A; Wed, 3 May 2017 19:59:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1D94D80F9A Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ming.lei@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1D94D80F9A Received: from localhost (ovpn-12-23.pek2.redhat.com [10.72.12.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C3DF189A8; Wed, 3 May 2017 19:59:22 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Bart Van Assche , Omar Sandoval , Ming Lei Subject: [PATCH V2 4/5] blk-mq: use hw tag for scheduling if hw tag space is big enough Date: Thu, 4 May 2017 03:58:38 +0800 Message-Id: <20170503195839.6539-5-ming.lei@redhat.com> In-Reply-To: <20170503195839.6539-1-ming.lei@redhat.com> References: <20170503195839.6539-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 03 May 2017 19:59:29 +0000 (UTC) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When tag space of one device is big enough, we use hw tag directly for I/O scheduling. Now the decision is made if hw queue depth is not less than q->nr_requests and the tag set isn't shared. Signed-off-by: Ming Lei --- block/blk-mq-sched.c | 24 +++++++++++++++++------- block/blk-mq-sched.h | 22 ++++++++++++++++++++++ block/blk-mq.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index 817c97c88942..e25a2837d9f0 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -416,9 +416,9 @@ void blk_mq_sched_insert_requests(struct request_queue *q, blk_mq_run_hw_queue(hctx, run_queue_async); } -static void blk_mq_sched_free_tags(struct blk_mq_tag_set *set, - struct blk_mq_hw_ctx *hctx, - unsigned int hctx_idx) +void blk_mq_sched_free_tags(struct blk_mq_tag_set *set, + struct blk_mq_hw_ctx *hctx, + unsigned int hctx_idx) { if (hctx->sched_tags) { blk_mq_free_rqs(set, hctx->sched_tags, hctx_idx); @@ -427,9 +427,9 @@ static void blk_mq_sched_free_tags(struct blk_mq_tag_set *set, } } -static int blk_mq_sched_alloc_tags(struct request_queue *q, - struct blk_mq_hw_ctx *hctx, - unsigned int hctx_idx) +int blk_mq_sched_alloc_tags(struct request_queue *q, + struct blk_mq_hw_ctx *hctx, + unsigned int hctx_idx) { struct blk_mq_tag_set *set = q->tag_set; int ret; @@ -455,8 +455,10 @@ static void blk_mq_sched_tags_teardown(struct request_queue *q) struct blk_mq_hw_ctx *hctx; int i; - queue_for_each_hw_ctx(q, hctx, i) + queue_for_each_hw_ctx(q, hctx, i) { + hctx->flags &= ~BLK_MQ_F_SCHED_USE_HW_TAG; blk_mq_sched_free_tags(set, hctx, i); + } } int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, @@ -505,6 +507,7 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e) struct elevator_queue *eq; unsigned int i; int ret; + bool auto_hw_tag; if (!e) { q->elevator = NULL; @@ -517,7 +520,14 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e) */ q->nr_requests = 2 * BLKDEV_MAX_RQ; + auto_hw_tag = blk_mq_sched_may_use_hw_tag(q); + queue_for_each_hw_ctx(q, hctx, i) { + if (auto_hw_tag) + hctx->flags |= BLK_MQ_F_SCHED_USE_HW_TAG; + else + hctx->flags &= ~BLK_MQ_F_SCHED_USE_HW_TAG; + ret = blk_mq_sched_alloc_tags(q, hctx, i); if (ret) goto err; diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h index edafb5383b7b..241d23c18181 100644 --- a/block/blk-mq-sched.h +++ b/block/blk-mq-sched.h @@ -35,6 +35,13 @@ void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, int blk_mq_sched_init(struct request_queue *q); +void blk_mq_sched_free_tags(struct blk_mq_tag_set *set, + struct blk_mq_hw_ctx *hctx, + unsigned int hctx_idx); +int blk_mq_sched_alloc_tags(struct request_queue *q, + struct blk_mq_hw_ctx *hctx, + unsigned int hctx_idx); + static inline bool blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio) { @@ -129,4 +136,19 @@ static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx) return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state); } +/* + * If this queue has enough hardware tags and doesn't share tags with + * other queues, just use hw tag directly for scheduling. + */ +static inline bool blk_mq_sched_may_use_hw_tag(struct request_queue *q) +{ + if (q->tag_set->flags & BLK_MQ_F_TAG_SHARED) + return false; + + if (blk_mq_get_queue_depth(q) < q->nr_requests) + return false; + + return true; +} + #endif diff --git a/block/blk-mq.c b/block/blk-mq.c index 681bf33d8de8..0d9433680b2a 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2132,6 +2132,31 @@ int blk_mq_get_queue_depth(struct request_queue *q) return tags->bitmap_tags.sb.depth + tags->breserved_tags.sb.depth; } +static void blk_mq_update_sched_flag(struct request_queue *q) +{ + struct blk_mq_hw_ctx *hctx; + int i; + + if (!q->elevator) + return; + + if (!blk_mq_sched_may_use_hw_tag(q)) + queue_for_each_hw_ctx(q, hctx, i) { + hctx->flags &= ~BLK_MQ_F_SCHED_USE_HW_TAG; + if (!hctx->sched_tags) { + if (blk_mq_sched_alloc_tags(q, hctx, i)) + goto force_use_hw_tag; + } + } + else + force_use_hw_tag: + queue_for_each_hw_ctx(q, hctx, i) { + hctx->flags |= BLK_MQ_F_SCHED_USE_HW_TAG; + if (hctx->sched_tags) + blk_mq_sched_free_tags(q->tag_set, hctx, i); + } +} + static void queue_set_hctx_shared(struct request_queue *q, bool shared) { struct blk_mq_hw_ctx *hctx; @@ -2671,8 +2696,11 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr) break; } - if (!ret && sched) - q->nr_requests = nr; + if (!ret) { + if (sched) + q->nr_requests = nr; + blk_mq_update_sched_flag(q); + } blk_mq_unfreeze_queue(q);