Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

taskstats: fill_stats_for_tgid: use for_each_thread()

do/while_each_thread should be avoided when possible.

Plus I _think_ this change allows to avoid lock_task_sighand() but I am
not sure, I forgot everything about taskstats. In any case, this code
does not look right in that the same thread can be accounted twice:
taskstats_exit() can account the exiting thread in signal->stats and drop
->siglock but this thread is still on the thread-group list, so
lock_task_sighand() can't help.

Link: https://lkml.kernel.org/r/20230909214951.GA24274@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Andrew Morton
ed5378a3 13b7bc60

+2 -3
+2 -3
kernel/taskstats.c
··· 233 233 else 234 234 memset(stats, 0, sizeof(*stats)); 235 235 236 - tsk = first; 237 236 start_time = ktime_get_ns(); 238 - do { 237 + for_each_thread(first, tsk) { 239 238 if (tsk->exit_state) 240 239 continue; 241 240 /* ··· 257 258 258 259 stats->nvcsw += tsk->nvcsw; 259 260 stats->nivcsw += tsk->nivcsw; 260 - } while_each_thread(first, tsk); 261 + } 261 262 262 263 unlock_task_sighand(first, &flags); 263 264 rc = 0;