From patchwork Thu Apr 13 06:28:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13209805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4699AC77B61 for ; Thu, 13 Apr 2023 06:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjDMG2p (ORCPT ); Thu, 13 Apr 2023 02:28:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbjDMG2o (ORCPT ); Thu, 13 Apr 2023 02:28:44 -0400 Received: from out-31.mta1.migadu.com (out-31.mta1.migadu.com [IPv6:2001:41d0:203:375::1f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A242683FF for ; Wed, 12 Apr 2023 23:28:39 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1681367316; 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=egK6cQcoNaTUC/dkRvlJHjCoro533vXXKI06JsMHHhk=; b=OLgzKgqo5RxBuxyyghem3Zr+nBfFIoz4x9MKZJJi9MVi/e3ETG7sXqdslYi9DYw1I1X1nH vIKa37IM3boWd8Vmt0udwAuuErkdq+EvP+gwE3dG//cSdwtDfTWQEFrVepocn8VC0wAGXk OdeaTC1QfLAE/f+X4ExEbHVfkF7qUsc= From: chengming.zhou@linux.dev To: axboe@kernel.dk, tj@kernel.org Cc: josef@toxicpanda.com, osandov@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Chengming Zhou , stable@vger.kernel.org Subject: [PATCH v2 1/2] blk-stat: fix QUEUE_FLAG_STATS clear Date: Thu, 13 Apr 2023 14:28:04 +0800 Message-Id: <20230413062805.2081970-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Chengming Zhou We need to set QUEUE_FLAG_STATS for two cases: 1. blk_stat_enable_accounting() 2. blk_stat_add_callback() So we should clear it only when ((q->stats->accounting == 0) && list_empty(&q->stats->callbacks)). blk_stat_disable_accounting() only check if q->stats->accounting is 0 before clear the flag, this patch fix it. Also add list_empty(&q->stats->callbacks)) check when enable, or the flag is already set. The bug can be reproduced on kernel without BLK_DEV_THROTTLING (since it unconditionally enable accounting, see the next patch). # cat /sys/block/sr0/queue/scheduler none mq-deadline [bfq] # cat /sys/kernel/debug/block/sr0/state SAME_COMP|IO_STAT|INIT_DONE|STATS|REGISTERED|NOWAIT|30 # echo none > /sys/block/sr0/queue/scheduler # cat /sys/kernel/debug/block/sr0/state SAME_COMP|IO_STAT|INIT_DONE|REGISTERED|NOWAIT # cat /sys/block/sr0/queue/wbt_lat_usec 75000 We can see that after changing elevator from "bfq" to "none", "STATS" flag is lost even though WBT callback still need it. Fixes: 68497092bde9 ("block: make queue stat accounting a reference") Cc: # v5.17+ Signed-off-by: Chengming Zhou Acked-by: Tejun Heo --- block/blk-stat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/blk-stat.c b/block/blk-stat.c index 74a1a8c32d86..bc7e0ed81642 100644 --- a/block/blk-stat.c +++ b/block/blk-stat.c @@ -190,7 +190,7 @@ void blk_stat_disable_accounting(struct request_queue *q) unsigned long flags; spin_lock_irqsave(&q->stats->lock, flags); - if (!--q->stats->accounting) + if (!--q->stats->accounting && list_empty(&q->stats->callbacks)) blk_queue_flag_clear(QUEUE_FLAG_STATS, q); spin_unlock_irqrestore(&q->stats->lock, flags); } @@ -201,7 +201,7 @@ void blk_stat_enable_accounting(struct request_queue *q) unsigned long flags; spin_lock_irqsave(&q->stats->lock, flags); - if (!q->stats->accounting++) + if (!q->stats->accounting++ && list_empty(&q->stats->callbacks)) blk_queue_flag_set(QUEUE_FLAG_STATS, q); spin_unlock_irqrestore(&q->stats->lock, flags); } From patchwork Thu Apr 13 06:28:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13209806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E631C77B61 for ; Thu, 13 Apr 2023 06:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjDMG2w (ORCPT ); Thu, 13 Apr 2023 02:28:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjDMG2v (ORCPT ); Thu, 13 Apr 2023 02:28:51 -0400 Received: from out-28.mta1.migadu.com (out-28.mta1.migadu.com [IPv6:2001:41d0:203:375::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C43E7EF1 for ; Wed, 12 Apr 2023 23:28:42 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1681367321; 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: in-reply-to:in-reply-to:references:references; bh=6uuLZUtgeUwzy7HQkKWbC2Y+wAfW1jsm3UvSSwpC9GQ=; b=KdB0OD7JaB79oRR+5d+zVaBx/OkQHm1RI0hi4MuiY0fVYA0qanpEgKP47Ya07PQz7534/g aGRUTTQBYv29sY1tMk+2zU0xsV6T3eukaU7MRE/bcN8yoQ0O50yRYeqmGlUxm0L9kLz0oN tla8TtElBNB6kkQ7rbtyJB2145QiMiA= From: chengming.zhou@linux.dev To: axboe@kernel.dk, tj@kernel.org Cc: josef@toxicpanda.com, osandov@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Chengming Zhou Subject: [PATCH v2 2/2] blk-throttle: only enable blk-stat when BLK_DEV_THROTTLING_LOW Date: Thu, 13 Apr 2023 14:28:05 +0800 Message-Id: <20230413062805.2081970-2-chengming.zhou@linux.dev> In-Reply-To: <20230413062805.2081970-1-chengming.zhou@linux.dev> References: <20230413062805.2081970-1-chengming.zhou@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Chengming Zhou blk_throtl_register() will unconditionally enable blk-stat for gendisk when register, even when we have no BLK_DEV_THROTTLING_LOW config. Since the kernel always has only BLK_DEV_THROTTLING config and the BLK_DEV_THROTTLING_LOW config is still in EXPERIMENTAL state, we can just skip blk-stat when !BLK_DEV_THROTTLING_LOW. Signed-off-by: Chengming Zhou Acked-by: Tejun Heo --- block/blk-throttle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 47e9d8be68f3..3c07c9cfa70a 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -2439,11 +2439,12 @@ void blk_throtl_register(struct gendisk *disk) #ifndef CONFIG_BLK_DEV_THROTTLING_LOW /* if no low limit, use previous default */ td->throtl_slice = DFL_THROTL_SLICE_HD; -#endif +#else td->track_bio_latency = !queue_is_mq(q); if (!td->track_bio_latency) blk_stat_enable_accounting(q); +#endif } #ifdef CONFIG_BLK_DEV_THROTTLING_LOW