From: JP Kobryn <inwardvessel@gmail.com>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: tj@kernel.org, shakeel.butt@linux.dev, mkoutny@suse.com,
hannes@cmpxchg.org, akpm@linux-foundation.org,
linux-mm@kvack.org, cgroups@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH v5 2/5] cgroup: use separate rstat trees for each subsystem
Date: Mon, 12 May 2025 10:30:10 -0700 [thread overview]
Message-ID: <d532450f-42b0-42a8-9a43-31f46e2143e2@gmail.com> (raw)
In-Reply-To: <aBsm22A8qWjGJgY9@google.com>
On 5/7/25 2:24 AM, Yosry Ahmed wrote:
> On Fri, May 02, 2025 at 05:12:19PM -0700, JP Kobryn wrote:
[..]
>> @@ -383,32 +395,45 @@ __bpf_kfunc void css_rstat_flush(struct cgroup_subsys_state *css)
>>
>> int css_rstat_init(struct cgroup_subsys_state *css)
>> {
>> - struct cgroup *cgrp = css->cgroup;
>> + struct cgroup *cgrp;
>> int cpu;
>> + bool is_cgroup = css_is_cgroup(css);
>>
>> - /* the root cgrp has rstat_cpu preallocated */
>> - if (!cgrp->rstat_cpu) {
>> - cgrp->rstat_cpu = alloc_percpu(struct cgroup_rstat_cpu);
>> - if (!cgrp->rstat_cpu)
>> - return -ENOMEM;
>> - }
>> + if (is_cgroup) {
>> + cgrp = css->cgroup;
>
> You can keep 'cgrp' initialized at the top of the function to avoid the
> extra level of indentation here, right?
>
I can move this initialization to the top but the indentation of this
conditional branch will remain. See more thoughts below related to this
block.
>>
>> - if (!cgrp->rstat_base_cpu) {
>> - cgrp->rstat_base_cpu = alloc_percpu(struct cgroup_rstat_base_cpu);
>> + /* the root cgrp has rstat_base_cpu preallocated */
>> if (!cgrp->rstat_base_cpu) {
>> - free_percpu(cgrp->rstat_cpu);
>> + cgrp->rstat_base_cpu = alloc_percpu(struct cgroup_rstat_base_cpu);
>> + if (!cgrp->rstat_base_cpu)
>> + return -ENOMEM;
>> + }
>> + } else if (css->ss->css_rstat_flush == NULL)
>> + return 0;
>
> We can probably just do this at the beginning of the function to be able
> to use the helper:
>
> if (!css_is_cgroup(css) && css->ss->css_rstat_flush == NULL)
> return 0;
If we did this we would be wasting extra memory allocating the base
stats for every subsystem css. The intention behind the way I wrote it
was to optimize the memory overhead needed for split rstat trees.
next prev parent reply other threads:[~2025-05-12 17:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-03 0:12 [PATCH v5 0/5] cgroup: separate rstat trees JP Kobryn
2025-05-03 0:12 ` [PATCH v5 1/5] cgroup: use helper for distingushing css in callbacks JP Kobryn
2025-05-06 0:52 ` Shakeel Butt
2025-05-07 9:02 ` Yosry Ahmed
2025-05-09 21:46 ` JP Kobryn
2025-05-03 0:12 ` [PATCH v5 2/5] cgroup: use separate rstat trees for each subsystem JP Kobryn
2025-05-07 9:24 ` Yosry Ahmed
2025-05-09 17:53 ` JP Kobryn
2025-05-12 17:30 ` JP Kobryn [this message]
2025-05-03 0:12 ` [PATCH v5 3/5] cgroup: use subsystem-specific rstat locks to avoid contention JP Kobryn
2025-05-07 9:37 ` Yosry Ahmed
2025-05-03 0:12 ` [PATCH v5 4/5] cgroup: helper for checking rstat participation of css JP Kobryn
2025-05-07 9:38 ` Yosry Ahmed
2025-05-03 0:12 ` [PATCH v5 5/5] cgroup: document the rstat per-cpu initialization JP Kobryn
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=d532450f-42b0-42a8-9a43-31f46e2143e2@gmail.com \
--to=inwardvessel@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-mm@kvack.org \
--cc=mkoutny@suse.com \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=yosry.ahmed@linux.dev \
/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;
as well as URLs for NNTP newsgroup(s).