Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4470886rwl; Tue, 28 Mar 2023 07:25:11 -0700 (PDT) X-Google-Smtp-Source: AKy350bt/CWr5jOSOY8za1lSRNEj0G1OSFuwbEmqXz+3mKsRHUvCnKr9SNFVbyK2lt7nNqCec5pF X-Received: by 2002:a17:906:d1cf:b0:8b1:7aaa:4c25 with SMTP id bs15-20020a170906d1cf00b008b17aaa4c25mr17525024ejb.29.1680013510906; Tue, 28 Mar 2023 07:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680013510; cv=none; d=google.com; s=arc-20160816; b=wPhWKIFGQOHMHx1FxahDqbnAlkIQ1rUaDc/bt0JQjES3QV6ukRrupCoOA55HuIhlCZ VoUSf/n2arp5kPQ6XWVTJVzNjv3Vxxd9rP2O/+H6vF3gvpgMrasWDnkK81TiuummoRE5 5AmIrsZNnpDGJFS9avqXW0nBJNQFhknPRmUbqMOUHQo+/SGrsj04pom4UEXmTef4vLMT cZayHbEbx/Sb11dQtJPd+gziEyOO5q/pJ27cQ21OT6vHts4uFAayC1dvM05gzLZZGS1E EarW5Hz5ywm800skn2LvQaBz7MEEu7XkRoGnZNNgrr5kUmKpaXjuny0YOK/elk6r/z/n 5m5Q== 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=fbUthmvZJbP0uWypvRq6mwPD7H6UG/v/3UyHU90H3o0=; b=M0WELJtj5jbGSusDNoLdNdhBPx6XdKI7ZZDISDJVfauC/Y7B3Mv9MADm+sjjo9/P0b PTibbimbVE8KWFGLU/+tnWOJTxcupTm6Jk+m5y3BMVDlOvQfhfFHIJnVIMa5rOsJ4aD+ i7zVuXGm6MaGSWm2LVJRYT9I6oa/RVP+f2X1SO+tWeVbjUidecDAVzx/KjNk60kh78kk gSWfa7L2AwRw1KqrX4SdaCHkZSx13nu762yopblRRzv+heodTsnAJ3DBWhQEmcWh5kQr H7CMX1QpOD0YdikQKG7AlOBvkV2oNOIHYcNqIJSOWz+wK+5ISVdPSHidPCOZjtLAV2Q0 GcQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=NTg1JCEY; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xj4-20020a170906db0400b0093defbd627dsi13245969ejb.1028.2023.03.28.07.24.44; Tue, 28 Mar 2023 07:25:10 -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=@bytedance.com header.s=google header.b=NTg1JCEY; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230378AbjC1OX0 (ORCPT + 99 others); Tue, 28 Mar 2023 10:23:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbjC1OXZ (ORCPT ); Tue, 28 Mar 2023 10:23:25 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAA4619BC for ; Tue, 28 Mar 2023 07:23:23 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id h14so7296283pgj.7 for ; Tue, 28 Mar 2023 07:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1680013403; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fbUthmvZJbP0uWypvRq6mwPD7H6UG/v/3UyHU90H3o0=; b=NTg1JCEYXIL5mZ4LMW8DcsZJvrDf8IwNw9hp30j9TO7GBAGr0SEnuxFWhsFCWyvFD2 O8bQkmMtjNy8tLclBcd6RNNFBrbtlCs5oxp1OKNk02oxnYYHOFkNH8j/Q/xQ+YVNPwDP ln+p36VFbYTbqUl1pKr0haZetqg2MamAFX+iM2arG8XIoKYEXwDDduY8YJCOEaEAzPcF tPMHjJPM810hJNCv2O4ZNsByZFmSSIE/8vXL5oFEUfVjB7yXmRhgI+UeQlxMw1P1qnvP fQT6rdeMMdTdB5xL5+pgB7wmQEhbrrZml75ao9Yh+IjqjDMfoEAv/5QPwCuNaEjh50+i vAOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680013403; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fbUthmvZJbP0uWypvRq6mwPD7H6UG/v/3UyHU90H3o0=; b=kyM/lFfO02ciNYex23VFWlZPX9+GLEGmxFscwX+pISv9WaBQGo0C3n4kbuhG71LCCT vrRMO221CN8D8fNiFdgZi/7sMU9eO3pUf3do7uBK+Vr7Zm47trBgn9AKw8EskvecxDkd 6jIYWGkVxWbazF/TzPFRx+Z/7MEAK3wH7VlpmZeBeVWSM02/C/vZyPpYabXnnw8I6Wv6 hqsSkeCnqT6qhBb34jEKd0xjS8YdPuwB7k0wqx7gNrW5u/PWHe1kkQHse75ERrIGbM6c LLeL//xu/uL7chq814Kc0he6GUwF/1/4M3dAtyVSLqddKkrISedWpLElUN6wCpr11gvn QSlA== X-Gm-Message-State: AO0yUKXhtH/bJtLDr2OGSWTJDawZRRKh26iWMMXm374lBTg+0zlQ3o6Z NUTb/4lQTbe57tNQ92nR4ZvtyQ== X-Received: by 2002:a05:6a00:190a:b0:626:f690:e745 with SMTP id y10-20020a056a00190a00b00626f690e745mr26435591pfi.6.1680013403339; Tue, 28 Mar 2023 07:23:23 -0700 (PDT) Received: from C02GD5ZHMD6R.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id g6-20020a62e306000000b005a8bf239f5csm21156215pfh.193.2023.03.28.07.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 07:23:22 -0700 (PDT) From: Jinke Han X-Google-Original-From: Jinke Han To: tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Jinke Han Subject: [PATCH] blk-throttle: Fix io statistics for cgroup v1 Date: Tue, 28 Mar 2023 22:23:09 +0800 Message-Id: <20230328142309.73413-1-hanjinke.666@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_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 From: Jinke Han Now the io statistics of cgroup v1 are no longer accurate. Although in the long run it's best that rstat is a good implementation of cgroup v1 io statistics. But before that, we'd better fix this issue. Signed-off-by: Jinke Han --- block/blk-cgroup.c | 3 +++ block/blk-throttle.c | 6 ------ block/blk-throttle.h | 9 +++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index bd50b55bdb61..677e4473e45e 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -2033,6 +2033,9 @@ 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.c b/block/blk-throttle.c index 47e9d8be68f3..2be66e9430f7 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -2174,12 +2174,6 @@ bool __blk_throtl_bio(struct bio *bio) rcu_read_lock(); - if (!cgroup_subsys_on_dfl(io_cgrp_subsys)) { - blkg_rwstat_add(&tg->stat_bytes, bio->bi_opf, - bio->bi_iter.bi_size); - blkg_rwstat_add(&tg->stat_ios, bio->bi_opf, 1); - } - spin_lock_irq(&q->queue_lock); throtl_update_latency_buckets(td); diff --git a/block/blk-throttle.h b/block/blk-throttle.h index ef4b7a4de987..d1ccbfe9f797 100644 --- a/block/blk-throttle.h +++ b/block/blk-throttle.h @@ -185,6 +185,15 @@ 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); + } + /* iops limit is always counted */ if (tg->has_rules_iops[rw]) return true; -- 2.20.1