Message ID | 20230412160754.1981705-1-chengming.zhou@linux.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp465445vqo; Wed, 12 Apr 2023 09:44:48 -0700 (PDT) X-Google-Smtp-Source: AKy350aNYVCnXjx+Sfv4VkOL7rVtGqqPWJNORlM0ykLOW+zylHavm8taVSwQpPc68H2ZGx6cYPND X-Received: by 2002:a50:fc0f:0:b0:504:98ea:31e4 with SMTP id i15-20020a50fc0f000000b0050498ea31e4mr12676639edr.4.1681317888127; Wed, 12 Apr 2023 09:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681317888; cv=none; d=google.com; s=arc-20160816; b=Eptb7GeWT2otVOSw3iQnIzldDstNNNC46Bwby1whcEpQnvXTIHYvqRjoJLhiYyNuwG DMlcVeXrvK9A3Gp1hIG9I5amPWkI8oJGs8QgIKeYw+uEGtBYZR6SiPHJbf2qe5Cgs+gg yoN8P6seF0O4csr0SIUJKLMSmO2PNXJmkC7Fop5tS+SLrR0MpB+beN3nGXC0kgbnIwh0 tnZi1a8WL3QTEGOfnT8hEMguxXZu5OLQGOkbQLuslOFZVk5daoXAISCb5jWSNAdQZutr BtKCGoxVo+BTiIph/qdpmEr1ioAsChHdUAE14qCIKoXfp6wP83hEvvsza1EnFZHxA2xi Ej0g== 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=YI/qDpTMRdMgkTJuLjq2rEZXaIXEU3z1owrkp+3opps=; b=kICdgY7tCfrftoxCS8c7SFXzEWr1HkOUtmuooRn4pOjw9EtEHw4vdcVT+x7R5N3r4P kErW78GPtQZL8YhLzPIWHNvYSMoeFMehKpYF3sL5hb4VLaiORA1OnJwBNrjRrA672A/f +NicUYl9qousd2DSetS3La5Y7eEySufoO4+okgQ/Uqgpr7quOJjvNfb81E9UEOBv71Te h1uLmFS6YmA5sKtl5qznU6ug4RFkNv6CxblIulROc9EWR/8DahwbhXVDdTFBe4F6oq4i Zv3ilniymUaBVjsVkphB3BStoK4vYON9GV4JbF3UbhexqyQkZTTOiQ7xOmmitZVEdYaZ nVcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ou71pWVf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a056402020200b005049b7f3dcasi7610767edv.661.2023.04.12.09.44.23; Wed, 12 Apr 2023 09:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ou71pWVf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbjDLQPY (ORCPT <rfc822;peter110.wang@gmail.com> + 99 others); Wed, 12 Apr 2023 12:15:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbjDLQPV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 12 Apr 2023 12:15:21 -0400 X-Greylist: delayed 393 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 12 Apr 2023 09:15:10 PDT Received: from out-14.mta0.migadu.com (out-14.mta0.migadu.com [91.218.175.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53FF56A5A for <linux-kernel@vger.kernel.org>; Wed, 12 Apr 2023 09:15:09 -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=1681315714; 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=YI/qDpTMRdMgkTJuLjq2rEZXaIXEU3z1owrkp+3opps=; b=ou71pWVf5VT9CbBBk9if3KGgvw/QwtAA4Qyb6AjKM61VVmqQPp3TudZiYdL6I9cZ0krY9u Vbv1Oz0VBiydJUZ5MpaYEe5+l3EnwB5Dh6R19Q96tBfvtqQBsT75c2SsTW9cmZsJ5x64VR 2OYkq5pZE6L72eC6MABobv5TuFFSoaE= From: chengming.zhou@linux.dev To: axboe@kernel.dk, tj@kernel.org Cc: josef@toxicpanda.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Chengming Zhou <zhouchengming@bytedance.com> Subject: [PATCH 1/2] blk-stat: fix QUEUE_FLAG_STATS clear Date: Thu, 13 Apr 2023 00:07:53 +0800 Message-Id: <20230412160754.1981705-1-chengming.zhou@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762989585845621443?= X-GMAIL-MSGID: =?utf-8?q?1762989585845621443?= |
Series |
[1/2] blk-stat: fix QUEUE_FLAG_STATS clear
|
|
Commit Message
Chengming Zhou
April 12, 2023, 4:07 p.m. UTC
From: Chengming Zhou <zhouchengming@bytedance.com> 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. Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> --- block/blk-stat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Thu, Apr 13, 2023 at 12:07:53AM +0800, chengming.zhou@linux.dev wrote: > From: Chengming Zhou <zhouchengming@bytedance.com> > > 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. > > Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> Acked-by: Tejun Heo <tj@kernel.org> It'd be useful to explicitly illustrate the buggy behavior in the description (e.g. if you do X, Y and then Z, then X incorrectly loses accounting). Can you also please add the appropriate stable cc? Thanks.
On 2023/4/13 01:12, Tejun Heo wrote: > On Thu, Apr 13, 2023 at 12:07:53AM +0800, chengming.zhou@linux.dev wrote: >> From: Chengming Zhou <zhouchengming@bytedance.com> >> >> 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. >> >> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> > > Acked-by: Tejun Heo <tj@kernel.org> > > It'd be useful to explicitly illustrate the buggy behavior in the > description (e.g. if you do X, Y and then Z, then X incorrectly loses Yes, I will add below buggy behavior in the next version: This bug can be reproduced as below on kernel without BLK_DEV_THROTTLING (since it will unconditionally enable accounting, see the second 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. > accounting). Can you also please add the appropriate stable cc? Ok, will do. Thanks. > > Thanks. >
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); }