Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp5078628imd; Tue, 30 Oct 2018 11:36:59 -0700 (PDT) X-Google-Smtp-Source: AJdET5cpqnJsbQ7H/bH88zWz6m1gfDVR2aWxxxFkLrdsEC1pxG9YlCA04pw7SnBUXGmGr4F24DWs X-Received: by 2002:a62:2e04:: with SMTP id u4-v6mr4192308pfu.229.1540924619407; Tue, 30 Oct 2018 11:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540924619; cv=none; d=google.com; s=arc-20160816; b=0nDydHS8v2sBjbpaYF0YY+IvhWhKJE4Af2KzgFrlDEYeD8mHg8F+RBobMtymJwWvFv nuM9tSMb5Lzrmn7EdttmwJbxZKIqD4rsCPCf7XNPpllus4RvRZs73NFwHNfvOm50K2lN v7D5NQCO90m7ya5z4JmTqy4/gFmtA0UBBg00iTtmUds8Qj1Sqd2+K31Pks5d6mWUssms 4vaMVr3QlwmDy/YfgyV00jHZXiims/NbNbuR3YgCSlRSrraa1tcGXG2DLZzbYHM+x33P 5uDcg/Wxo7VxaOVMT0rtlLKiP8Sk4sZk1OD2K1AEcEbXy4RiKuxhqD6QjNCKMgbEojvu +wlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=YaNlZPxgZjMsE6yDVY2FyfjFvXinmFQDne8Zv8Bpjm0=; b=fD/ql/M1HtbzxlEFHOV7BHTH1PbPUeIsv1CqqO/azXca52U5qtg8G2G56o63ZONTL4 l/V8kOIGFpfzrIpEN4cpyDAtDV7tN8L9K46ImHn0hblx+QxxBe4WdaUfBrC/mf7U/9OV NpSmp8Wg+H1UneROeTBzt9j4RD/YA1xCo2Kt4T16qkEApXTP6nvfAoROf169QJxadhc2 yEDfhCHa5d56C76YnRZCz1axX72PSItw5oNL/etWroXJpMIDbVrEoa5S5u2wzoXYzg3j L76gha7nMZ/hIyx6z0CtcEm848w8sndjfuc889RCVuDNWibplX9TwOK2gFezF/RddG9u +3pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=rvJN3FEp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z10-v6si24302362pgv.487.2018.10.30.11.36.36; Tue, 30 Oct 2018 11:36:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=rvJN3FEp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727739AbeJaD2w (ORCPT + 99 others); Tue, 30 Oct 2018 23:28:52 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:50837 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727870AbeJaD1r (ORCPT ); Tue, 30 Oct 2018 23:27:47 -0400 Received: by mail-it1-f194.google.com with SMTP id k206-v6so14965073ite.0 for ; Tue, 30 Oct 2018 11:33:12 -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=YaNlZPxgZjMsE6yDVY2FyfjFvXinmFQDne8Zv8Bpjm0=; b=rvJN3FEpSNBj12cWkHpNYG7i5NmARKfJSGWGLfZWELhd2ghH2qATNNTI3NmE9wB6de LvZOmj22JPpd8H4nShUmkioSmKplguqzr/kxV4D2wF5GA7EIjYBx3sIYHadXPUlpodaK aTk9KYY0EJsFCicSrCPQjTc+SJXkJWz5SIOmiiA6dx62gfeuiakNh6IgTtKsM7vjYQBJ 9/f6GzuJo8mNiAs+s45s5lJHYxmHUPkyZJKhSFRNSFrSJ/CKf7+TtsrNFBh5i11x52CP Cy745LEdaBZVaS2/t09CxGR+9OKdh2YkJUh/ZkCMO5Sr8dmh1JSOKXZyNxnUZxKueWev GxhA== 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=YaNlZPxgZjMsE6yDVY2FyfjFvXinmFQDne8Zv8Bpjm0=; b=oLF5qwwrjLfPrwlKuU/nUMiKdFl1hMvj+mQmXgYOxADhvVE78YYGSfnQw9IdLS+gj9 0ZcvNqZ9Y6UWIoj+6UNYMUnuB7La86U5RMHVkBzrjnSLsibVsah5DTnsuFPLv2jtbIi3 zGE7yMLqrB/cQKsuL94L8oZnPuKsqrapGwz7SYop7iwAUUlVYKAhPR0lzzYm9lh73Qv3 BLHAcShq0LwxsNEZbhO4fOIoiJPFsc4FNUihU7g6yNKGVYJjgJWmWKSvNd6Mirrw+X2f AwlKPAKqNSwLCnYhLGhNCnsrtXO6ZDltS3xp3ke/naeui9wk8YZx1iC/UhQ9STsOc37A 4HvQ== X-Gm-Message-State: AGRZ1gIzFVUVeC0YjOpsPicGaEhCvrnhXks3VWPBu/c/7RPW/9GhpyH9 0Hmbvv+VwLtAkbsBhUMPfCfJWg== X-Received: by 2002:a24:b303:: with SMTP id e3-v6mr19471itf.82.1540924392117; Tue, 30 Oct 2018 11:33:12 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 11:33:10 -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 08/16] blk-mq: separate number of hardware queues from nr_cpu_ids Date: Tue, 30 Oct 2018 12:32:44 -0600 Message-Id: <20181030183252.17857-9-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Bart Van Assche Signed-off-by: Jens Axboe --- 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 9d6e2f6f8ee9..1ca48cf3bbc7 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2668,6 +2668,19 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, mutex_unlock(&q->sysfs_lock); } +/* + * Maximum number of hardware 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) { @@ -2687,7 +2700,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; @@ -2699,7 +2713,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; @@ -2889,12 +2902,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; @@ -2937,7 +2951,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++) { @@ -3069,7 +3083,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; -- 2.17.1