From patchwork Tue Oct 30 18:32:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10661401 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 4E69A14DE for ; Tue, 30 Oct 2018 18:34:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58E3D299B9 for ; Tue, 30 Oct 2018 18:34:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CFB829C60; Tue, 30 Oct 2018 18:34:09 +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 D2650299B9 for ; Tue, 30 Oct 2018 18:34:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728280AbeJaD1z (ORCPT ); Tue, 30 Oct 2018 23:27:55 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:52985 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728279AbeJaD1y (ORCPT ); Tue, 30 Oct 2018 23:27:54 -0400 Received: by mail-it1-f194.google.com with SMTP id r5-v6so12973742ith.2 for ; Tue, 30 Oct 2018 11:33:19 -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=lH0eWuHHiCANq4BSpJWvv00qJJn3hhUC9L40R4M73kg=; b=L6UjNA4JF31+E+Ock5f0VSU5X3Dk0iICBqga3Tx3kV+eKs7FPIeIuGNFXw5aHPW9tC TVwvcWPavhVJ2QbIQ+h5OpAXYxad1lIJbebfSSkaXCV2yyHCZzReBM8nWjaiJzQcN/xl aqEbmoe/1XkpU2PKUl/6KmogXOQdlzebab6HO4MHtl3NbJpFBJexnJ4ZoXyG40z7Spd5 2U2vluq64peFNvQocy7lBQS5LfYRfG2YkjAgg1ZL72D3avVYuMbCpND8myxsk5BVd+6k P/CDe734E92S1g7S1KJzdMEPkQhiVi4IzwalJwgw57If4l2SBGaX9ZK5jjZSJAR8kuEM NO2A== 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=lH0eWuHHiCANq4BSpJWvv00qJJn3hhUC9L40R4M73kg=; b=pz6KOVk18tyJNgfeAOmHnCauMyclYW2PIM/P6IN6I5TME7nhVLEswHqmbwCHJBeQw2 Nj2I9Jw2OZ+Kf6c4/9zPEd2CMC7/25wie23FLFmKu/p4vyxdm94Qm8xim+7sV/pBJQfY td/CGBPeNZJmZGsGjXj6/s5HQq9Lzj9VDpN+0EZA4oep1SNAYp5vUyYh7gnuJm9zwyhN Q9lK6BAbS9E0s03lS32qmxRqSnd74k+ZtrVtwrO13ff0B/CujgCw5zsFEl0iwJzkss+w ihi2cEGvLnKwfVsaziBJvGqmzCnMBe2ZKfh1IkxMWJdEyd++qcqtk/p1zn0KZdTC3VXh kdlw== X-Gm-Message-State: AGRZ1gKK46Vs/sft5dSeMDb6yAjgZQBFqznZj6xe93gJzRXX/bE6cGLP 1ddmWgH1xtHbJoJOD4Pmp9VNjkbMDzs= X-Google-Smtp-Source: AJdET5fJmAz/Erkrun47XTQOD03fsZT2RF6veLieGBkVH7Q2awM3QXsS60ET2WTEo3MiOaT1qQf9IQ== X-Received: by 2002:a24:1706:: with SMTP id 6-v6mr30592ith.16.1540924397941; Tue, 30 Oct 2018 11:33:17 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id o20-v6sm4895739itc.34.2018.10.30.11.33.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 11:33:16 -0700 (PDT) From: Jens Axboe To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 11/16] blk-mq: improve plug list sorting Date: Tue, 30 Oct 2018 12:32:47 -0600 Message-Id: <20181030183252.17857-12-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181030183252.17857-1-axboe@kernel.dk> References: <20181030183252.17857-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 Currently we only look at the software queue, but with support for multiple maps, we should also look at the hardware queue. This is important since we'll flush out the request list if either the software queue or hardware queue don't match. This sorts by software queue first, then hardware queue if that differs. Finally we sort by request location like before. This minimizes the flush points per plug list. Signed-off-by: Jens Axboe Reviewed-by: Sagi Grimberg Reviewed-by: Hannes Reinecke --- block/blk-mq.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 51b8166959b9..5a34c9374dc7 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1611,14 +1611,21 @@ void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx, spin_unlock(&ctx->lock); } -static int plug_ctx_cmp(void *priv, struct list_head *a, struct list_head *b) +static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b) { struct request *rqa = container_of(a, struct request, queuelist); struct request *rqb = container_of(b, struct request, queuelist); - return !(rqa->mq_ctx < rqb->mq_ctx || - (rqa->mq_ctx == rqb->mq_ctx && - blk_rq_pos(rqa) < blk_rq_pos(rqb))); + if (rqa->mq_ctx < rqb->mq_ctx) + return -1; + else if (rqa->mq_ctx > rqb->mq_ctx) + return 1; + else if (rqa->mq_hctx < rqb->mq_hctx) + return -1; + else if (rqa->mq_hctx > rqb->mq_hctx) + return 1; + + return blk_rq_pos(rqa) > blk_rq_pos(rqb); } void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) @@ -1633,7 +1640,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule) list_splice_init(&plug->mq_list, &list); - list_sort(NULL, &list, plug_ctx_cmp); + list_sort(NULL, &list, plug_rq_cmp); this_q = NULL; this_hctx = NULL;