From patchwork Fri Oct 13 12:47:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 152576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1865182vqb; Fri, 13 Oct 2023 05:49:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqj6NesGmqfvminbfJBUc/2z616V1VkhV/SnnnSvJ0+h6xzWqbm9VLqZnxlQWs5N7PH8F8 X-Received: by 2002:a92:d9c4:0:b0:349:4e1f:e9a0 with SMTP id n4-20020a92d9c4000000b003494e1fe9a0mr26571412ilq.2.1697201387103; Fri, 13 Oct 2023 05:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697201387; cv=none; d=google.com; s=arc-20160816; b=kHFJEhTwQBvPRaNfRv1hK9JvjYG9+bBON4PDM0dAZKQBiAu+ooA/40yxNsgHB5RPbS qyoN5bVhElca3FPqI5b4ppUNQjLT9q2U9MRGLJ0BanQ1b6e90mH4w9q18aou7IYiZBKC WSQIn7RGdh3AEIIGUr9NbTFmf52czHPfD0lS6V85IV/9a/WKN+TLCyYHagcIPu91DQlR CFUxPl2yt/1nLJpYWqNxC4lbwU3LjTOxieKL/YTPS7uNtObSnf8lvdyTzsKvFuQvRKaO sX5AlureWk5HI3Aocqfjff6ekQZ6xYF3r40NmD6pKVZEkRmuioaJX57cN3o0ZCS1ETIa OIAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=h78T/7NPGQz52SHwxHI3clyF7jiR025tvOcU1xIze+A=; fh=6/y0Z0KJXRU5sW8kNtvGh/4WXOLRsuMr64rBIcQVNSQ=; b=s8yAgH0P1IA5yThQr8pVefVAqotzIVl+i1eLMK3qjKtpOScQokG4Ml0pseb9wzsIVO MnXMWjI6Jg4cYZ9wjuSqqjLREYqsIuqkEQlcJQyG/UJxUzYKpY9t2GKMuFkWO1xLG4j4 jF+iKzummxMWDU6jjtOMGUCLXfPvmaDpxa7fcs8A9vPfOqhvH3eb6N7Km65FEK3Tt2ZL z+tOyo4Dxeu+KFaYk0QMHCBdtUmNnSW9Za15IvrsIswF7LclI50D23ajyOmARZAT+lPk PsC0/6CosvaEiOwf/PYb18oabxAsyHfvT3kf1c7ceO0IoS/5kwk2KKjoC3bJoX3XZRmf ICOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FRPdpewy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k6-20020a635606000000b00565e509dc75si4316074pgb.359.2023.10.13.05.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 05:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FRPdpewy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BD1E283B2E00; Fri, 13 Oct 2023 05:49:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231658AbjJMMtB (ORCPT + 19 others); Fri, 13 Oct 2023 08:49:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjJMMs7 (ORCPT ); Fri, 13 Oct 2023 08:48:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED108BE for ; Fri, 13 Oct 2023 05:48:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697201291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=h78T/7NPGQz52SHwxHI3clyF7jiR025tvOcU1xIze+A=; b=FRPdpewyp5EOGrYQwJt5n8PRMABbAo3+E2zVJgqT236jBdRCSwtqaZOqtK2RMzKI0Aqab6 Sce2WJbzorrFBAb3sHB12dEQxEtNAw05cN8oxQMtlTzOflfWy2l9lwdfAIOLAaXAUMg5x8 DQwwEHUN8g8mCdmdcH0ZBMAynkMuLyk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-0i1UD0zaOym2JiTld1dkKQ-1; Fri, 13 Oct 2023 08:48:08 -0400 X-MC-Unique: 0i1UD0zaOym2JiTld1dkKQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 921211C00D21; Fri, 13 Oct 2023 12:48:07 +0000 (UTC) Received: from localhost (unknown [10.72.120.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FA2D492BFA; Fri, 13 Oct 2023 12:48:06 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, Tejun Heo , linux-kernel@vger.kernel.org, Ming Lei , Juri Lelli , Andrew Theurer , Joe Mario , Sebastian Jug , Frederic Weisbecker Subject: [PATCH V2] blk-mq: don't schedule block kworker on isolated CPUs Date: Fri, 13 Oct 2023 20:47:58 +0800 Message-ID: <20231013124758.1492796-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 13 Oct 2023 05:49:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779644642046904480 X-GMAIL-MSGID: 1779644642046904480 Kernel parameter of `isolcpus=` or 'nohz_full=' are used for isolating CPUs for specific task, and user often won't want block IO to disturb these CPUs, also long IO latency may be caused if blk-mq kworker is scheduled on these isolated CPUs. Kernel workqueue only respects this limit for WQ_UNBOUND, for bound wq, the responsibility should be on wq user. So don't not run block kworker on isolated CPUs by ruling out isolated CPUs from hctx->cpumask. Meantime in cpuhp handler, use queue map to check if all CPUs in this hw queue are offline, this way can avoid any cost in fast IO code path. Cc: Juri Lelli Cc: Andrew Theurer Cc: Joe Mario Cc: Sebastian Jug Cc: Frederic Weisbecker Signed-off-by: Ming Lei Tested-by: Joe Mario --- V2: - remove module parameter, meantime use queue map to check if all cpus in one hctx are offline block/blk-mq.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index ec922c6bccbe..91055bdc4426 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -3476,14 +3477,27 @@ static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx) return data.has_rq; } -static inline bool blk_mq_last_cpu_in_hctx(unsigned int cpu, - struct blk_mq_hw_ctx *hctx) +static bool blk_mq_hctx_has_online_cpu(struct blk_mq_hw_ctx *hctx) { - if (cpumask_first_and(hctx->cpumask, cpu_online_mask) != cpu) - return false; - if (cpumask_next_and(cpu, hctx->cpumask, cpu_online_mask) < nr_cpu_ids) - return false; - return true; + struct blk_mq_tag_set *tag_set = hctx->queue->tag_set; + int cpu; + + /* + * hctx->cpumask has rule out isolated CPUs, but userspace still + * might submit IOs on these isolated CPUs, so use queue map to + * check if all CPUs mapped to this hctx are offline + */ + for_each_possible_cpu(cpu) { + unsigned idx = tag_set->map[hctx->type].mq_map[cpu]; + + if (idx != hctx->queue_num) + continue; + + if (cpu_online(cpu)) + return true; + } + + return false; } static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node) @@ -3491,8 +3505,7 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node) struct blk_mq_hw_ctx *hctx = hlist_entry_safe(node, struct blk_mq_hw_ctx, cpuhp_online); - if (!cpumask_test_cpu(cpu, hctx->cpumask) || - !blk_mq_last_cpu_in_hctx(cpu, hctx)) + if (blk_mq_hctx_has_online_cpu(hctx)) return 0; /* @@ -3900,6 +3913,8 @@ static void blk_mq_map_swqueue(struct request_queue *q) } queue_for_each_hw_ctx(q, hctx, i) { + int cpu; + /* * If no software queues are mapped to this hardware queue, * disable it and free the request entries. @@ -3926,6 +3941,15 @@ static void blk_mq_map_swqueue(struct request_queue *q) */ sbitmap_resize(&hctx->ctx_map, hctx->nr_ctx); + /* + * rule out isolated CPUs from hctx->cpumask for avoiding to + * run wq worker on isolated CPU + */ + for_each_cpu(cpu, hctx->cpumask) { + if (cpu_is_isolated(cpu)) + cpumask_clear_cpu(cpu, hctx->cpumask); + } + /* * Initialize batch roundrobin counts */