From patchwork Mon Oct 29 16:37:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10659703 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 1F41613B5 for ; Mon, 29 Oct 2018 16:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04E412967A for ; Mon, 29 Oct 2018 16:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED91F29C43; Mon, 29 Oct 2018 16:38:01 +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 8576D29C49 for ; Mon, 29 Oct 2018 16:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728273AbeJ3B1W (ORCPT ); Mon, 29 Oct 2018 21:27:22 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:34139 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728271AbeJ3B1V (ORCPT ); Mon, 29 Oct 2018 21:27:21 -0400 Received: by mail-it1-f196.google.com with SMTP id e81-v6so10683966itc.1 for ; Mon, 29 Oct 2018 09:37:59 -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=CCxQ1w7oEfeYNp97sRQwoZGVpyu0hoStQAxbQ0x4cMs=; b=1x9QymbKSfQAQsEaeunWt42kHkrjMbrs37kzbMSUPQ6kQQVhCOLo4tC9Q72IzkoGen /y4yFpjcwH3Kvhkcu1BrpwfjByT85VqZX3zMwQ+fcxS2SI/d4XcOOmwdLVCtH8DEWvro Y8BygKmSvW4drwMIfl9l7x/tIDz+fXl1nx0WaNXZH5B/pYlwvoix1PAQGftREplo4TLe 6uGNwji5R2mRnR7Dt9jkEv9i9DEtPuhAHGeeTEaL5VfAouZF3i01okwpF9lU8VI5+z6T Vvto4i83rswwrASfhDL3trpevQ4lkcC8OUX9i59RmY6wvrwb0j+Hs4ZEus4phy++AiAk ycvQ== 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=CCxQ1w7oEfeYNp97sRQwoZGVpyu0hoStQAxbQ0x4cMs=; b=pU4lPoCMO1Q2X+G9n4LXizEKZ9b4ehWtI7q6p4/V2efj52c+d7K2TwCRliMIMnXZPj Hi5Jz5cVoKe6ov3jZ9i7l/3oOXzAOQKWJ9PqTttGCaypX8cSRuGUnJCjkn1KBWGPDFmo /4VdtrEIE9cFqpKJVQRva9WG7JIVBBbnfqBVXmN2cF8KEAtH7UClExj8G2ZQlH/IFF4w hTEbxVNpxkkfVCaDuSSqDsWh3wdjfIEiMfSOYUAvgYP7kmHdsSeTJ+EsKfbgwSg2dd1g SM5rJ5gI49wpFf9lSMZg/+zBvRRjJ9EcSjqRnYxua9dmYuHdERwHI7WkI4lTtKFZluXT +ivA== X-Gm-Message-State: AGRZ1gKiZktbu1IDm5cnnEwpg/cC0DbxnDDpQGGH2VxExI8YllI3V7J8 R3Z94Y14Lr2TEQNXvS7qxpjG/F9Vljc= X-Google-Smtp-Source: AJdET5fmxR4SW5z/LgB6ktrnLBgw6BrY449jiuxnWGCX46++qkiTSZHw10Ttf2eU3HjE+B9sXt3d8w== X-Received: by 2002:a24:1a56:: with SMTP id 83-v6mr6138029iti.135.1540831079149; Mon, 29 Oct 2018 09:37:59 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Oct 2018 09:37:57 -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 08/14] blk-mq: separate number of hardware queues from nr_cpu_ids Date: Mon, 29 Oct 2018 10:37:32 -0600 Message-Id: <20181029163738.10172-9-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 With multiple maps, nr_cpu_ids is no longer the maximum number of hardware queues we support on a given devices. The initializer of the tag_set can have set ->nr_hw_queues larger than the available number of CPUs, since we can exceed that with multiple queue maps. Reviewed-by: Hannes Reinecke Signed-off-by: Jens Axboe Reviewed-by: Bart Van Assche --- block/blk-mq.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 0fab36372ace..60a951c4934c 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2663,6 +2663,19 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, mutex_unlock(&q->sysfs_lock); } +/* + * Maximum number of queues we support. For single sets, we'll never have + * more than the CPUs (software queues). For multiple sets, the tag_set + * user may have set ->nr_hw_queues larger. + */ +static unsigned int nr_hw_queues(struct blk_mq_tag_set *set) +{ + if (set->nr_maps == 1) + return nr_cpu_ids; + + return max(set->nr_hw_queues, nr_cpu_ids); +} + struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, struct request_queue *q) { @@ -2682,7 +2695,8 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, /* init q->mq_kobj and sw queues' kobjects */ blk_mq_sysfs_init(q); - q->queue_hw_ctx = kcalloc_node(nr_cpu_ids, sizeof(*(q->queue_hw_ctx)), + q->nr_queues = nr_hw_queues(set); + q->queue_hw_ctx = kcalloc_node(q->nr_queues, sizeof(*(q->queue_hw_ctx)), GFP_KERNEL, set->numa_node); if (!q->queue_hw_ctx) goto err_percpu; @@ -2694,7 +2708,6 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, INIT_WORK(&q->timeout_work, blk_mq_timeout_work); blk_queue_rq_timeout(q, set->timeout ? set->timeout : 30 * HZ); - q->nr_queues = nr_cpu_ids; q->tag_set = set; q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT; @@ -2884,12 +2897,13 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set) set->queue_depth = min(64U, set->queue_depth); } /* - * There is no use for more h/w queues than cpus. + * There is no use for more h/w queues than cpus if we just have + * a single map */ - if (set->nr_hw_queues > nr_cpu_ids) + if (set->nr_maps == 1 && set->nr_hw_queues > nr_cpu_ids) set->nr_hw_queues = nr_cpu_ids; - set->tags = kcalloc_node(nr_cpu_ids, sizeof(struct blk_mq_tags *), + set->tags = kcalloc_node(nr_hw_queues(set), sizeof(struct blk_mq_tags *), GFP_KERNEL, set->numa_node); if (!set->tags) return -ENOMEM; @@ -2932,7 +2946,7 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set) { int i, j; - for (i = 0; i < nr_cpu_ids; i++) + for (i = 0; i < nr_hw_queues(set); i++) blk_mq_free_map_and_requests(set, i); for (j = 0; j < set->nr_maps; j++) { @@ -3064,7 +3078,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, lockdep_assert_held(&set->tag_list_lock); - if (nr_hw_queues > nr_cpu_ids) + if (set->nr_maps == 1 && nr_hw_queues > nr_cpu_ids) nr_hw_queues = nr_cpu_ids; if (nr_hw_queues < 1 || nr_hw_queues == set->nr_hw_queues) return;