cgroup, netclassid: on modifying netclassid in cgroup, only consider the main process.

When modifying netclassid, the command("echo 0x100001 > net_cls.classid")
will take more time on many threads of one process, because the process
create many fds.
for example, one process exists 28000 fds and 60000 threads, echo command
will task 45 seconds.
Now, we only consider the main process when exec "iterate_fd", and the
time is about 52 milliseconds.

Signed-off-by: Liansen Zhai <zhailiansen@kuaishou.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20231012090330.29636-1-zhailiansen@kuaishou.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Liansen Zhai 2023-10-12 17:03:30 +08:00 committed by Jakub Kicinski
parent 1cfce8261d
commit c60991f8e1
1 changed files with 6 additions and 0 deletions

View File

@ -88,6 +88,12 @@ static void update_classid_task(struct task_struct *p, u32 classid)
};
unsigned int fd = 0;
/* Only update the leader task, when many threads in this task,
* so it can avoid the useless traversal.
*/
if (p != p->group_leader)
return;
do {
task_lock(p);
fd = iterate_fd(p->files, fd, update_classid_sock, &ctx);