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: 10659707 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 C26D01751 for ; Mon, 29 Oct 2018 16:38:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4CC82967A for ; Mon, 29 Oct 2018 16:38:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98EE429C45; Mon, 29 Oct 2018 16:38:05 +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 391912967A for ; Mon, 29 Oct 2018 16:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728292AbeJ3B1Y (ORCPT ); Mon, 29 Oct 2018 21:27:24 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:32999 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728293AbeJ3B1Y (ORCPT ); Mon, 29 Oct 2018 21:27:24 -0400 Received: by mail-it1-f194.google.com with SMTP id p11-v6so876925itf.0 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=tdDJskU1uc6On1ynHAy4A433LWKfJ9YetkfA3vUDpSWkKDhrg3hWnypAr9F/ckwqdL 7mXRCBr60UhBQlRn7mSD/TesJyq9SRcQwfY+qpKUt/ry6gzh32Qxj/xz0XsT4BHsViBR NVtp/KfIgYyI9T8mSe5hp5Q8nqspbHCI4qZdlYPLIf3v8XWYMRWdbqKuLMmowgpFnJFx CkDxHKQsaCVa5O3V+2UnCmnlkaOSEgi73vxs1toaTLV51sYl3U6nio2/kt/1vtjYJbRa ks3o0RCdCSlhIo8dpzikgQt6argvUp2yyxFBibHGzLsUbRJGvOSviaKnwSOn3feCdlOQ UYYg== X-Gm-Message-State: AGRZ1gJLj7rwRugANezvuv6QVSsZeCcXL1RMRiX8UlVM33GJsgwJzhdH HOA2slmFutwLWF7Nx4AJmM1Hmz/I3Wg= 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-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. 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;