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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C1B7C7EE23 for ; Wed, 24 May 2023 08:43:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240256AbjEXInL (ORCPT ); Wed, 24 May 2023 04:43:11 -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-Google-Smtp-Source: ACHHUZ5hZGClD8Wm6BRjHwUzH4LIwlL/jyB4wklJZWIBhBzz+AkGHz5cDJ1YVqdT0xuc+4+ZgMFqtA== 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 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