Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2543090imm; Thu, 16 Aug 2018 11:11:19 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyzNs+ffcY+oPG24mwdJ+gGhxh0xL+8Nvyt8bwNTeKDtBqiJHsbkButkhITMm9O2mZKpp3F X-Received: by 2002:a63:cb04:: with SMTP id p4-v6mr354487pgg.197.1534443079922; Thu, 16 Aug 2018 11:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534443079; cv=none; d=google.com; s=arc-20160816; b=FelZrKUK8vvaCH+0yt460l+ATu6tDCHz+ZZ+s9odgQGQB5JgVfcShzH42Ap9PYShvq etS69/tRwk4pyNwnmn9mpxYMUJe2ZNrOebuwTShdYRFuz89VvXAHbWOLtGtR43HGWZHZ kJbe7FFGxDHus/OVlmc13mHrkBNdCmBpr29PaUthWkTOKSHABz/l/yR4KJWhH8QkV55I PTYsg5NcVueeQQoFYC9WJnaztpXpgcKDtJtqFWGrHYd4geXyU/un6eB9O4DCiDJ0jW/H gRgr0PvjpkQN5moL1SgKnmlOoFfJF1RZ8AuOf3jLKQnIk6+s97E5LBLd9vPCY+Ez06sA ASfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=CoX3dNJScf7XKXSP//g1g64zw3tbEo+4zzPpvRXSZU8=; b=wPFDZkcOY/19p06OqRg7/HSKb+oi+elxwZZjcGkrOYPSgfsx0LFR9U5xprhxitim46 7FLEYZAjIhNQhysn3bE1tpQImI0mVX9/3mu1v651wQ+1Um8obeZ0R+KqUCCUUaXdJof2 P1a2lryCmdxFPeQTNgig1suN1emyBr3H/VQyuR0zQUkC+ertNbV3L65t514XI3WZUKca mcii+dhqsiqgxwXmt6yN60huWBnD6cojT4qz9G02n5QwEsXgFQmmYvKeldnmcQoObuYO fq7V042XWBCE/0q4bkSYZ/14xRBhGGLcx/6PPjiFBWWk4rcswgHMiTW+avW7AWzZciOW gkRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16-v6si22966553pll.1.2018.08.16.11.11.04; Thu, 16 Aug 2018 11:11:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390564AbeHPMg1 (ORCPT + 99 others); Thu, 16 Aug 2018 08:36:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45952 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730390AbeHPMg1 (ORCPT ); Thu, 16 Aug 2018 08:36:27 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 109D040201C9; Thu, 16 Aug 2018 09:39:08 +0000 (UTC) Received: from ming.t460p (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F1DAA2026D7E; Thu, 16 Aug 2018 09:38:56 +0000 (UTC) Date: Thu, 16 Aug 2018 17:38:51 +0800 From: Ming Lei To: "jianchao.wang" Cc: Ming Lei , Jens Axboe , Bart Van Assche , Keith Busch , linux-block , Linux Kernel Mailing List Subject: Re: [PATCH 2/2] blk-mq: sync the update nr_hw_queues with part_in_flight Message-ID: <20180816093850.GB7144@ming.t460p> References: <1534317915-5041-1-git-send-email-jianchao.w.wang@oracle.com> <1534317915-5041-3-git-send-email-jianchao.w.wang@oracle.com> <8cd103e6-0986-2c45-00f2-8a2a540a2eb5@oracle.com> <20180816090334.GA7144@ming.t460p> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 09:39:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 16 Aug 2018 09:39:08 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 16, 2018 at 05:20:50PM +0800, jianchao.wang wrote: > Hi Ming > > On 08/16/2018 05:03 PM, Ming Lei wrote: > > diff --git a/block/blk-mq.c b/block/blk-mq.c > > index b42a2c9ba00e..fbc5534f8178 100644 > > --- a/block/blk-mq.c > > +++ b/block/blk-mq.c > > @@ -113,6 +113,10 @@ void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part, > > struct mq_inflight mi = { .part = part, .inflight = inflight, }; > > > > inflight[0] = inflight[1] = 0; > > + > > + if (percpu_ref_is_dying(&q->q_usage_counter)) > > + return; > > + > > blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi); > > } > > That's a good idea to use q->q_usage_counter. > But I think we could do following modification: > 1. use percpu_ref_is_zero, then we will not miss any in-flight request here. > 2. use rcu to ensure the user of blk_mq_in_flight has gone out of the critical section. > Like following patch: > diff --git a/block/blk-mq.c b/block/blk-mq.c > index 89904cc..cd9878e 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -113,7 +113,12 @@ void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part, > > inflight[0] = inflight[1] = 0; > > + rcu_read_lock(); > + if (percpu_ref_is_zero(&q->q_usage_counter)) > + return; > + > blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi); > + rcu_read_unlock(); > } > > static void blk_mq_check_inflight_rw(struct blk_mq_hw_ctx *hctx, > @@ -2907,6 +2912,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, > list_for_each_entry(q, &set->tag_list, tag_set_list) > blk_mq_freeze_queue(q); > > + synchronize_rcu(); > /* > * switch io scheduler to NULL to clean up the data in it. > * will get it back after update mapping between cpu and hw queues. > > And also, some comment is needed to describe them. ;) This patch looks fine for me. Thanks Ming