From patchwork Wed Sep 5 04:09:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jianchao.wang" X-Patchwork-Id: 10588211 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B9FF13AC for ; Wed, 5 Sep 2018 04:08:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 151222958F for ; Wed, 5 Sep 2018 04:08:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06C082959A; Wed, 5 Sep 2018 04:08:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 9CD9D2958F for ; Wed, 5 Sep 2018 04:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727525AbeIEIg4 (ORCPT ); Wed, 5 Sep 2018 04:36:56 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51498 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727462AbeIEIgz (ORCPT ); Wed, 5 Sep 2018 04:36:55 -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 w8543rrd098209; Wed, 5 Sep 2018 04:08:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=ZZGWplWggGJJdNVAZEyFTAY0lLunXe191YVe7YvEIWo=; b=FrHRU3UvpRhm7cMD3wRbFMKEDAKQfazqMb8DWj6OUo7xreHYkTlEhzcoSzLCCEsTWa5G 9CE5CEX4AQWV2OxqqoqxYBWUg6DwDvhbPhNY9tTpbkkvlz043Vr6faNPj7pE8Zils2Qf mwuFfc9FgKgZuTet3qyjPrVAFSi2fJxaEwtANK0/tI4tMxXAXh8PTCmDI02uKHb/91Or GeIk+YN3DXI7DlNYjBJzKpgPPWOqkoPN1oSnVmydNHv8mJfsUSiX40v9i57a2UDQBjcF ZD1GkabIOnC5qWfXhkGMARkxAhynmiVdSa02buF2hlxhApT/BexjiDxy0MSiyUkKiRV6 Fg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2m7kdqgyxq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 05 Sep 2018 04:08:21 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w8548Lb6022776 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 5 Sep 2018 04:08:21 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w8548KNi026190; Wed, 5 Sep 2018 04:08:20 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.70.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 05 Sep 2018 04:08:19 +0000 From: Jianchao Wang To: axboe@kernel.dk, ming.lei@redhat.com, bart.vanassche@wdc.com, sagi@grimberg.me, keith.busch@intel.com, jthumshirn@suse.de, jsmart2021@gmail.com Cc: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 2/3] blk-core: introduce queue close feature Date: Wed, 5 Sep 2018 12:09:45 +0800 Message-Id: <1536120586-3378-3-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536120586-3378-1-git-send-email-jianchao.w.wang@oracle.com> References: <1536120586-3378-1-git-send-email-jianchao.w.wang@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9006 signatures=668708 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-1809050042 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 blk queue freeze is often used to prevent new IO from entering request queue. However, becuase we kill the percpu-ref q_usage_counter when freeze queue, we have to drain the request queue when unfreeze. This is unnecessary for just preventing new IO. In addition, If there is IO timeout or other issue when unfreeze the queue, the scenario could be very tricky. So we introduce BLK_QUEUE_GATE_CLOSED to implement a light-weight queue close feature base on the queue_gate to prevent new IO from comming in queue which will not need to drain the queue any more. Signed-off-by: Jianchao Wang --- block/blk-core.c | 17 +++++++++++++++++ block/blk.h | 1 + include/linux/blkdev.h | 3 +++ 3 files changed, 21 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index d1bdded..b073c68 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -449,6 +449,23 @@ void blk_clear_preempt_only(struct request_queue *q) } EXPORT_SYMBOL_GPL(blk_clear_preempt_only); +int blk_set_queue_closed(struct request_queue *q) +{ + if (test_and_set_bit(BLK_QUEUE_GATE_CLOSED, &q->queue_gate)) + return 1; + + synchronize_rcu(); + return 0; +} +EXPORT_SYMBOL_GPL(blk_set_queue_closed); + +void blk_clear_queue_closed(struct request_queue *q) +{ + clear_bit(BLK_QUEUE_GATE_CLOSED, &q->queue_gate); + wake_up_all(&q->mq_freeze_wq); +} +EXPORT_SYMBOL_GPL(blk_clear_queue_closed); + /** * __blk_run_queue_uncond - run a queue whether or not it has been stopped * @q: The queue to run diff --git a/block/blk.h b/block/blk.h index cdef4c1..90ff6bb 100644 --- a/block/blk.h +++ b/block/blk.h @@ -21,6 +21,7 @@ extern struct dentry *blk_debugfs_root; enum blk_queue_gate_flag_t { BLK_QUEUE_GATE_PREEMPT_ONLY, + BLK_QUEUE_GATE_CLOSED, }; struct blk_flush_queue { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 4a33814..a7f77da 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -741,6 +741,9 @@ bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q); extern int blk_set_preempt_only(struct request_queue *q); extern void blk_clear_preempt_only(struct request_queue *q); +extern int blk_set_queue_closed(struct request_queue *q); +extern void blk_clear_queue_closed(struct request_queue *q); + static inline int queue_in_flight(struct request_queue *q) { return q->in_flight[0] + q->in_flight[1];