cgroup: Remove duplicates in cgroup v1 tasks file
Michal Koutný
maintainerPATCH 1/1 cgroup: Remove duplicates in cgroup v1 tasks file
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:
Quoted 1 line
seq_file: buggy .next functionkernfs_seq_nextdid 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).
--- kernel/cgroup/cgroup-v1.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/cgroup/cgroup-v1.c +2 -3
@@ -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) {
Signature · 1 line
2.42.0
Quoted 15 lines · Michal Koutný
One PID may appear multiple times in a preloaded pidlist. (Possibly due to PID recycling but we have reports of the same
task_structappearing with different PIDs, thus possibly involving transfer of PID viade_thread().)Because v1
seq_fileiterator uses PIDs as position, it leads to a message:Quoted 1 line
seq_file: buggy .next functionkernfs_seq_nextdid not update position indexConservative and quick fix consists of removing duplicates from
tasksfile (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).
Quoted 3 lines
Suggested-by Firo Yang <[email protected]>Signed-off-by Michal Koutný <[email protected]>
Applied to cgroup/for-6.6-fixes.
Thanks.
Signature · 1 line
tejun