mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cgroup: Remove duplicates in cgroup v1 tasks file
@ 2023-10-09 13:58 Michal Koutný
  2023-10-09 16:32 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Koutný @ 2023-10-09 13:58 UTC (permalink / raw)
  To: cgroups, linux-kernel; +Cc: Tejun Heo, Zefan Li, Johannes Weiner, Firo Yang

One PID may appear multiple times in a preloaded pidlist.
(Possibly due to PID recycling but we have reports of the same
task_struct appearing with different PIDs, thus possibly involving
transfer of PID via de_thread().)

Because v1 seq_file iterator uses PIDs as position, it leads to
a message:
> seq_file: buggy .next function kernfs_seq_next did not update position index

Conservative and quick fix consists of removing duplicates from `tasks`
file (as opposed to removing pidlists altogether). It doesn't affect
correctness (it's sufficient to show a PID once), performance impact
would be hidden by unconditional sorting of the pidlist already in place
(asymptotically).

Link: https://lore.kernel.org/r/20230823174804.23632-1-mkoutny@suse.com/
Suggested-by: Firo Yang <firo.yang@suse.com>
Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
 kernel/cgroup/cgroup-v1.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index c487ffef6652..76db6c67e39a 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -360,10 +360,9 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
 	}
 	css_task_iter_end(&it);
 	length = n;
-	/* now sort & (if procs) strip out duplicates */
+	/* now sort & strip out duplicates (tgids or recycled thread PIDs) */
 	sort(array, length, sizeof(pid_t), cmppid, NULL);
-	if (type == CGROUP_FILE_PROCS)
-		length = pidlist_uniq(array, length);
+	length = pidlist_uniq(array, length);
 
 	l = cgroup_pidlist_find_create(cgrp, type);
 	if (!l) {
-- 
2.42.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] cgroup: Remove duplicates in cgroup v1 tasks file
  2023-10-09 13:58 [PATCH] cgroup: Remove duplicates in cgroup v1 tasks file Michal Koutný
@ 2023-10-09 16:32 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2023-10-09 16:32 UTC (permalink / raw)
  To: Michal Koutný
  Cc: cgroups, linux-kernel, Zefan Li, Johannes Weiner, Firo Yang

On Mon, Oct 09, 2023 at 03:58:11PM +0200, Michal Koutný wrote:
> One PID may appear multiple times in a preloaded pidlist.
> (Possibly due to PID recycling but we have reports of the same
> task_struct appearing with different PIDs, thus possibly involving
> transfer of PID via de_thread().)
> 
> Because v1 seq_file iterator uses PIDs as position, it leads to
> a message:
> > seq_file: buggy .next function kernfs_seq_next did not update position index
> 
> Conservative and quick fix consists of removing duplicates from `tasks`
> file (as opposed to removing pidlists altogether). It doesn't affect
> correctness (it's sufficient to show a PID once), performance impact
> would be hidden by unconditional sorting of the pidlist already in place
> (asymptotically).
> 
> Link: https://lore.kernel.org/r/20230823174804.23632-1-mkoutny@suse.com/
> Suggested-by: Firo Yang <firo.yang@suse.com>
> Signed-off-by: Michal Koutný <mkoutny@suse.com>

Applied to cgroup/for-6.6-fixes.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-09 16:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 13:58 [PATCH] cgroup: Remove duplicates in cgroup v1 tasks file Michal Koutný
2023-10-09 16:32 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®