Re: [PATCH 7/8] lib: convert process iterator to for_each_process_rcu
From: Michal Hocko
Date: Fri Sep 04 2026 - 08:10:57 EST
On Fri 04-09-26 16:29:59, Ye Liu wrote:
> From: Ye Liu <liuye@xxxxxxxxxx>
>
> Replace the manual rcu_read_lock()/rcu_read_unlock() pair combined
> with for_each_process() loop in lib/ with for_each_process_rcu().
>
> No functional change.
>
> Signed-off-by: Ye Liu <liuye@xxxxxxxxxx>
> ---
> lib/is_single_threaded.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
> index 8c98b20bfc41..0682dc87bcdf 100644
> --- a/lib/is_single_threaded.c
> +++ b/lib/is_single_threaded.c
> @@ -26,8 +26,7 @@ bool current_is_single_threaded(void)
> return true;
>
> ret = false;
> - rcu_read_lock();
> - for_each_process(p) {
> + for_each_process_rcu(p) {
> if (unlikely(p->flags & PF_KTHREAD))
> continue;
> if (unlikely(p == task->group_leader))
> @@ -48,7 +47,5 @@ bool current_is_single_threaded(void)
> }
> ret = true;
> found:
> - rcu_read_unlock();
> -
> return ret;
This can be slightly simplified as below. Anyway
Acked-by: Michal Hocko <mhocko@xxxxxxxx>
---
diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
index 8c98b20bfc41..4f7620481066 100644
--- a/lib/is_single_threaded.c
+++ b/lib/is_single_threaded.c
@@ -17,7 +17,6 @@ bool current_is_single_threaded(void)
struct task_struct *task = current;
struct mm_struct *mm = task->mm;
struct task_struct *p, *t;
- bool ret;
if (atomic_read(&task->signal->live) != 1)
return false;
@@ -25,9 +24,7 @@ bool current_is_single_threaded(void)
if (atomic_read(&mm->mm_users) == 1)
return true;
- ret = false;
- rcu_read_lock();
- for_each_process(p) {
+ for_each_process_rcu(p) {
if (unlikely(p->flags & PF_KTHREAD))
continue;
if (unlikely(p == task->group_leader))
@@ -35,7 +32,7 @@ bool current_is_single_threaded(void)
for_each_thread(p, t) {
if (unlikely(t->mm == mm))
- goto found;
+ return false
if (likely(t->mm))
break;
/*
@@ -46,9 +43,5 @@ bool current_is_single_threaded(void)
smp_rmb();
}
}
- ret = true;
-found:
- rcu_read_unlock();
-
- return ret;
+ return true;
}
--
Michal Hocko
SUSE Labs