Will a process with more threads in linux have more CPU time than a process with one thread?

Will a process with more threads on Linux have more CPU time than a process with one thread?

On Linux, processes and threads are described by the structure of the task, and scheduling is based on tasks . I also found this :

When a new process is created, do_fork() sets the counter field of both the current (parent) and p (child) processes as follows:

 current->counter >>= 1; p->counter = current->counter; 

In other words, the number of ticks left before the parent is divided into two halves, one for the parent and one for the child. This is done so that users do not get an unlimited amount of processor time using the following method: the parent process creates a child process that runs the same code and then kills itself; By correctly adjusting the creation speed, the child process will always receive a new quantum before the expiration of its parent. This software trick does not work because the kernel does not award forks. Similarly, a user cannot inflate an unfair share of the processor by running many background processes in the shell or by opening many windows on the graphical desktop. More generally, a process cannot process resources (unless it has privileges to provide real-time policy) by propagating multiple descendants.

In fact, I did not find this in the kernel sources, but maybe this is my mistake, maybe I saw the wrong version of the kernel.

But what will happen next, will each thread participate in planning as a separate process? Will a ten-thread process receive ten times more ticks than a single-thread process? What about AI in this sense?

+5
multithreading linux-kernel scheduler
source share
1 answer

Yes, a process with a large number of threads will receive more processor time than its competitors. A well-known case is maven compilation, maven uses many threads that use CPU intensively, clogging the system.

But the current linux scheduler does not only consider tasks; it also considers management groups in the cpu cgu hierarchy. Thus, the processor time is divided between control groups, and then in each control group the processor time is divided between tasks.

Starting from 2.6.38, Linux automatically places taks in different cpu groups based on their session identifiers. This means that, for example, the individual tabs in the console / dwarf terminal receive their own control group. So, now your maven build is beautifully isolated and no longer starts the system. See kernelnewbies and lwn.net descriptions .

Before 2.6.38 got into most systems, Lennart Poettering showed how to do it manually in a shell script on this LKML post .

In fact, I have a system in which I run Eclipse and maven compilations, as well as switching from pre-2.6.38 to pre-2.6.38 + binding to the Lennart group (on which I put /etc/bashrc and on my splash screen Eclipse script) was just perfect. Maven no longer starts the system (you did not know that maven is being compiled if it is not for the processor load monitor), and Eclipse now just starts itself and not the rest of the system (I agree with Eclipse). Now I just need to update the kernel to a better record on a dirty page, and this system will work to work.

+8
source share

All Articles