Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4189580imm; Wed, 30 May 2018 00:27:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKf+6snF2B9mgjS1NDiw36fGMhJ75HkuLkU6Zxsorf06KY5U34ECfTg5I7kNQxL9VgLayKi X-Received: by 2002:a17:902:8c92:: with SMTP id t18-v6mr1739358plo.337.1527665228796; Wed, 30 May 2018 00:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527665228; cv=none; d=google.com; s=arc-20160816; b=gI/TGsTcN4BsYVNDr2vcZ7b2gvH4awh7M6MEUuOon8UmbmxWCm5Fnh24MDZO/biw65 ycyypmAC8cy168RbaBh0vT1Fo+/iomzZl08NlFtoOYBHZi+zhY0mK9iBUTu+4TNoAs3T +eE9etZYI4RX4kYY7+MgqHFz6dicQ2hjaQ4S2NwkbsgkSzUXw6fwDOKsviXEmc75pygg s8LoyT86fBc95VOgMW+jcA5UA/kplLwdG3F8v0rql8XDqAH+QxY8dJRIa9jqNNMd9Kcd jdabTJ/tR/Od0ZwdSXKO6/bZzdqNS2GkY7yR1T4HvWRNrQGLIpNokV/0vDCT3BZiWN37 X2zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=gUMaOKh6OEZ2uoajY/iDkAaR84F+XB5W57w3AU78PwQ=; b=bupRXcaCfTIbJj98U+tTF1srTUtBbo822/NnsJ5sdB4pI2nFv+90dYEmpM61r/jcgA wZRxqTMUaNruX20QLLxQWB13g7SwRCAiYgZHRF7HzgUtlc5YkkNoeMIIFMkDOIatSR6V K5gAj8jDe/u0FRqastyX2U7LecDCQKkA7qmYSigQE1/qZRZAb+ZTygDI9fOAH+YfWUAu IVt8rTo45IamdKSsLCP31bk8jLeEXGxJtekuD31hfxcEtS8hfSjWpYKRGQEF7kYOvBwv yefEK8YtJo2ZBliHZS4GWiwQEudP23FdPNMXlmrsLE/etBcCahYylozFDbN7eFZlxCRy oD4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=E0WeCJxb; 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 61-v6si33740709plz.290.2018.05.30.00.26.54; Wed, 30 May 2018 00:27:08 -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-2017-10-26 header.b=E0WeCJxb; 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 S935894AbeE3HZV (ORCPT + 99 others); Wed, 30 May 2018 03:25:21 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:54992 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934600AbeE3HZT (ORCPT ); Wed, 30 May 2018 03:25:19 -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 w4U7MFUv065585; Wed, 30 May 2018 07:25:15 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-2017-10-26; bh=gUMaOKh6OEZ2uoajY/iDkAaR84F+XB5W57w3AU78PwQ=; b=E0WeCJxbRnqtCLZl59oR51F9ZpyEaqad7Ev6XhwFS2gow1m7HJfYjLxxIzvqElarBUK4 HSlRnCrbJkZpUudz5c3dsoOkh5yu5E/nkZZ8N64CUxa9+xmvJNQxVooijWbwVI8Feey8 HUT9ghpcffBsvnYlNPqhXF8SIQu2yiNNI8qNJtwDKLGWfBYeWvMsYSxGEpCPYFiRfpDk vow52YXEtuynZsj/VBZiNbs5GETUohgA68ICicXReac6PrtNudcgkoN00obPMgYGPzzk heWeL/o+KbwuqHTH+WQnozKa7mUtC+GwKhKeEzOd+USoj0Ot0YyWI7Im7x/nBfTFgxNY SA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2j9ev813de-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 May 2018 07:25:15 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w4U7PEHa013003 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 May 2018 07:25:14 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w4U7PEZZ020503; Wed, 30 May 2018 07:25:14 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.70.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 30 May 2018 00:25:13 -0700 From: Jianchao Wang To: axboe@kernel.dk, osandov@osandov.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V3 1/2] blk-mq: abstract out blk-mq-sched rq list iteration bio merge helper Date: Wed, 30 May 2018 15:26:07 +0800 Message-Id: <1527665168-1965-2-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527665168-1965-1-git-send-email-jianchao.w.wang@oracle.com> References: <1527665168-1965-1-git-send-email-jianchao.w.wang@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8908 signatures=668702 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-1805220000 definitions=main-1805300085 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe No functional changes in this patch, just a prep patch for utilizing this in an IO scheduler. Signed-off-by: Jens Axboe Reviewed-by: Omar Sandoval --- block/blk-mq-sched.c | 34 ++++++++++++++++++++++++---------- include/linux/blk-mq.h | 3 ++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c index 25c14c5..b0f2c2a 100644 --- a/block/blk-mq-sched.c +++ b/block/blk-mq-sched.c @@ -268,19 +268,16 @@ bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio, EXPORT_SYMBOL_GPL(blk_mq_sched_try_merge); /* - * Reverse check our software queue for entries that we could potentially - * merge with. Currently includes a hand-wavy stop count of 8, to not spend - * too much time checking for merges. + * Iterate list of requests and see if we can merge this bio with any + * of them. */ -static bool blk_mq_attempt_merge(struct request_queue *q, - struct blk_mq_ctx *ctx, struct bio *bio) +bool blk_mq_bio_list_merge(struct request_queue *q, struct list_head *list, + struct bio *bio) { struct request *rq; int checked = 8; - lockdep_assert_held(&ctx->lock); - - list_for_each_entry_reverse(rq, &ctx->rq_list, queuelist) { + list_for_each_entry_reverse(rq, list, queuelist) { bool merged = false; if (!checked--) @@ -305,13 +302,30 @@ static bool blk_mq_attempt_merge(struct request_queue *q, continue; } - if (merged) - ctx->rq_merged++; return merged; } return false; } +EXPORT_SYMBOL_GPL(blk_mq_bio_list_merge); + +/* + * Reverse check our software queue for entries that we could potentially + * merge with. Currently includes a hand-wavy stop count of 8, to not spend + * too much time checking for merges. + */ +static bool blk_mq_attempt_merge(struct request_queue *q, + struct blk_mq_ctx *ctx, struct bio *bio) +{ + lockdep_assert_held(&ctx->lock); + + if (blk_mq_bio_list_merge(q, &ctx->rq_list, bio)) { + ctx->rq_merged++; + return true; + } + + return false; +} bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio) { diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index ebc34a5..fb35517 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -259,7 +259,8 @@ void blk_mq_add_to_requeue_list(struct request *rq, bool at_head, void blk_mq_kick_requeue_list(struct request_queue *q); void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs); void blk_mq_complete_request(struct request *rq); - +bool blk_mq_bio_list_merge(struct request_queue *q, struct list_head *list, + struct bio *bio); bool blk_mq_queue_stopped(struct request_queue *q); void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx); void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx); -- 2.7.4