From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AC5CC433E2 for ; Wed, 9 Sep 2020 10:42:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F9C421582 for ; Wed, 9 Sep 2020 10:42:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gAxWhmRE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727087AbgIIKl4 (ORCPT ); Wed, 9 Sep 2020 06:41:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34453 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726440AbgIIKlx (ORCPT ); Wed, 9 Sep 2020 06:41:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599648108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mpthdq6vNnXcbU3sxe9VzaFMMJAvmjzEwErsb5Ve6W4=; b=gAxWhmREHnMeJr5XcB0dGAzgD1alI4EPzF2Q+LlGjnB7DgSZbs1bUjLXHv/uKmjn4SKz8X 8B57EInATofF51B4znAWpzhBMc+Z2KIhSMrAMNFou5SgnD1MWjRX/QiQLYPGhfPrBtjv0z g3Kl1q5DkQbboFds9oaQTz1F1dNDTek= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-470-hrr8b-kCMfCGnduAOqxmmA-1; Wed, 09 Sep 2020 06:41:44 -0400 X-MC-Unique: hrr8b-kCMfCGnduAOqxmmA-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B55BC10ABDA2; Wed, 9 Sep 2020 10:41:42 +0000 (UTC) Received: from localhost (ovpn-12-76.pek2.redhat.com [10.72.12.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0202B7E8DC; Wed, 9 Sep 2020 10:41:41 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch Cc: Ming Lei , Sagi Grimberg , Bart Van Assche , Johannes Thumshirn , Chao Leng , Hannes Reinecke Subject: [PATCH V4 3/4] blk-mq: add tagset quiesce interface Date: Wed, 9 Sep 2020 18:41:15 +0800 Message-Id: <20200909104116.1674592-4-ming.lei@redhat.com> In-Reply-To: <20200909104116.1674592-1-ming.lei@redhat.com> References: <20200909104116.1674592-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org drivers that have shared tagsets may need to quiesce potentially a lot of request queues that all share a single tagset (e.g. nvme). Add an interface to quiesce all the queues on a given tagset. This interface is useful because it can speedup the quiesce by doing it in parallel. For tagsets that have BLK_MQ_F_BLOCKING set, we kill request queue's dispatch percpu-refcount such that all of them wait for the counter becoming zero. For tagsets that don't have BLK_MQ_F_BLOCKING set, we simply call a single synchronize_rcu as this is sufficient. This patch is against Sagi's original post. Signed-off-by: Ming Lei Cc: Sagi Grimberg Cc: Bart Van Assche Cc: Johannes Thumshirn Cc: Chao Leng Reviewed-by: Hannes Reinecke --- block/blk-mq.c | 59 +++++++++++++++++++++++++++++++++++------- include/linux/blk-mq.h | 2 ++ 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 37263ed48a8a..7669fe815cf9 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -214,16 +214,7 @@ void blk_mq_quiesce_queue_nowait(struct request_queue *q) } EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait); -/** - * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished - * @q: request queue. - * - * Note: this function does not prevent that the struct request end_io() - * callback function is invoked. Once this function is returned, we make - * sure no dispatch can happen until the queue is unquiesced via - * blk_mq_unquiesce_queue(). - */ -void blk_mq_quiesce_queue(struct request_queue *q) +static void __blk_mq_quiesce_queue(struct request_queue *q, bool wait) { bool blocking = !!(q->tag_set->flags & BLK_MQ_F_BLOCKING); bool was_quiesced =__blk_mq_quiesce_queue_nowait(q); @@ -231,12 +222,29 @@ void blk_mq_quiesce_queue(struct request_queue *q) if (!was_quiesced && blocking) percpu_ref_kill(&q->dispatch_counter); + if (!wait) + return; + if (blocking) wait_event(q->mq_quiesce_wq, percpu_ref_is_zero(&q->dispatch_counter)); else synchronize_rcu(); } + +/** + * blk_mq_quiesce_queue() - wait until all ongoing dispatches have finished + * @q: request queue. + * + * Note: this function does not prevent that the struct request end_io() + * callback function is invoked. Once this function is returned, we make + * sure no dispatch can happen until the queue is unquiesced via + * blk_mq_unquiesce_queue(). + */ +void blk_mq_quiesce_queue(struct request_queue *q) +{ + __blk_mq_quiesce_queue(q, true); +} EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue); /* @@ -258,6 +266,37 @@ void blk_mq_unquiesce_queue(struct request_queue *q) } EXPORT_SYMBOL_GPL(blk_mq_unquiesce_queue); +void blk_mq_quiesce_tagset(struct blk_mq_tag_set *set) +{ + struct request_queue *q; + + mutex_lock(&set->tag_list_lock); + list_for_each_entry(q, &set->tag_list, tag_set_list) + __blk_mq_quiesce_queue(q, false); + + /* wait until all queues' quiesce is done */ + if (set->flags & BLK_MQ_F_BLOCKING) { + list_for_each_entry(q, &set->tag_list, tag_set_list) + wait_event(q->mq_quiesce_wq, + percpu_ref_is_zero(&q->dispatch_counter)); + } else { + synchronize_rcu(); + } + mutex_unlock(&set->tag_list_lock); +} +EXPORT_SYMBOL_GPL(blk_mq_quiesce_tagset); + +void blk_mq_unquiesce_tagset(struct blk_mq_tag_set *set) +{ + struct request_queue *q; + + mutex_lock(&set->tag_list_lock); + list_for_each_entry(q, &set->tag_list, tag_set_list) + blk_mq_unquiesce_queue(q); + mutex_unlock(&set->tag_list_lock); +} +EXPORT_SYMBOL_GPL(blk_mq_unquiesce_tagset); + void blk_mq_wake_waiters(struct request_queue *q) { struct blk_mq_hw_ctx *hctx; diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index df642055f02c..90da3582b91d 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -519,6 +519,8 @@ int blk_mq_map_queues(struct blk_mq_queue_map *qmap); void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues); void blk_mq_quiesce_queue_nowait(struct request_queue *q); +void blk_mq_quiesce_tagset(struct blk_mq_tag_set *set); +void blk_mq_unquiesce_tagset(struct blk_mq_tag_set *set); unsigned int blk_mq_rq_cpu(struct request *rq); -- 2.25.2