From: Hao Jia <jiahao.os@bytedance.com>
To: Tejun Heo <tj@kernel.org>
Cc: lizefan.x@bytedance.com, hannes@cmpxchg.org, mkoutny@suse.com,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [External] Re: [PATCH] cgroup/rstat: record the cumulative per-cpu time of cgroup and its descendants
Date: Mon, 7 Aug 2023 11:36:22 +0800 [thread overview]
Message-ID: <2ee4f673-8218-ac72-684f-3cd78c46f750@bytedance.com> (raw)
In-Reply-To: <ZMrNHf2tg8AZ2F0z@slm.duckdns.org>
On 2023/8/3 Tejun Heo wrote:
> I couldn't come up with an answer. Let's go ahead with adding the field but
> can you please do the followings?
>
Thank you for your suggestion. I am very willing to do it.
> * Name it to something like subtree_bstat instead of cumul_bstat. The
> counters are all cumulative.
I did it in v2 patch.
>
> * Are you sure the upward propagation logic is correct? It's calculating
> global delta and then propagating to the per-cpu delta of the parent. Is
> that correct because the two delta calculations always end up the same?
Sorry, I made a mistake and misled you. These two deltas are not always
equal.
I found and reproduced a bug case:
We build /sys/fs/cgroup/test /sys/fs/cgroup/test/t1,
/sys/fs/cgroup/test/t1/tt1 in turn.
And there are only tasks in /sys/fs/cgroup/test/t1/tt1. After applying
this patch, some operations and corresponding data changes are as follows:
Step 1、cat /sys/fs/cgroup/test/t1/tt1/cpu.stat
*cpu 6* current flush cgroup /test/t1/tt1
per-cpu delta utime 0 stime 0 sum_exec_runtime 257341
/test/t1/tt1 cumul_bstat(cpu 6) utime 0 stime 0 sum_exec_runtime 257341
/test/t1/tt1 cgrp->bstat utime 0 stime 0 sum_exec_runtime 257341
if (cgroup_parent(parent)) {
cgrp delta utime 0 stime 0 sum_exec_runtime 257341
parent(/test/t1) ->bstat utime 0 stime 0 sum_exec_runtime 257341
parent(/test/t1) last_bstat utime 0 stime 0 sum_exec_runtime 0
parent(/test/t1) cumul_bstat utime 0 stime 0 sum_exec_runtime 257341
}
Step 2、cat /sys/fs/cgroup/test/t1/tt1/cpu.stat
*cpu 12* current flush cgroup /test/t1/tt1
per-cpu delta utime 0 stime 1000000 sum_exec_runtime 747042
/test/t1/tt1 cumul_bstat utime 0 stime 1000000 sum_exec_runtime 747042
/test/t1/tt1 cgrp->bstat utime 0 stime 1000000 sum_exec_runtime 1004383
if (cgroup_parent(parent)) {
cgrp delta utime 0 stime 1000000 sum_exec_runtime 747042
parent(/test/t1) ->bstat utime 0 stime 1000000 sum_exec_runtime 1004383
parent(/test/t1) last_bstat utime 0 stime 0 sum_exec_runtime 0
parent(/test/t1) cumul_bstat utime 0 stime 1000000 sum_exec_runtime
747042
}
Step 3、cat /sys/fs/cgroup/test/cpu.stat
(cgroup fulsh /test/t1/tt1 -> /test/t1 -> /test in turn)
*cpu 6* current flush cgroup /test/t1/tt1
per-cpu delta utime 0 stime 0 sum_exec_runtime 263468
/test/t1/tt1 cumul_bstat(cpu 6) utime 0 stime 0 sum_exec_runtime 520809
/test/t1/tt1 cgrp->bstat utime 0 stime 1000000 sum_exec_runtime 1267851
if (cgroup_parent(parent)) {
cgrp delta utime 0 stime 0 sum_exec_runtime 263468
parent(/test/t1) ->bstat utime 0 stime 1000000 sum_exec_runtime 1267851
parent(/test/t1) last_bstat utime 0 stime 0 sum_exec_runtime 0
parent(/test/t1) cumul_bstat utime 0 stime 0 sum_exec_runtime 520809
}
*cpu 6* current flush cgroup /test/t1
per-cpu delta utime 0 stime 0 sum_exec_runtime 0
/test/t1 cumul_bstat(cpu 6) utime 0 stime 0 sum_exec_runtime 520809
/test/t1 cgrp->bstat utime 0 stime 1000000 sum_exec_runtime 1267851
if (cgroup_parent(parent)) {
cgrp delta utime 0 stime 1000000 sum_exec_runtime 1267851 <---
parent(/test) ->bstat utime 0 stime 1000000 sum_exec_runtime 1267851
parent(/test) last_bstat utime 0 stime 0 sum_exec_runtime 0
parent(/test) cumul_bstat (cpu 6) utime 0 stime 1000000
sum_exec_runtime 1267851 <--- *error*
******
Here cgrp delta is *not equal* to per-cpu delta.
The frequency of cgroup (/test) and its chiled cgroup (/test/t1/tt1)
flush is inconsistent.
In other words (when we call cgroup_base_stat_flush(), we will not
necessarily flush to the highest-level cgroup except root(like step 1
and 2 above)).
Therefore, cgrp delta may contain the cumulative value of multiple
per-cpu deltas.
The correct value of parent(/test) cumul_bstat should be utime 0
stime 0 sum_exec_runtime 520809.
******
}
*cpu 6* current flush cgroup /test
per-cpu delta utime 0 stime 0 sum_exec_runtime 0
cumul_bstat utime 0 stime 1000000 sum_exec_runtime 1267851
/test ->bstat utime 0 stime 1000000 sum_exec_runtime 1267851
cgroup_parent(parent) is NULL end.
So we should add a per-cpu variable subtree_last_bstat similar to
cgrp->last_bstat to record the last value.
I have sent v2 patch, please review it again.
v2 link:
https://lore.kernel.org/all/20230807032930.87785-1-jiahao.os@bytedance.com
> * Please add a comment explaining that the field is not currently used
> outside of being read from bpf / drgn and what not and that we're still
> trying to determine how to expose that in the cgroupfs interface.
Thanks, I did it in v2 patch.
Thanks,
Hao
prev parent reply other threads:[~2023-08-07 3:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-17 9:36 Hao Jia
2023-07-17 19:52 ` Tejun Heo
2023-07-18 10:08 ` [External] " Hao Jia
2023-07-18 21:53 ` Tejun Heo
2023-07-19 3:01 ` Hao Jia
2023-07-27 12:05 ` Hao Jia
2023-07-27 17:44 ` Tejun Heo
2023-08-02 21:39 ` Tejun Heo
2023-08-07 3:36 ` Hao Jia [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2ee4f673-8218-ac72-684f-3cd78c46f750@bytedance.com \
--to=jiahao.os@bytedance.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan.x@bytedance.com \
--cc=mkoutny@suse.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®