linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Juri Lelli <juri.lelli@redhat.com>
To: Waiman Long <longman@redhat.com>
Cc: Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>, Qais Yousef <qyousef@layalina.io>,
	Hao Luo <haoluo@google.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Xia Fukun <xiafukun@huawei.com>
Subject: Re: [PATCH] cgroup/cpuset: Change nr_deadline_tasks to an atomic_t value
Date: Fri, 13 Oct 2023 08:09:09 +0200	[thread overview]
Message-ID: <ZSjfBWgZf15TchA5@localhost.localdomain> (raw)
In-Reply-To: <c421a8d5-b364-d3c6-df18-2a6766fc069b@redhat.com>

On 12/10/23 12:35, Waiman Long wrote:
> On 10/11/23 08:54, Waiman Long wrote:

...

> > We can argue that there can be racing between cgroup_exit() and the
> > iteration of tasks in cpuset_attach() or cpuset_can_attach(). An
> > rcu_read_lock() is probably needed. I am stilling investigating that.
> 
> Cgroup has a rather complex task migration and iteration scheme. According
> to the following comments in include/linux/cgroup-defs.h:
> 
>         /*
>          * Lists running through all tasks using this cgroup group.
>          * mg_tasks lists tasks which belong to this cset but are in the
>          * process of being migrated out or in.  Protected by
>          * css_set_lock, but, during migration, once tasks are moved to
>          * mg_tasks, it can be read safely while holding cgroup_mutex.
>          */
>         struct list_head tasks;
>         struct list_head mg_tasks;
>         struct list_head dying_tasks;
> 
> I haven't fully figured out how that protection works yet. Assuming that is
> the case, task iteration in cpuset_attach() should be fine since
> cgroup_mutex is indeed held when it is invoked. That protection, however,
> does not applied to nr_deadline_tasks. It may be too costly to acquire
> cpuset_mutex before updating nr_deadline_tasks in cgroup_exit(). So changing
> it to an atomic_t should be the easy way out of the potential racing
> problem.

My biggest perplexity is/was still about dl_rebuild_rd_accounting() and
cgroup_exit(); I wonder if the latter, operating outside cpuset_mutex
guard, might still be racy wrt the former (even if we change to
atomic_t).

However, looking again at it, dl_rebuild_rd_accounting() operates on
css(es) via css_task_iter_start(), which grabs css_set_lock. So maybe we
are OK already also for this case?

Apologies for being pedantic, but we fought already several times with
races around these bits and now I'm probably over-suspicious. :)

Thanks,
Juri


      reply	other threads:[~2023-10-13  6:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09 19:15 [PATCH] cgroup/cpuset: Change nr_deadline_tasks to an atomic_t value Waiman Long
2023-10-10  5:34 ` Juri Lelli
2023-10-10 19:44   ` Waiman Long
2023-10-10 20:03     ` Waiman Long
2023-10-11  8:14       ` Juri Lelli
2023-10-11 12:54         ` Waiman Long
2023-10-12 16:35           ` Waiman Long
2023-10-13  6:09             ` Juri Lelli [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=ZSjfBWgZf15TchA5@localhost.localdomain \
    --to=juri.lelli@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=haoluo@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=longman@redhat.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=tj@kernel.org \
    --cc=xiafukun@huawei.com \
    /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).