From: Michal Hocko <mhocko@suse.com>
To: Ye Liu <ye.liu@linux.dev>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
Marco Elver <elver@google.com>, Ye Liu <liuye@kylinos.cn>,
Yi Tao <escape@linux.alibaba.com>, Tejun Heo <tj@kernel.org>,
Bart Van Assche <bvanassche@acm.org>,
Christian Brauner <brauner@kernel.org>,
linux-kernel@vger.kernel.org, Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH 1/8] mm: introduce for_each_process_rcu and for_each_thread_rcu
Date: Fri, 4 Sep 2026 13:03:15 +0200 [thread overview]
Message-ID: <apqlcw1qJd3QjsMq@tiehlicka> (raw)
In-Reply-To: <20260904083001.553587-2-ye.liu@linux.dev>
You want to CC Oleg at least. Now added
Also prefixing this patch with mm is confusing as this has nothing to do
with mm.
On Fri 04-09-26 16:29:53, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
>
> Introduce for_each_process_rcu(), for_each_thread_rcu() and
> for_each_process_thread_rcu() macros that acquire the RCU read lock
> before the iteration starts and release it when the loop is left, so
> that the RCU read-side critical section is scoped to the loop body
> instead of an externally managed rcu_read_lock()/rcu_read_unlock()
> pair.
>
> Signed-off-by: Ye Liu <liuye@kylinos.cn>
Apparat from potential naming changes this makes a lot of sense to me.
Many users really need RCU in the scope of iteration and this simplifies
the code and it makes less prone to bugs.
I do not really care much about the naming TBH
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
> include/linux/sched/signal.h | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
> index 584ae88b435e..fe0c41dc99a1 100644
> --- a/include/linux/sched/signal.h
> +++ b/include/linux/sched/signal.h
> @@ -2,6 +2,7 @@
> #ifndef _LINUX_SCHED_SIGNAL_H
> #define _LINUX_SCHED_SIGNAL_H
>
> +#include <linux/cleanup.h>
> #include <linux/rculist.h>
> #include <linux/signal.h>
> #include <linux/sched.h>
> @@ -663,6 +664,24 @@ extern bool current_is_single_threaded(void);
> #define for_each_process_thread(p, t) \
> for_each_process(p) for_each_thread(p, t)
>
> +/*
> + * RCU-internal variants: automatically acquire and release the RCU read
> + * lock around the iteration. Equivalent to scoped_guard(rcu) combined
> + * with the respective non-_rcu variant.
> + */
> +#define for_each_process_rcu(p) \
> + scoped_guard(rcu) \
> + for (p = &init_task ; (p = next_task(p)) != &init_task ; )
> +
> +#define for_each_thread_rcu(p, t) \
> + scoped_guard(rcu) \
> + __for_each_thread((p)->signal, t)
> +
> +/* Careful: this is a double loop, 'break' won't work as expected. */
> +#define for_each_process_thread_rcu(p, t) \
> + scoped_guard(rcu) \
> + for_each_process(p) for_each_thread(p, t)
> +
> typedef int (*proc_visitor)(struct task_struct *p, void *data);
> void walk_process_tree(struct task_struct *top, proc_visitor, void *);
>
> --
> 2.25.1
>
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2026-09-04 11:03 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 8:29 [PATCH 0/8] mm: introduce for_each_process_rcu and for_each_thread_rcu Ye Liu
2026-09-04 8:29 ` [PATCH 1/8] " Ye Liu
2026-09-04 11:03 ` Michal Hocko [this message]
2026-09-04 16:25 ` Steven Rostedt
2026-09-04 21:17 ` Thomas Gleixner
2026-09-04 23:07 ` Steven Rostedt
2026-09-05 7:27 ` Thomas Gleixner
2026-09-08 8:38 ` Peter Zijlstra
2026-09-11 12:54 ` Steven Rostedt
2026-09-11 15:54 ` Bart Van Assche
2026-09-08 12:42 ` Steven Rostedt
2026-09-04 8:29 ` [PATCH 2/8] mm/oom_kill: convert process/thread iterators to for_each_*_rcu Ye Liu
2026-09-04 11:04 ` Michal Hocko
2026-09-05 0:32 ` SJ Park
2026-09-04 8:29 ` [PATCH 3/8] mm/ksm: convert process iterator to for_each_process_rcu Ye Liu
2026-09-04 11:04 ` Michal Hocko
2026-09-05 0:33 ` SJ Park
2026-09-04 8:29 ` [PATCH 4/8] mm/memory-failure: " Ye Liu
2026-09-04 11:05 ` Michal Hocko
2026-09-05 0:39 ` SJ Park
2026-09-07 3:05 ` Miaohe Lin
2026-09-04 8:29 ` [PATCH 5/8] kernel: convert process/thread iterators to for_each_*_rcu Ye Liu
2026-09-04 8:40 ` sashiko-bot
2026-09-04 11:06 ` Michal Hocko
2026-09-04 14:14 ` Günther Noack
2026-09-04 8:29 ` [PATCH 6/8] fs: " Ye Liu
2026-09-04 9:05 ` Oleg Nesterov
2026-09-04 9:22 ` Lorenzo Stoakes (ARM)
2026-09-04 11:06 ` Michal Hocko
2026-09-08 16:45 ` Alexey Dobriyan
2026-09-08 17:10 ` Lorenzo Stoakes (ARM)
2026-09-08 17:26 ` Alexey Dobriyan
2026-09-08 17:41 ` Lorenzo Stoakes (ARM)
2026-09-08 17:12 ` Oleg Nesterov
2026-09-04 8:29 ` [PATCH 7/8] lib: convert process iterator to for_each_process_rcu Ye Liu
2026-09-04 11:09 ` Michal Hocko
2026-09-04 8:30 ` [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu Ye Liu
2026-09-04 12:21 ` Justin Suess
2026-09-04 14:17 ` Günther Noack
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=apqlcw1qJd3QjsMq@tiehlicka \
--to=mhocko@suse.com \
--cc=brauner@kernel.org \
--cc=bvanassche@acm.org \
--cc=elver@google.com \
--cc=escape@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liuye@kylinos.cn \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
--cc=ye.liu@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.