I'm writing a program launcher that uses nice to launch X applications with a higher than usual priority and while there's plenty of guides to using nice/renice there's not much discussion about best practise in setting program priorities. I found one site that says going over -10 can be counter-productive as "vital sub-processes" will get less priority than the program relying on them and another saying that -20 is a bad idea but everything else is ok. So my question would be for a single user desktop running word processors/browsers/games/whatever is there a point of diminishing returns or is there any reason why I wouldn't want to default to -19 for any program started by the user? At this point I anticipate it will run on linux kernels but also interested if there's any potential problems on other unices like BSD.
The scheduler in Linux has the following policies:
SCHED_NORMAL
this is used by virtually all of your tasks. The higher priority these tasks are the more scheduling time they get.SCHED_BATCH
lower thanSCHED_NORMAL
in priority.SCHED_IDLE
even lower priority than19
forSCHED_NORMAL
.SCHED_FIFO
/SCHED_RR
are pretty much real-time and have the highest priority on the system. Basically they have no time slices and can run until they terminate.
The documentation for this is here: https://www.kernel.org/doc/Documentation/scheduler/sched-design-CFS.txt
To understand what is going on with these priorities you need to understand what the scheduler does:
In computing, scheduling is the method by which work specified by some means is assigned to resources that complete the work.
More specifically, CFS is the scheduler you're referring to.
So setting a process to a higher priority means that the scheduler will have a higher preference to that process than lower priority processes.
On a single user desktop, there would be not real drawback/risk changing your main application process priority, assuming you are talking about niceness and the nice
command and not real-time scheduling.
There would be no real incentive either though for two reasons:
Process priority is about CPU usage but the CPU is rarely the bottleneck nowadays, CPU are fast and often multi-core and multi-threaded so there is often enough power to run simultaneously the processes willing to use a CPU, if any.
A desktop application is usually interactive so commonly spend a lot of its time waiting for user input, or network I/Os or disk I/Os so changing its priority would make not much difference anyway as its real priority would be raised after these idle periods.
Some cases where that would make a difference is if you launch CPU intensive batch jobs, reducing their priority or raising some other process priority might have a visible impact.