From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C924C433E0 for ; Sat, 6 Feb 2021 03:35:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB50861606 for ; Sat, 6 Feb 2021 03:35:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB50861606 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 369756B0005; Fri, 5 Feb 2021 22:35:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31B686B006C; Fri, 5 Feb 2021 22:35:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20AAB6B006E; Fri, 5 Feb 2021 22:35:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 0AB716B0005 for ; Fri, 5 Feb 2021 22:35:32 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C2F37181AEF1A for ; Sat, 6 Feb 2021 03:35:31 +0000 (UTC) X-FDA: 77786428062.21.brake56_0f16eda275ea Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id AAF45180442C0 for ; Sat, 6 Feb 2021 03:35:31 +0000 (UTC) X-HE-Tag: brake56_0f16eda275ea X-Filterd-Recvd-Size: 7163 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Sat, 6 Feb 2021 03:35:31 +0000 (UTC) Received: by mail-qt1-f182.google.com with SMTP id x3so4678079qti.5 for ; Fri, 05 Feb 2021 19:35:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=IvmfqIU5DXZ+U45JTS5bf/DzmLeS1efZIG+7GNtTIZs=; b=nlB9qdbDK7an1HVmKu1x7dyzmCUf75hspLWyYVdt9HRej55Aa/uBj8j7Cb2YG9ouOE SxWkGe4WkVQZw1074K5MKXCyYgpcammBsW6K7BNMyziereI6ca7/R3JRbJIrGdUJMEwb imDqwlc50saRmE2N9wzsZrxs1N71E9fWPkAL9Dv98YGbN+o20OZVONYavOKyMkhI7aLo 7y9dPVA5gOjjSZhzfPwFBRGPkWri2jhw2IPnoij3/jNy68WslT/zBjWOP9V8w0K/R3GP tKIRNLnc8y/4HyX3eXOLsfTWjbBmg20T7OaKfnz5fnvpDxCoUzi8p6ensZ9nrSUnSVIL h5fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=IvmfqIU5DXZ+U45JTS5bf/DzmLeS1efZIG+7GNtTIZs=; b=oLZQ9rJsxtJDcCv2PtQLxrO9vHnL9obzyAIixahOX8TqDAgt2I16sevDJArqJzNlpb m7DYczCDZmHmk93SBX9CcZlpO/LfEGPSiaBVcuI2osLIIBEHEVSuJ2iKgy5VoZo48HUQ dfgKv5NcYEGMjwF9yHw3fgcv+fABnBSNa5P3EmHUriBqf4bNuWO5WIbTLK5RllCyY5jc UmTy1UVOMKZyKLMGK3OJ8choT/FH0YzJ8t3xjt1RL016E3RSF1PgX8ULrhanHr1fM0// YnSFeLRNXfjzBvbJ2zwPPqHaFDwUx3xK0E2SWBF9sFWc/Pj1qC2Ov/2HTHox7NXyMi97 nlSA== X-Gm-Message-State: AOAM531AqR7fvxm32IY46SbgxX6QBVtugRYk7eUDAIHqI1BGQkmV6vpz +eFVE0QLLw9JhQ5YegS/STY= X-Google-Smtp-Source: ABdhPJzDs7khSL2MtxgIlvlQLkbA8Btb4AvAWQY5TJJQsEcz4HcY4sTO6s/vzTgjB+fYwQtVXkRStQ== X-Received: by 2002:ac8:1494:: with SMTP id l20mr7431549qtj.151.1612582530368; Fri, 05 Feb 2021 19:35:30 -0800 (PST) Received: from localhost (dhcp-6c-ae-f6-dc-d8-61.cpe.echoes.net. [72.28.8.195]) by smtp.gmail.com with ESMTPSA id 138sm11711025qkd.80.2021.02.05.19.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 19:35:29 -0800 (PST) Date: Fri, 5 Feb 2021 22:34:39 -0500 From: Tejun Heo To: Johannes Weiner Cc: Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 5/8] cgroup: rstat: punt root-level optimization to individual controllers Message-ID: References: <20210205182806.17220-1-hannes@cmpxchg.org> <20210205182806.17220-6-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210205182806.17220-6-hannes@cmpxchg.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hello, On Fri, Feb 05, 2021 at 01:28:03PM -0500, Johannes Weiner wrote: > Current users of the rstat code can source root-level statistics from > the native counters of their respective subsystem, allowing them to > forego aggregation at the root level. This optimization is currently > implemented inside the generic rstat code, which doesn't track the > root cgroup and doesn't invoke the subsystem flush callbacks on it. > > However, the memory controller cannot do this optimization, because > cgroup1 breaks out memory specifically for the local level, including > at the root level. In preparation for the memory controller switching > to rstat, move the optimization from rstat core to the controllers. > > Afterwards, rstat will always track the root cgroup for changes and > invoke the subsystem callbacks on it; and it's up to the subsystem to > special-case and skip aggregation of the root cgroup if it can source > this information through other, cheaper means. > > The extra cost of tracking the root cgroup is negligible: on stat > changes, we actually remove a branch that checks for the root. The > queueing for a flush touches only per-cpu data, and only the first > stat change since a flush requires a (per-cpu) lock. > > Signed-off-by: Johannes Weiner Generally looks good to me. Acked-by: Tejun Heo A couple nits below. > diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c > index 02ce2058c14b..76725e1cad7f 100644 > --- a/block/blk-cgroup.c > +++ b/block/blk-cgroup.c > @@ -766,6 +766,10 @@ static void blkcg_rstat_flush(struct cgroup_subsys_state *css, int cpu) > struct blkcg *blkcg = css_to_blkcg(css); > struct blkcg_gq *blkg; > > + /* Root-level stats are sourced from system-wide IO stats */ > + if (!cgroup_parent(css->cgroup)) > + return; > + > rcu_read_lock(); > > hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) { > @@ -789,6 +793,7 @@ static void blkcg_rstat_flush(struct cgroup_subsys_state *css, int cpu) > u64_stats_update_end(&blkg->iostat.sync); > > /* propagate global delta to parent */ > + /* XXX: could skip this if parent is root */ > if (parent) { > u64_stats_update_begin(&parent->iostat.sync); > blkg_iostat_set(&delta, &blkg->iostat.cur); Might as well update this similar to cgroup_base_stat_flush()? > @@ -58,8 +53,16 @@ void cgroup_rstat_updated(struct cgroup *cgrp, int cpu) > if (rstatc->updated_next) > break; > > + if (!parent) { Maybe useful to note that the node is being marked busy but not added to the non-existent parent. > + rstatc->updated_next = cgrp; > + break; > + } > + > + prstatc = cgroup_rstat_cpu(parent, cpu); > rstatc->updated_next = prstatc->updated_children; > prstatc->updated_children = cgrp; > + > + cgrp = parent; > } > > raw_spin_unlock_irqrestore(cpu_lock, flags); ... > static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu) > { > - struct cgroup *parent = cgroup_parent(cgrp); > struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu); > + struct cgroup *parent = cgroup_parent(cgrp); Is this chunk intentional? > struct cgroup_base_stat cur, delta; > unsigned seq; > > + /* Root-level stats are sourced from system-wide CPU stats */ > + if (!parent) > + return; > + > /* fetch the current per-cpu values */ > do { > seq = __u64_stats_fetch_begin(&rstatc->bsync); > @@ -326,8 +336,8 @@ static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu) > cgroup_base_stat_add(&cgrp->bstat, &delta); > cgroup_base_stat_add(&rstatc->last_bstat, &delta); > > - /* propagate global delta to parent */ > - if (parent) { > + /* propagate global delta to parent (unless that's root) */ > + if (cgroup_parent(parent)) { Yeah, this makes sense. Can you add a short while-at-it note in the patch description? Thanks. -- tejun