public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Friedrich Vock <friedrich.vock@gmx.de>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: Tejun Heo <tj@kernel.org>, Johannes Weiner <hannes@cmpxchg.org>,
	Simona Vetter <simona.vetter@ffwll.ch>,
	David Airlie <airlied@gmail.com>,
	Maarten Lankhorst <dev@lankhorst.se>,
	Maxime Ripard <mripard@kernel.org>,
	dri-devel@lists.freedesktop.org, cgroups@vger.kernel.org
Subject: Re: [PATCH] cgroup/dmem: Don't clobber pool in dmem_cgroup_calculate_protection
Date: Sun, 26 Jan 2025 17:38:19 +0100	[thread overview]
Message-ID: <2a5c5c05-1d54-4b23-898b-ab4ef96fa61c@gmx.de> (raw)
In-Reply-To: <qu3jdiik2sfstey4ecxdojndkzb5gzblg37i76p43xccnotawl@jlbafrgjad2x>

On 24.01.25 10:56, Michal Koutný wrote:
> On Fri, Jan 17, 2025 at 08:02:55PM +0100, Friedrich Vock <friedrich.vock@gmx.de> wrote:
>> Yeah, there are pools for the whole path between limit_pool and
>> test_pool, but the issue is that we traverse the entire tree of cgroups,
>> and we don't always stay on the path between limit_pool and test_pool
>> (because we're iterating from the top down, and we don't know what the
>> path is in that direction - so we just traverse the whole tree until we
>> find test_pool).
>>
>> This means that we'll sometimes end up straying off-path - and there are
>> no guarantees for which pools are present in the cgroups we visit there.
>> These cgroups are the potentially problematic ones where the issue can
>> happen.
>>
>> Ideally we could always stay on the path between limit_pool and
>> test_pool, but this is hardly possible because we can only follow parent
>> links (so bottom-up traversal) but for accurate protection calculation
>> we need to traverse the path top-down.
>
> Aha, thanks for bearing with me.
>
> 	css_foreach_descendant_pre(css, limit_pool->cs->css) {
> 		dmemcg_iter = container_of(css, struct dmemcg_state, css);
>
> 		struct dmem_cgroup_pool_state *found_pool = NULL;
> 		list_for_each_entry_rcu(pool, &dmemcg_iter->pools, css_node) {
> 			if (pool->region == limit_pool->region) {
> 				found_pool = pool
> 				break;
> 			}
> 		}
> 		if (!found_pool)
> 			continue;
>
> 		page_counter_calculate_protection(
> 			climit, &found->cnt, true);
> 	}
>
> Here I use (IMO) more idiomatic css_foreach_descendant_pre() instead and
> I use the predicate based on ->region (correct?) to match pool's
> devices.

Good catch with ->region! That works well indeed, I think it might not
have been a thing back when I wrote this tree traversal :>

I've applied this snippet (with a few minor edits) and taken it for a
test run too - it appears to work nicely in practice as well. I'll send
out a v2 with this approach tomorrow.

Thanks,
Friedrich

>
> Would that work as intended?
>
> Michal


  reply	other threads:[~2025-01-26 16:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14 15:39 [PATCH] cgroup/dmem: Don't clobber pool in dmem_cgroup_calculate_protection Friedrich Vock
2025-01-14 15:58 ` Michal Koutný
2025-01-16  8:20   ` Friedrich Vock
2025-01-17 17:29     ` Michal Koutný
2025-01-17 19:02       ` Friedrich Vock
2025-01-24  9:56         ` Michal Koutný
2025-01-26 16:38           ` Friedrich Vock [this message]
2025-01-27 15:27 ` [PATCH v2] cgroup/dmem: Don't open-code css_for_each_descendant_pre Friedrich Vock
2025-02-12  8:40   ` Maarten Lankhorst
2025-02-18 14:55   ` Maarten Lankhorst
2025-02-18 18:39     ` Tejun Heo
2025-02-19  8:53       ` Maarten Lankhorst
2025-02-19  9:08       ` Maxime Ripard
2025-02-19 13:26         ` Simona Vetter

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=2a5c5c05-1d54-4b23-898b-ab4ef96fa61c@gmx.de \
    --to=friedrich.vock@gmx.de \
    --cc=airlied@gmail.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dev@lankhorst.se \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hannes@cmpxchg.org \
    --cc=mkoutny@suse.com \
    --cc=mripard@kernel.org \
    --cc=simona.vetter@ffwll.ch \
    --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