Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2284522rda; Tue, 24 Oct 2023 19:58:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmlYcRCR/Jdfk0lx9q6dnwsLbjYLVM3UYozCo5V4GXBjUqYZWpE8iAusPiBR0HgEfOK2Md X-Received: by 2002:a0d:d587:0:b0:5a7:be3f:c451 with SMTP id x129-20020a0dd587000000b005a7be3fc451mr13239175ywd.3.1698202734635; Tue, 24 Oct 2023 19:58:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698202734; cv=none; d=google.com; s=arc-20160816; b=ez3FEi6ySn/4zZzp2rlj2T5gg6I2VuCuZGn/2R8HX+bFDZaJZpjflKQwWtLDYL2G2V GFu6sHT85/HtM1IkE20v9/L0fkYz2YenT8FfuDXGE+o/hLts2/DZwfWXOwK8yRw0wm/Y 67NEMPbggDCcRrQIiFbkVtOGIyRCKIK3Q8I0pS+/M4VcZkaJGSZBKl88f/rUdgTiaAv0 Br0FAfYeGK/qH9FP96bvFXFTW7yp829RxwbZaFuBifRGowef5IgBSE2R1FyJX1mMkZkl tGpXb46rC7TTitFTaLrCRL8iMYvrs/O2AsQVwyelvSbNaB8yzvENxuhXTq4NZpwE1801 6F5Q== 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=hBy/IOVULBLpWvlSTWRdaYyj/wgoU15vxkhYAJo7MDQ=; fh=dA1CNY9t1IKzuC6Od2a3/x9aDCoZGNfmTY2lyYCPDdA=; b=RMsDS+DaSkE2MeAxku+46P/RTzR7mGgcmm3CaeET8MTqvLECGrjG3EKOpo/09JDPEs X3eyKDlhqruG8T2qh8NthSGf2NbEH+1kWR90DXdJFi+KfbxYzzTJFnK8TKoYcM6QlLGn kOrooTJYIUxwanc4tJATO+2TE1qkf2HnEXwVA3dZ4Ry3Q5pPhpdrQC6eT4s5rIqfThoy E0MH/J5RJZubTK5MOmRjHzjIKEiPd/pWGxGLDkcoJJEbg61p4H2Eng/dTJqDxTrx+nea UxA2hdgk1KCIIFYvFnXxYBAgpvfr0auW4nZPVd6PyR4ldBP8bXz3e11R1edlgAEDNXqo mfsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XcZt9zVn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c190-20020a814ec7000000b005a7bbdb6b38si9550148ywb.312.2023.10.24.19.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 19:58:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XcZt9zVn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id EC75E802571C; Tue, 24 Oct 2023 19:58:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232229AbjJYC6r (ORCPT + 99 others); Tue, 24 Oct 2023 22:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjJYC6q (ORCPT ); Tue, 24 Oct 2023 22:58:46 -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 1D4E811D for ; Tue, 24 Oct 2023 19:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698202679; 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=hBy/IOVULBLpWvlSTWRdaYyj/wgoU15vxkhYAJo7MDQ=; b=XcZt9zVnUPs1vuul8HILlcltGrCSdYV+JztIO0VT0zgSgmQ0X5pieJ3AfMNL+4cCW1H/vP DJ0XzOGkR+bCk0maeQ76nur1bQu7r2GzZkcAXnkTzywe0zqCjQ6k9Z4ejkChkoS4NJhRw6 81e0tXvMOjb8JysDPPR6uk6SxwANeYE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-459-7CjZFFHcN9GmebVuhiMhlg-1; Tue, 24 Oct 2023 22:57:48 -0400 X-MC-Unique: 7CjZFFHcN9GmebVuhiMhlg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4DB51185A785; Wed, 25 Oct 2023 02:57:48 +0000 (UTC) Received: from localhost (unknown [10.72.120.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A2D41C060AE; Wed, 25 Oct 2023 02:57:46 +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 , Bart Van Assche Subject: [PATCH V3] blk-mq: don't schedule block kworker on isolated CPUs Date: Wed, 25 Oct 2023 10:57:37 +0800 Message-ID: <20231025025737.358756-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 19:58:53 -0700 (PDT) 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 Cc: Bart Van Assche Signed-off-by: Ming Lei --- V3: - avoid to check invalid cpu as reported by Bart - take current cpu(to be offline, not done yet) into account - simplify blk_mq_hctx_has_online_cpu() V2: - remove module parameter, meantime use queue map to check if all cpus in one hctx are offline block/blk-mq.c | 51 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index e2d11183f62e..4556978ce71b 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -2158,7 +2159,11 @@ static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx) bool tried = false; int next_cpu = hctx->next_cpu; - if (hctx->queue->nr_hw_queues == 1) + /* + * In case of single queue or no allowed CPU for scheduling + * worker, don't bound our worker with any CPU + */ + if (hctx->queue->nr_hw_queues == 1 || next_cpu >= nr_cpu_ids) return WORK_CPU_UNBOUND; if (--hctx->next_cpu_batch <= 0) { @@ -3459,14 +3464,30 @@ 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, + unsigned int this_cpu) { - 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; + enum hctx_type type = hctx->type; + 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_online_cpu(cpu) { + struct blk_mq_hw_ctx *h = blk_mq_map_queue_type(hctx->queue, + type, cpu); + + if (h != hctx) + continue; + + /* this current CPU isn't put offline yet */ + if (this_cpu != cpu) + return true; + } + + return false; } static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node) @@ -3474,8 +3495,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, cpu)) return 0; /* @@ -3883,6 +3903,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. @@ -3909,6 +3931,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 */ -- 2.41.0