From patchwork Thu Oct 25 21:16:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10656615 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 E440714DE for ; Thu, 25 Oct 2018 21:16:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D64192C463 for ; Thu, 25 Oct 2018 21:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C48EA2C656; Thu, 25 Oct 2018 21:16: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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 5850D2C463 for ; Thu, 25 Oct 2018 21:16:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727250AbeJZFvH (ORCPT ); Fri, 26 Oct 2018 01:51:07 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:37442 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbeJZFvH (ORCPT ); Fri, 26 Oct 2018 01:51:07 -0400 Received: by mail-io1-f68.google.com with SMTP id k17-v6so6419050ioc.4 for ; Thu, 25 Oct 2018 14:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+c7Pr+f64gmPa03Ptxfz2xO9kvQtiyGDeig20u/3rFI=; b=gMIVkhNhFdlzuoEHLIR/iDWckrNbx4BpeAQrC+8x/HFZljSfoBM0girz4TCWmav5XI c1492Ss5IR7dD2c3oyNLTNsoYBhh24u6uFewTkogJTh7ZyMPTi0Ezh6WDwnbDKyUV4Fm Bu6hEBtiZhal8o7b7KWYES/RErYkHJAe/cgboX5AHLDj1v++OrkqGnLEl6MaNCW4V5gi jpmrLQBvidJvtTrCTqySvvF4/wqZTbLvr+EgL3d9nsejDy2QICRBwqvS1JfvmZYCamCF PJp7PbpBSzyiJS4yF7uotzlGr8plBoM/u0j/b+7EkVk1vhtH5iCK9hxh38qCu1M66t6a FVcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+c7Pr+f64gmPa03Ptxfz2xO9kvQtiyGDeig20u/3rFI=; b=QvqmFEeI00yu67V1EkawMAkM5zIoNvbbJk7j64DRKrB4bG1WAXHoxuO6q8rODCRm+Q vZS0Tt7ukrIlWQR7UAXprjbjhmnXj9fdyVERmyud4hYEfh9/pWfWbCKZ6mbpSiQLso0L HRyrw7Z1kNa/Ratl88nGKH/RGsXN8fnFPeUQkf7LvLjHP/MxbDIJHP9MymswAYFmLVmD 0+cGsqwrL6ngdPMdJhAF0HIC0D8G6LYNj446QbVZt7auuo2y9R3VdkhJizGunYvdXAfR j/NVocIgbwOWHLKynuDnsZywWLEhlzbe6ibR7x2U3TXRF+OiQFmiSn+v9FdCtFr4wBep iZ4g== X-Gm-Message-State: AGRZ1gLnSkv6YUB94u5YItsMhes80bfbXV9GWQ9M9r6KyGAVeJA7NPAk Az0MqE/KyaaUhUj4oGzdYMQusPXHMVQqqw== X-Google-Smtp-Source: AJdET5e2/U/xmsCLOoEf8QlNC784FscW7fyBCeyG/TxYQLuQdC5FUivTfTgPQ+rvpg1tdoibHUQgow== X-Received: by 2002:a6b:4117:: with SMTP id n23-v6mr599001ioa.150.1540502207188; Thu, 25 Oct 2018 14:16:47 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id l23-v6sm2831890ioj.40.2018.10.25.14.16.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Oct 2018 14:16:45 -0700 (PDT) From: Jens Axboe To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: Jens Axboe Subject: [PATCH 09/14] blk-mq: ensure that plug lists don't straddle hardware queues Date: Thu, 25 Oct 2018 15:16:21 -0600 Message-Id: <20181025211626.12692-10-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181025211626.12692-1-axboe@kernel.dk> References: <20181025211626.12692-1-axboe@kernel.dk> 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 Since we insert per hardware queue, we have to ensure that every request on the plug list being inserted belongs to the same hardware queue. Signed-off-by: Jens Axboe Reviewed-by: Hannes Reinecke --- block/blk-mq.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 60a951c4934c..52b07188b39a 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1621,6 +1621,27 @@ static int plug_ctx_cmp(void *priv, struct list_head *a, struct list_head *b) blk_rq_pos(rqa) < blk_rq_pos(rqb))); } +/* + * Need to ensure that the hardware queue matches, so we don't submit + * a list of requests that end up on different hardware queues. + */ +static bool ctx_match(struct request *req, struct blk_mq_ctx *ctx, + unsigned int flags) +{ + if (req->mq_ctx != ctx) + return false; + + /* + * If we just have one map, then we know the hctx will match + * if the ctx matches + */ + if (req->q->tag_set->nr_maps == 1) + return true; + + return blk_mq_map_queue(req->q, req->cmd_flags, ctx->cpu) == + blk_mq_map_queue(req->q, flags, ctx->cpu); +} + void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) { struct blk_mq_ctx *this_ctx; @@ -1628,7 +1649,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) struct request *rq; LIST_HEAD(list); LIST_HEAD(ctx_list); - unsigned int depth; + unsigned int depth, this_flags; list_splice_init(&plug->mq_list, &list); @@ -1636,13 +1657,14 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) this_q = NULL; this_ctx = NULL; + this_flags = 0; depth = 0; while (!list_empty(&list)) { rq = list_entry_rq(list.next); list_del_init(&rq->queuelist); BUG_ON(!rq->q); - if (rq->mq_ctx != this_ctx) { + if (!ctx_match(rq, this_ctx, this_flags)) { if (this_ctx) { trace_block_unplug(this_q, depth, !from_schedule); blk_mq_sched_insert_requests(this_q, this_ctx, @@ -1650,6 +1672,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) from_schedule); } + this_flags = rq->cmd_flags; this_ctx = rq->mq_ctx; this_q = rq->q; depth = 0;