From patchwork Mon Oct 29 16:37:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10659729 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 62EF11751 for ; Mon, 29 Oct 2018 16:38:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4855229485 for ; Mon, 29 Oct 2018 16:38:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C92629494; Mon, 29 Oct 2018 16:38:41 +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=unavailable 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 DB9B229485 for ; Mon, 29 Oct 2018 16:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728023AbeJ3B2B (ORCPT ); Mon, 29 Oct 2018 21:28:01 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:38262 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728271AbeJ3B1X (ORCPT ); Mon, 29 Oct 2018 21:27:23 -0400 Received: by mail-it1-f193.google.com with SMTP id i76-v6so10174282ita.3 for ; Mon, 29 Oct 2018 09:38:02 -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=+Ubma7dzFX73Hbh4PnPWob3RQ4KFeUeAMfxQdKC8go8=; b=Yd47KbApQEd/1cn4fhtp/9aMGY4JyemCI0tK+Q3VU6uBVkHWnexp8wnOthKXO+1d1j 9pMn/MKd2iXdtc8P4Vw6EWw+pO1ml0OCkCkNGhCYZCldTvBu+6Sy16wC6SvFIjD2Kso9 VKnBp1DJyZXRbgOiqfxitizZnxYZWZPMfNkb6eTRg0KT+FcIABMzMyt3FjRCOuLEXT/p fXzRL/Wu3kLTZLY/7Is9jLBlMWbhNCb/DgcqLstVvPOZkVwlTGB4ZTj45WRUBd88/4y1 1VxqnBj49AAzg7DO0BZfYlFfC0YtmUyApqDGNOllLHUbjQm0gwGXVNJ9SKYM3DCbD3Vd fjNg== 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=+Ubma7dzFX73Hbh4PnPWob3RQ4KFeUeAMfxQdKC8go8=; b=IF6m2SS30kbDS4QHtMK89blTV44GH3hipQQa199ak0mo6XIDYdI2Ncc0YwTF3qCL1K 3WXJvAaJp4Kk9YEfaE8VI4hSAR+b0lBmsO4caVYjjrHOZwKrOyiyQfU9Z0Gd3nBlIiTV Di6EPe7IvxFYWl/mFYZ6D4Wu4DrHxSfCJ29Bir8aemPBK4yKT+yTgssyRugNd/vUoki4 GQ7Db7MS/TyaB/14iS8FdOqI2HysjCCb3iWU5BlJr752OojEeXnLUQ4+/9Nuh4/n7kgl vbVadWhVBLVF9w9a8n3/yBj/rbdCqEoJ6ap2xyQGPyMEfyrdhvlK5JyaIUBKQBOyL9+S c7Ow== X-Gm-Message-State: AGRZ1gKIcLD8KWj6FXRXHKPeZNFAwWaRxC47PtImOSq5/Rkw3bGkSQPZ LviZPQBv1D8AHIei0FNkL8L2+g== X-Google-Smtp-Source: AJdET5dAOXg1i6IzXCnAtCwU9nkIkH03E0vPTE6obve10Xk/y4S1tX8YKXzwn1TwKyIhxmv8FvMk7A== X-Received: by 2002:a02:9f85:: with SMTP id a5-v6mr3533728jam.2.1540831081595; Mon, 29 Oct 2018 09:38:01 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id q15-v6sm3367019itc.38.2018.10.29.09.37.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Oct 2018 09:38:00 -0700 (PDT) From: Jens Axboe To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 09/14] blk-mq: ensure that plug lists don't straddle hardware queues Date: Mon, 29 Oct 2018 10:37:33 -0600 Message-Id: <20181029163738.10172-10-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181029163738.10172-1-axboe@kernel.dk> References: <20181029163738.10172-1-axboe@kernel.dk> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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. Reviewed-by: Hannes Reinecke Signed-off-by: Jens Axboe --- 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;