[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8e65aa62-c92c-857d-3e27-8ccddf51b07f@bytedance.com>
Date: Wed, 24 May 2023 16:41:08 +0800
From: Hao Jia <jiahao.os@...edance.com>
To: Michal Koutný <mkoutny@...e.com>
Cc: tj@...nel.org, lizefan.x@...edance.com, hannes@...xchg.org,
cgroups@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [External] Re: [PATCH] cgroup: rstat: Simplified
cgroup_base_stat_flush() update last_bstat logic
On 2023/5/24 Michal Koutný wrote:
> On Wed, May 24, 2023 at 02:54:10PM +0800, Hao Jia <jiahao.os@...edance.com> 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
Powered by blists - more mailing lists