From patchwork Fri Oct 25 16:50:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11212683 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8169F1920 for ; Fri, 25 Oct 2019 16:50:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6992921D71 for ; Fri, 25 Oct 2019 16:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409587AbfJYQuV (ORCPT ); Fri, 25 Oct 2019 12:50:21 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36233 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409570AbfJYQuU (ORCPT ); Fri, 25 Oct 2019 12:50:20 -0400 Received: by mail-pg1-f194.google.com with SMTP id 23so1906189pgk.3 for ; Fri, 25 Oct 2019 09:50:20 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=Nc1ug63CH73vTb+uKvAKYhTrY+3OfJCTIh8JbxXvNNg=; b=ctg0MbzAE1BquUuqiaUa2HyfPjxBD73oDfiHM6iat/yNau4Tat68r+5wTHs8oFdOFb 1MaULWUFFuxyVXLwFqQBgp7ab+vGSAuCS45pDzvRKt/47QtpzgW7ikka76mIRI1u2wax eyK/2CNbUpkkk2dnigYags1WrzkbR24W+KsaQAprfgm47XmA+1C4zyP8rTpvTAedQL9L p05nFYQCl5RV+BPeBzxL74Sd3k8Al3WQuQF8wEvYl1Zm0I6H3G3dlfWDjn0/D1836jVA m2Gjp5onQPrySD9gwmwqMtR/41SIsyl7PGLoOVFw/i+5k1Wyj1B+l4kkrey7WIn+VOuu 0fFw== X-Gm-Message-State: APjAAAXw+1+uf8e2hYfkm/SC1UKunlhSwFCR30vhcwk38mAdixeqkfFg ouZ5iJhy9IuuuCFXoHdk8/M= X-Google-Smtp-Source: APXvYqyOScN7zvGNB4bLBgMIjCypd17KbXq83hzT1zsAWTy3UQ3KvPmrnN6StZGaN3sENMdkaQ9s8w== X-Received: by 2002:a63:a849:: with SMTP id i9mr5580314pgp.237.1572022219580; Fri, 25 Oct 2019 09:50:19 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id c8sm4088158pfi.117.2019.10.25.09.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 09:50:18 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei , Jianchao Wang , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH v2 1/3] block: Remove the synchronize_rcu() call from __blk_mq_update_nr_hw_queues() Date: Fri, 25 Oct 2019 09:50:08 -0700 Message-Id: <20191025165010.211462-2-bvanassche@acm.org> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191025165010.211462-1-bvanassche@acm.org> References: <20191025165010.211462-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Since the blk_mq_{,un}freeze_queue() calls in __blk_mq_update_nr_hw_queues() already serialize __blk_mq_update_nr_hw_queues() against blk_mq_queue_tag_busy_iter(), the synchronize_rcu() call in __blk_mq_update_nr_hw_queues() is not necessary. Hence remove it. Note: the synchronize_rcu() call in __blk_mq_update_nr_hw_queues() was introduced by commit f5bbbbe4d635 ("blk-mq: sync the update nr_hw_queues with blk_mq_queue_tag_busy_iter"). Commit 530ca2c9bd69 ("blk-mq: Allow blocking queue tag iter callbacks") removed the rcu_read_{,un}lock() calls that correspond to the synchronize_rcu() call in __blk_mq_update_nr_hw_queues(). Reviewed-by: Ming Lei Cc: Jianchao Wang Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn Signed-off-by: Bart Van Assche --- block/blk-mq.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 8538dc415499..7528678ef41f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3242,10 +3242,6 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, list_for_each_entry(q, &set->tag_list, tag_set_list) blk_mq_freeze_queue(q); - /* - * Sync with blk_mq_queue_tag_busy_iter. - */ - synchronize_rcu(); /* * Switch IO scheduler to 'none', cleaning up the data associated * with the previous scheduler. We will switch back once we are done From patchwork Fri Oct 25 16:50:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11212681 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 228921390 for ; Fri, 25 Oct 2019 16:50:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 09B8A21D71 for ; Fri, 25 Oct 2019 16:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409600AbfJYQuh (ORCPT ); Fri, 25 Oct 2019 12:50:37 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44106 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440697AbfJYQuW (ORCPT ); Fri, 25 Oct 2019 12:50:22 -0400 Received: by mail-pl1-f195.google.com with SMTP id q16so1277413pll.11 for ; Fri, 25 Oct 2019 09:50:21 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=R6y7GYeP0zUmbxzTjL5a6O2gfkXfcoR6unQQzw6yRVc=; b=U6/FHT0c3LRpKFkP58764nBCcMpRh77Purnvu1NJSiGfWlsUzG4leXErEAQD2bEkVz XjwyONf0CphA1B96MXIUXm1u/JPZyKByue6DjyVRZh3WYFosbzcCDvvPM4UFlIgaB8xz VcvzRaara067+d1TbqrlfCNF6vUG7hpuHVH18k8helWliHgXm8EJHB1hjfnqZAhRzmxx XflYw73HK+jUDT3Pp3+ySSX4u8FYLXqUUnL1mWa8t9f05KQEIl+5oMI/Et1E66TAkgIl /ndlJcTk5B0S3wxwB6Gkhn4H6xesqTUdBiJdabIf/GRjYMAT/GtjF0Orx+8jtYuJDN7w eyUw== X-Gm-Message-State: APjAAAXYvd07Gb9mNNYTo64l/QNpPnCYjmy8u4933UbMgq5mTAnDDugL xmQ4Am6BW2MZGpWZ0F3UH94= X-Google-Smtp-Source: APXvYqzLhozGHH0NFkxTf+fwwMg2TnoelXwhRxp3Fkt0kkm+HqIevKjCD7NH/WLcHxZco+i+Ga6Xrg== X-Received: by 2002:a17:902:a581:: with SMTP id az1mr4801891plb.311.1572022221364; Fri, 25 Oct 2019 09:50:21 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id c8sm4088158pfi.117.2019.10.25.09.50.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 09:50:20 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Keith Busch , Christoph Hellwig , Ming Lei , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH v2 2/3] block: Reduce the amount of memory required per request queue Date: Fri, 25 Oct 2019 09:50:09 -0700 Message-Id: <20191025165010.211462-3-bvanassche@acm.org> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191025165010.211462-1-bvanassche@acm.org> References: <20191025165010.211462-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of always allocating at least nr_cpu_ids hardware queues per request queue, reallocate q->queue_hw_ctx if it has to grow. This patch improves behavior that was introduced by commit 868f2f0b7206 ("blk-mq: dynamic h/w context count"). Cc: Keith Busch Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Johannes Thumshirn Signed-off-by: Bart Van Assche --- block/blk-mq.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 7528678ef41f..ba09cda49953 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2761,6 +2761,23 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, int i, j, end; struct blk_mq_hw_ctx **hctxs = q->queue_hw_ctx; + if (q->nr_hw_queues < set->nr_hw_queues) { + struct blk_mq_hw_ctx **new_hctxs; + + new_hctxs = kcalloc_node(set->nr_hw_queues, + sizeof(*new_hctxs), GFP_KERNEL, + set->numa_node); + if (!new_hctxs) + return; + if (hctxs) + memcpy(new_hctxs, hctxs, q->nr_hw_queues * + sizeof(*hctxs)); + q->queue_hw_ctx = new_hctxs; + q->nr_hw_queues = set->nr_hw_queues; + kfree(hctxs); + hctxs = new_hctxs; + } + /* protect against switching io scheduler */ mutex_lock(&q->sysfs_lock); for (i = 0; i < set->nr_hw_queues; i++) { @@ -2848,12 +2865,6 @@ 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_hw_queues(set), - sizeof(*(q->queue_hw_ctx)), GFP_KERNEL, - set->numa_node); - if (!q->queue_hw_ctx) - goto err_sys_init; - INIT_LIST_HEAD(&q->unused_hctx_list); spin_lock_init(&q->unused_hctx_lock); @@ -2901,7 +2912,6 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, err_hctxs: kfree(q->queue_hw_ctx); q->nr_hw_queues = 0; -err_sys_init: blk_mq_sysfs_deinit(q); err_poll: blk_stat_free_callback(q->poll_cb); From patchwork Fri Oct 25 16:50:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11212679 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F2D81390 for ; Fri, 25 Oct 2019 16:50:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ED16021D71 for ; Fri, 25 Oct 2019 16:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409519AbfJYQuc (ORCPT ); Fri, 25 Oct 2019 12:50:32 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34325 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440789AbfJYQuX (ORCPT ); Fri, 25 Oct 2019 12:50:23 -0400 Received: by mail-pf1-f195.google.com with SMTP id b128so1958685pfa.1 for ; Fri, 25 Oct 2019 09:50:23 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=CU0k9qROSs1SMECH5+HOGD2NHrqwUXVzrsyMYyRmrwk=; b=e/4jHcxBkrWMKyCQysBzsL1IYNbABmTvAcXCQUxKFDT9QMJyvOMPtJKa0xo1PGpTIj Kfcu6EAjIhhe6l09X5kkzO7b8ANvLUxFUPrSyj+Kdoa9u0otKInaTay9QB7lr5e1FvqX LOe00aZA4CU7iuqEdaz7P1fCUSmMD9ftMTVkQ/ZNlfC5aUfEseDsppzpKo5m2wnLEVDj 5D6xBbPPClPxajpixMtiK9Awca9Kbv4GyEJEe3KB4e1OGvVt0M8SFUXTGaPNa0drHTh+ eVCozkv/GxC/gNYHWNJWUtbQ8s7TcOs/z9bqkbWnuguguxCh7eTURYAfjp91szMa31om yOWw== X-Gm-Message-State: APjAAAXo+fr/Xo9bOLxZzWSdbqJODro6JR2xYXt+tsh2kJErQ2Xpwtmr /+XfcOWfLRiJUDKV3Nh/BMI= X-Google-Smtp-Source: APXvYqz8hQoUcMKExVT6fSqCyp43/UBP4sTyOcmuT14wy6Y9Ktkx8vlkDISQ5RWwWp6QTRkwm7UG/g== X-Received: by 2002:a17:90b:153:: with SMTP id em19mr5390374pjb.22.1572022222551; Fri, 25 Oct 2019 09:50:22 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:202:4308:52a3:24b6:2c60]) by smtp.gmail.com with ESMTPSA id c8sm4088158pfi.117.2019.10.25.09.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 09:50:21 -0700 (PDT) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Keith Busch , Christoph Hellwig , Ming Lei , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH v2 3/3] block: Reduce the amount of memory used for tag sets Date: Fri, 25 Oct 2019 09:50:10 -0700 Message-Id: <20191025165010.211462-4-bvanassche@acm.org> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191025165010.211462-1-bvanassche@acm.org> References: <20191025165010.211462-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of allocating an array of size nr_cpu_ids for set->tags, allocate an array of size set->nr_hw_queues. This patch improves behavior that was introduced by commit 868f2f0b7206 ("blk-mq: dynamic h/w context count"). Reallocating tag sets from inside __blk_mq_update_nr_hw_queues() is safe because: - All request queues that share the tag sets are frozen before the tag sets are reallocated. - blk_mq_queue_tag_busy_iter() holds q->q_usage_counter while active and hence is serialized against __blk_mq_update_nr_hw_queues(). Cc: Keith Busch Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Johannes Thumshirn Signed-off-by: Bart Van Assche --- block/blk-mq.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index ba09cda49953..df41b2d16261 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2833,19 +2833,6 @@ 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, bool elevator_init) @@ -3012,6 +2999,29 @@ static int blk_mq_update_queue_map(struct blk_mq_tag_set *set) } } +static int blk_mq_realloc_tag_set_tags(struct blk_mq_tag_set *set, + int cur_nr_hw_queues, int new_nr_hw_queues) +{ + struct blk_mq_tags **new_tags; + + if (cur_nr_hw_queues >= new_nr_hw_queues) + return 0; + + new_tags = kcalloc_node(new_nr_hw_queues, sizeof(struct blk_mq_tags *), + GFP_KERNEL, set->numa_node); + if (!new_tags) + return -ENOMEM; + + if (set->tags) + memcpy(new_tags, set->tags, cur_nr_hw_queues * + sizeof(*set->tags)); + kfree(set->tags); + set->tags = new_tags; + set->nr_hw_queues = new_nr_hw_queues; + + return 0; +} + /* * Alloc a tag set to be associated with one or more request queues. * May fail with EINVAL for various error conditions. May adjust the @@ -3065,9 +3075,7 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set) if (set->nr_maps == 1 && set->nr_hw_queues > nr_cpu_ids) set->nr_hw_queues = nr_cpu_ids; - set->tags = kcalloc_node(nr_hw_queues(set), sizeof(struct blk_mq_tags *), - GFP_KERNEL, set->numa_node); - if (!set->tags) + if (blk_mq_realloc_tag_set_tags(set, 0, set->nr_hw_queues) < 0) return -ENOMEM; ret = -ENOMEM; @@ -3108,7 +3116,7 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set) { int i, j; - for (i = 0; i < nr_hw_queues(set); i++) + for (i = 0; i < set->nr_hw_queues; i++) blk_mq_free_map_and_requests(set, i); for (j = 0; j < set->nr_maps; j++) { @@ -3266,6 +3274,10 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, blk_mq_sysfs_unregister(q); } + if (blk_mq_realloc_tag_set_tags(set, set->nr_hw_queues, nr_hw_queues) < + 0) + goto reregister; + prev_nr_hw_queues = set->nr_hw_queues; set->nr_hw_queues = nr_hw_queues; blk_mq_update_queue_map(set); @@ -3282,6 +3294,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, blk_mq_map_swqueue(q); } +reregister: list_for_each_entry(q, &set->tag_list, tag_set_list) { blk_mq_sysfs_register(q); blk_mq_debugfs_register_hctxs(q);