Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5466002rwd; Wed, 24 May 2023 02:05:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4jUvJVym48hv0XXXjWkwq+DmDGidfyLDW822hQ1EnZdDqsn+Q+fIqfoVF+Rbrmr/ljkw4h X-Received: by 2002:a05:6a20:7f91:b0:ff:ca91:68ee with SMTP id d17-20020a056a207f9100b000ffca9168eemr17987654pzj.9.1684919125421; Wed, 24 May 2023 02:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684919125; cv=none; d=google.com; s=arc-20160816; b=h5ojID4IXWzwgt/PJw1LQ4kfjrbz4WTz3wnHn9rf2oyqDh4JZgTymiOcaFcTYBbPcE PBcvY8KyBKkYsRdDhh9OIlDxap4LM1JXck0pZCQTSh9l7m3X2zdI3eBSBsd2YwNj8KRW yE5f3er2ocJlAdZoZV+OKfr9WIn2ZpM6tiaxV7Am/OPGg4AgSskOQOw7VjkU7D7GQthE nGC17iALSngoRwA592pssuixkEvPUWTI8KY+VEv242InW2ZQE7voBi51OWkJErLneBKS WZr/zBEXnzO+N7xhVkhhh2nnzvYGsmQO+aBbwOBTqfndVVFPjTcq1weloMpxbrCWTkYD dIiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=dTHbB0gony/TYMogUW6Qo/V1GtsaSfduo/QCXMjaxUM=; b=YsoKVcYV/YBWSBwsPGfeednI1iSGW2Wnt4LzrXPxgBc0KVu5OpX5bPHXn4YlzUOCuP kWva+iqWR0eIPEYSMgPsRgk9zFNzsaloVAkmZrLo1wq1a5uTKoMPWaizeALUjiBPNhX3 G2Hqe5V/vu1zWcZcAhj12IofgJ/+8ZntKfgRmS3+tc7gl6ssa/42Xd9nEWZ9BuuZGTHx OlsTKO53oBsvN8s1J/HJ4xiNA0u5uuqAzbw6z9xoB6MHDG4S5xyG5eu2rgidopc39h43 R1UXpNSxcxupoWM6TzeseFtjzr6UUWY9+fo2MCtSGjm3OsF6G8MlbDEcHluW2DpUBN7b 2dFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZnX7arnh; 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 y18-20020a63b512000000b00534842e134fsi5434850pge.272.2023.05.24.02.05.12; Wed, 24 May 2023 02:05:25 -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=ZnX7arnh; 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 S240301AbjEXInK (ORCPT + 99 others); Wed, 24 May 2023 04:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240303AbjEXImw (ORCPT ); Wed, 24 May 2023 04:42:52 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 201E8E51 for ; Wed, 24 May 2023 01:41:21 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2553f2706bfso725984a91.1 for ; Wed, 24 May 2023 01:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684917680; x=1687509680; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=dTHbB0gony/TYMogUW6Qo/V1GtsaSfduo/QCXMjaxUM=; b=ZnX7arnhJ7Q+Ipi910Jn2NK7QtDaPy4TlGLSCmXMrFgaUyqr1HH/K1c8b6/vd5Uy7O jNoxiqXlVyu7dS8JQ6XZcHcyTIWBo5LiGPQ2ieUIGyL0YZetHQ2aHFnCghlX8XgkIv+F f5EuBJnyV4VDQSb9NGCcJtePUs1XekOOsQ7ZeebwLbsoZ8oXPbGQ8lEuVgI+YY4ZT/0S A5DUGll7sRLEHXSOQqu1Q8FZI26Y3oe3l2415CbQ8TxjnBND2kMPXNEJYohRbUKP5kVZ woD/ctZI3vJHoAqhsIdLRO+9uYd6q4ASQGv3xtle4N7GIVzykLdRozpCCKQxXXlzaFno K06w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684917680; x=1687509680; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=dTHbB0gony/TYMogUW6Qo/V1GtsaSfduo/QCXMjaxUM=; b=GRsKjSZyoxVViz5lCV6Ket7cWn+jAx8P0PNstDn/s0ImDqdi/dKAkFMhlzE+E6FMuA hWZXwsj59D5UJQKmKEdxHAVFYMUHfZ0NvnTD0Sq96/qBIEB4fbd/r6s5AMoXBCDcZK6S 8uuWsExE5+zcjUSakHAww0HmAj5E9TOWG9fCzYJmK2rqgtoGLb/rieKkuvcmnwxZkCBm Va7OjfUVvxiPnjlndCTM5mnnlAKeRJM6YYb0aIMJCqpGeD4Qi7QE3jFQb0uVvN8v0dcW hFhSA4W0xvkQt6WAvpwDg32/SNTbaLiL5q4nyho12L1SAf9l0g9EzkjcbtZuhT/3r1Fs JBHQ== X-Gm-Message-State: AC+VfDw2jjhC0O8dZFf9IOyi+wBLIhemtQIirE1RFC+e2QsNNOrb/E1y rv1MrkR8qM+WAQr6hS1a5hPTmA== X-Received: by 2002:a17:90b:378c:b0:23f:962e:825d with SMTP id mz12-20020a17090b378c00b0023f962e825dmr17772299pjb.1.1684917680462; Wed, 24 May 2023 01:41:20 -0700 (PDT) Received: from [10.85.115.102] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id n3-20020a17090ab80300b00253298287ccsm857956pjr.14.2023.05.24.01.41.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 01:41:20 -0700 (PDT) Message-ID: <8e65aa62-c92c-857d-3e27-8ccddf51b07f@bytedance.com> Date: Wed, 24 May 2023 16:41:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [External] Re: [PATCH] cgroup: rstat: Simplified cgroup_base_stat_flush() update last_bstat logic To: =?UTF-8?Q?Michal_Koutn=c3=bd?= Cc: tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230518124142.57644-1-jiahao.os@bytedance.com> <5g73i4yvi4ub4dqrf4dnq5qghkyckoygmgd2st6be3gg7twww2@w6zim6nxpt3b> <4d49f7e7-2488-9690-258e-34e617cfef6f@bytedance.com> From: Hao Jia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On 2023/5/24 Michal Koutný wrote: > On Wed, May 24, 2023 at 02:54:10PM +0800, Hao Jia wrote: >> Yes, so we need @curr to record the bstat value after the sequence fetch is >> completed. > > No, I still don't see a problem that it solves. If you find incorrect > data being reported, please explain it more/with an example. Sorry to confuse you. My earliest patch is like this: diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 9c4c55228567..3e5c4c1c92c6 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -376,14 +376,14 @@ static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu) /* propagate percpu delta to global */ cgroup_base_stat_sub(&delta, &rstatc->last_bstat); (1) <--- cgroup_base_stat_add(&cgrp->bstat, &delta); - cgroup_base_stat_add(&rstatc->last_bstat, &delta); + rstatc->last_bstat = rstatc->bstat; (2) <-- /* propagate global delta to parent (unless that's root) */ if (cgroup_parent(parent)) { delta = cgrp->bstat; cgroup_base_stat_sub(&delta, &cgrp->last_bstat); cgroup_base_stat_add(&parent->bstat, &delta); - cgroup_base_stat_add(&cgrp->last_bstat, &delta); + cgrp->last_bstat = cgrp->bstat; } } If I understand correctly, the rstatc->bstat at (1) and (2) may be different. At (2) rstatc->bstat may have been updated on other CPUs. Or we should not read rstatc->bstat directly, we should pass the following way do { seq = __u64_stats_fetch_begin(&rstatc->bsync); cur = rstatc->bstat; } while (__u64_stats_fetch_retry(&rstatc->bsync, seq)); > >> Yes, but it may not be obvious. >> Another reason is that when we complete an update, we snapshot last_bstat as >> the current bstat, which is better for readers to understand. Arithmetics is >> somewhat obscure. > > The readability here is subjective. It'd be interesting to have some > data comparing arithmetics vs copying though. Thanks for your suggestion, I plan to use RDTSC to compare the time consumption of arithmetics vs copying. Do you have better suggestions or tools? Thanks, Hao