Re: [PATCH 6/8] fs: convert process/thread iterators to for_each_*_rcu
From: Michal Hocko
Date: Fri Sep 04 2026 - 08:15:18 EST
On Fri 04-09-26 16:29:58, Ye Liu wrote:
> From: Ye Liu <liuye@xxxxxxxxxx>
>
> Replace the manual rcu_read_lock()/rcu_read_unlock() pairs combined
> with for_each_process() and for_each_process_thread() loops in fs/
> with the for_each_*_rcu() macros.
>
> No functional change.
>
> Signed-off-by: Ye Liu <liuye@xxxxxxxxxx>
Acked-by: Michal Hocko <mhocko@xxxxxxxx>
> ---
> fs/proc/base.c | 4 +---
> fs/resctrl/rdtgroup.c | 8 ++------
> 2 files changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 6a39de424f62..da36ba73dc17 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -1160,8 +1160,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> if (mm) {
> struct task_struct *p;
>
> - rcu_read_lock();
> - for_each_process(p) {
> + for_each_process_rcu(p) {
> if (same_thread_group(task, p))
> continue;
>
> @@ -1177,7 +1176,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> }
> task_unlock(p);
> }
> - rcu_read_unlock();
> mmdrop(mm);
> }
> err_unlock:
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index 5dcbb0a964e8..3f96d21b84ab 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -709,14 +709,12 @@ int rdtgroup_tasks_assigned(struct rdtgroup *r)
>
> lockdep_assert_held(&rdtgroup_mutex);
>
> - rcu_read_lock();
> - for_each_process_thread(p, t) {
> + for_each_process_thread_rcu(p, t) {
> if (is_closid_match(t, r) || is_rmid_match(t, r)) {
> ret = 1;
> break;
> }
> }
> - rcu_read_unlock();
>
> return ret;
> }
> @@ -826,15 +824,13 @@ static void show_rdt_tasks(struct rdtgroup *r, struct seq_file *s)
> struct task_struct *p, *t;
> pid_t pid;
>
> - rcu_read_lock();
> - for_each_process_thread(p, t) {
> + for_each_process_thread_rcu(p, t) {
> if (is_closid_match(t, r) || is_rmid_match(t, r)) {
> pid = task_pid_vnr(t);
> if (pid)
> seq_printf(s, "%d\n", pid);
> }
> }
> - rcu_read_unlock();
> }
>
> static int rdtgroup_tasks_show(struct kernfs_open_file *of,
> --
> 2.25.1
>
--
Michal Hocko
SUSE Labs