Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2490859imm; Thu, 16 Aug 2018 10:21:21 -0700 (PDT) X-Google-Smtp-Source: AA+uWPySkmCEETmZeaQll6IODmGPBKGnQiAIu/I5Q92ZffTKml1vsxWnH0VxmaGhXeMVw9BphoPu X-Received: by 2002:a17:902:a58c:: with SMTP id az12-v6mr866494plb.339.1534440081540; Thu, 16 Aug 2018 10:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534440081; cv=none; d=google.com; s=arc-20160816; b=KP053HUAVvS2V1Cq8RaYLbjBGFMGWWWL5tELhUCnGjqMgvq7IF6MQarnsm3eGoDnPf kpP8YXgo1bjyouR1kmY1zTZGGSpYucLGdeJE7HbF+aZVnTPw8OkhsVVWTy8Aq5ctIT84 meUkMARlXg/4NJRo4WDmJElLcYV5F8Xyh5CqDWj7CFa4DMjGNaoTfHB5w0DU7NAPG1+h S79bIByWUabfelCV3+5dqVKRbum01Pm8FX/VGZwf+vaksvl5qnoucMVos7ul95nROJy8 3b8/WHq26BS0scGEuLhg/Iuh8ZtcdyiqukyaCQtbZEy20YdMUvwTlJmxmdVoY8n/3GNc Qyew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=N6UNoeuLUqBzuX6fo923I1SNsCQl1mjHmLxlcaQghrw=; b=Ustsympq0/mPgJAcdc42MPWhvhU2nqOKeDSGjutaYxj9rUa5USt7i1K5QxuWpeVxMd xWEJGEqPwXbNA2D9uNhF2b+jCvTYX0iHvGs9EATgOxNvPK/OP+c6uiAhTzcw/2JrZJju AwGhY9Ynhh4HqtHf6DHBFieEsvHI3OThGI1gkWQ2LjvajOyvmurHneBower6qjnxeyZ1 5z7nJ+zjNPidY4r2yATs3kSX0LJ9FUMKAaYco3pHHnTZpkogbmJXPLti5DJchE6bwO47 BlfjSzzr1Xa9jrEqE9WSAvpPgEziH9YULho0tT2PrswYI9c0mge7JGPgwjd+Z0XdaA6z cWPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=GqIDM8LK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p19-v6si25718613pgm.109.2018.08.16.10.21.04; Thu, 16 Aug 2018 10:21:21 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=GqIDM8LK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390429AbeHPMTA (ORCPT + 99 others); Thu, 16 Aug 2018 08:19:00 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:49986 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727243AbeHPMTA (ORCPT ); Thu, 16 Aug 2018 08:19:00 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w7G9IpLT012350; Thu, 16 Aug 2018 09:20:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=N6UNoeuLUqBzuX6fo923I1SNsCQl1mjHmLxlcaQghrw=; b=GqIDM8LKxFCotAR1V6tbBV7eh48rk5RVR6i/8yppXkCWhfQ6Vp1t/YbVmMqtlYqaKJjO lKJsZ54aqqd1SLHaKJQDBoon4ORLPVtLSTC5mIQVP8Tf9ilXpr8bm2j7YygMSDP1tkrq VZg5WaP7zKhI7OsBK3nI8GVZdBEAFwqfOe7Aa0vWbvNMQ4FEohT0gDtIDO4kbXBimmD4 AOpe68yCyOiZdg39itYcQ9v0y+axA2jIhSEM+VCtt5zDNs+So/oL7mmklG83UR3NDvOP 3D8pcshb/sRC5XAKilJAQCEyIMLj3GO4FTGNQavqc1zxffHvPW6n5AoVaAdjB39XAV50 TA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2ksreq99c2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Aug 2018 09:20:42 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7G9KfWI012343 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Aug 2018 09:20:41 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7G9Kfps026095; Thu, 16 Aug 2018 09:20:41 GMT Received: from [10.182.69.179] (/10.182.69.179) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Aug 2018 02:20:40 -0700 Subject: Re: [PATCH 2/2] blk-mq: sync the update nr_hw_queues with part_in_flight To: Ming Lei Cc: Ming Lei , Jens Axboe , Bart Van Assche , Keith Busch , linux-block , Linux Kernel Mailing List 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> From: "jianchao.wang" Message-ID: Date: Thu, 16 Aug 2018 17:20:50 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180816090334.GA7144@ming.t460p> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8986 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808160098 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. ;) Thanks Jianchao