Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2090303rwr; Sat, 6 May 2023 04:52:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7UJLk5cZLQbo/mx2alSqAyXMF6n3AHa3DPOBd3LGltpMBRXJuJtffJH9LgP+pvIjpZ5KO0 X-Received: by 2002:a17:903:32c2:b0:1aa:e938:3ddf with SMTP id i2-20020a17090332c200b001aae9383ddfmr5338900plr.7.1683373961640; Sat, 06 May 2023 04:52:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683373961; cv=none; d=google.com; s=arc-20160816; b=kNwbdrE/6TPgbCXF4sVPiInqEA9e3Pl4WkMai2ByIovnEGmTMcKxxpRv2+w9pfmQjw Abpyfp7yrIkQ7r1/t2VSeRb5IMWNqXmJJNZhHhKgqDAVpbOe/3HwUIhtLTz+3NKeeyTu yf4KjPxgSSpMoyUfcOJYfDbYYVJDTMBL8V54j7+sUjPwU1t6lPyX16zqLaP496ulm6Xi xxUQrtBku+wy0QoNGAotwMQx8VXKD+VE93M3AO7m01vJ5K5pO2wsjaLznqW1ySsIsoPY vHTxgrI4yav1tLYkdQ4SkiDn4srNI62uNg5kzWcA59/mbExGaDAeECKX0rdH9oRH5c7p YjKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LHpyysAD0KT29d8ObzyF//DXpS+COhpwRCE79w2kL7U=; b=AP2Yed0TQGnnBczzxyLWREUuM+rTQ86iQoC6/UfKoK9a17O6HHqAVus2FoZzN60emW qIkartiFSPzijp4GHGJdSaNeA6qfmpwj6IK7iCU2IEkuL+csK6kPjZ+sLB1I7zrVgMrf pIv/K+817o2kSDe5XIu/qCf8VpVsyuZboZzQQTaOdvFBJqEXoirizLZ4ijPAMOd8B0ui +VI7DpTmVFrhYvXSQdlHfW7iqtdfVS5165adBRcmoUJyKvONptbYxSdb9Ocq4ZJ+02pp XsRW1VzmrSZprzHHZFhHgFWEQxVIS5rwOO7iLsqacRUgymEnPI2XMoEZq9X1x1ixS7up oW7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b="qQKY/TVz"; 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=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a17090ade0500b00250252e39besi3881341pjv.135.2023.05.06.04.52.26; Sat, 06 May 2023 04:52:41 -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=@canonical.com header.s=20210705 header.b="qQKY/TVz"; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbjEFLoo (ORCPT + 99 others); Sat, 6 May 2023 07:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbjEFLok (ORCPT ); Sat, 6 May 2023 07:44:40 -0400 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E4BCA243 for ; Sat, 6 May 2023 04:44:38 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (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 smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 6D0533F481 for ; Sat, 6 May 2023 11:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1683373476; bh=LHpyysAD0KT29d8ObzyF//DXpS+COhpwRCE79w2kL7U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=qQKY/TVz6NbLNXDX1WAg0MuJP6K37kRnAsMAb1lUYLoUwrOodJDM50s2EpKrbN9LF cL1sNDwhvA40upc7fVVuph/xdcdM/yp14UpxsiZcKiJT/w9ZZ1qUZeAydvb3EN7s8+ WAOdYD1VCHHhPKSJOS+zPRaYJz11TGiEsNwrk70QPc0cYGNTBBjbaAyuq4VnP6eZSG 7s2+v+X4Wt0ccbWfirKhsREpaV6OC1+TLNEnYZRStz8CVnRt13dfAT+ZZoz8rXXBL4 kJivIi36fVuCJisSWwlK6rjjNL12LU5wYr9kU68lfxRFMxn2GpFvHej9pnfJE1+Ai1 76/rpEbL/NbXg== Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-30634323dfeso986996f8f.3 for ; Sat, 06 May 2023 04:44:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683373476; x=1685965476; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LHpyysAD0KT29d8ObzyF//DXpS+COhpwRCE79w2kL7U=; b=SMCOGkMywUyGvwbD50WRR4H8tKm0vdz+Ecpkixt19wXsuM7/q/s9JQwxu4L2QbWjy3 rU//YiW20wK8Im4sDVG9J9qzXdxTDKiSb92bhUWcqByzRxj2fF7nM1SD8MCndzpuZYzV tvRmr+ZH4QZSZK9+JxvIr5njFUAA2tRO34iIEh+poUEAikd7GBqTtl9udzOPsI4aQ5tz hy1kSnovoHGdOCCtfU06cx7H7q1goMOGFKIZW+19AOu+McU+FkAkS7YcfVKzliHmfpMC J94WS4/SsFKGtbGmYIRsCMsIl7eZZctlgXwywRiJ/Z4pV+cbWhU/yu9uXltn9weIu9SG GK+A== X-Gm-Message-State: AC+VfDzg3dGgEbf/tEOrmeNFcMAIYzHboMbauQgUwmeDPLGIS/wGd8yf o0CM0R57dvaKTOLOzYPL405tgVS36P9edR7CJVgxK+SUk338DfFA3JFl78ugqP/kQL4hUHsx65K ifUC6yvV87qUi2goitYp47j9pkH4bNYGlSrlr6MhcgQ== X-Received: by 2002:adf:f749:0:b0:306:334a:7f1a with SMTP id z9-20020adff749000000b00306334a7f1amr3442077wrp.20.1683373475876; Sat, 06 May 2023 04:44:35 -0700 (PDT) X-Received: by 2002:adf:f749:0:b0:306:334a:7f1a with SMTP id z9-20020adff749000000b00306334a7f1amr3442067wrp.20.1683373475586; Sat, 06 May 2023 04:44:35 -0700 (PDT) Received: from localhost ([151.82.128.252]) by smtp.gmail.com with ESMTPSA id a11-20020adfeecb000000b003048477729asm5170198wrp.81.2023.05.06.04.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 May 2023 04:44:35 -0700 (PDT) Date: Sat, 6 May 2023 13:44:33 +0200 From: Andrea Righi To: hanjinke Cc: tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [External] Re: [PATCH v2] blk-throttle: Fix io statistics for cgroup v1 Message-ID: References: <20230401094708.77631-1-hanjinke.666@bytedance.com> <6696100e-e838-d96a-2894-bbca9783d2a3@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6696100e-e838-d96a-2894-bbca9783d2a3@bytedance.com> X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,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: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 05, 2023 at 09:35:21PM +0800, hanjinke wrote: > > > 在 2023/5/5 上午5:13, Andrea Righi 写道: > > On Thu, May 04, 2023 at 11:08:53PM +0800, hanjinke wrote: > > > Hi > > > > > > Sorry for delay(Chinese Labor Day holiday). > > > > No problem, it was also Labor Day in Italy. :) > > > > > > > > 在 2023/4/29 上午3:05, Andrea Righi 写道: > > > > On Sat, Apr 01, 2023 at 05:47:08PM +0800, Jinke Han wrote: > > > > > From: Jinke Han > > > > > > > > > > After commit f382fb0bcef4 ("block: remove legacy IO schedulers"), > > > > > blkio.throttle.io_serviced and blkio.throttle.io_service_bytes become > > > > > the only stable io stats interface of cgroup v1, and these statistics > > > > > are done in the blk-throttle code. But the current code only counts the > > > > > bios that are actually throttled. When the user does not add the throttle > > > > > limit, the io stats for cgroup v1 has nothing. I fix it according to the > > > > > statistical method of v2, and made it count all ios accurately. > > > > > > > > > > Fixes: a7b36ee6ba29 ("block: move blk-throtl fast path inline") > > > > > Signed-off-by: Jinke Han > > > > > > > > Thanks for fixing this! > > > > > > > > The code looks correct to me, but this seems to report io statistics > > > > only if at least one throttling limit is defined. IIRC with cgroup v1 it > > > > was possible to see the io statistics inside a cgroup also with no > > > > throttling limits configured. > > > > > > > > Basically to restore the old behavior we would need to drop the > > > > cgroup_subsys_on_dfl() check, something like the following (on top of > > > > your patch). > > > > > > > > But I'm not sure if we're breaking other behaviors in this way... > > > > opinions? > > > > > > > > block/blk-cgroup.c | 3 --- > > > > block/blk-throttle.h | 12 +++++------- > > > > 2 files changed, 5 insertions(+), 10 deletions(-) > > > > > > > > diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c > > > > index 79138bfc6001..43af86db7cf3 100644 > > > > --- a/block/blk-cgroup.c > > > > +++ b/block/blk-cgroup.c > > > > @@ -2045,9 +2045,6 @@ void blk_cgroup_bio_start(struct bio *bio) > > > > struct blkg_iostat_set *bis; > > > > unsigned long flags; > > > > - if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) > > > > - return; > > > > - > > > > /* Root-level stats are sourced from system-wide IO stats */ > > > > if (!cgroup_parent(blkcg->css.cgroup)) > > > > return; > > > > diff --git a/block/blk-throttle.h b/block/blk-throttle.h > > > > index d1ccbfe9f797..bcb40ee2eeba 100644 > > > > --- a/block/blk-throttle.h > > > > +++ b/block/blk-throttle.h > > > > @@ -185,14 +185,12 @@ static inline bool blk_should_throtl(struct bio *bio) > > > > struct throtl_grp *tg = blkg_to_tg(bio->bi_blkg); > > > > int rw = bio_data_dir(bio); > > > > - if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) { > > > > - if (!bio_flagged(bio, BIO_CGROUP_ACCT)) { > > > > - bio_set_flag(bio, BIO_CGROUP_ACCT); > > > > - blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf, > > > > - bio->bi_iter.bi_size); > > > > - } > > > > - blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1); > > > > + if (!bio_flagged(bio, BIO_CGROUP_ACCT)) { > > > > + bio_set_flag(bio, BIO_CGROUP_ACCT); > > > > + blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf, > > > > + bio->bi_iter.bi_size); > > > > } > > > > + blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1); > > > > > I checked the code again. If we remove cgroup_subsys_on_dfl check here, io > statistics will still be performed in the case of v2, which I think is > unnecessary, and this information will be counted to > io_service_bytes/io_serviced, these two files are not visible in v2. Am I > missing something? You are absolutely right. Sorry, I have just re-tested your fix and it seems to handle the cgroup v1 case correctly, you can add my: Tested-by: Andrea Righi And we definitely need the cgroup_subsys_on_dfl() check, otherwise we'd account extra IO in the v2 case that is not really needed. Thanks, -Andrea