TIP nice Portage
From Gentoo Linux Wiki
Contents |
[edit] Introduction
The Linux kernel has a process scheduler that selects which process gets CPU time at any given moment. One factor influencing the scheduler's decision about which process to assign CPU time to, is the priority of a process. Processes with a high priority will run before those with a lower priority, and processes with the same priority will take turns in running, one after the other and over again.
[edit] Priority Example
Run top from a terminal on your host and pay special attention to the PR and NI columns:
| File: Sample top output |
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8005 root 20 0 85188 33m 57m R 3.3 6.7 8:43.77 X
8148 tobias 20 10 25624 2376 24m S 0.3 0.5 0:00.60 xscreensaver
1 root 20 0 2476 552 2304 S 0.0 0.1 0:00.31 init
2 root 39 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
3 root 15 -5 0 0 0 S 0.0 0.0 0:00.09 events/0
|
The PR column indicates the priority level of a process, the value in the NI column displays the so-called nice value of process (how nice it is to other processes). Possible values range from -20 (very high priority) to 19 (very low priority). 0 is the priority at which a process runs by default. In our example above the xscreensaver process has a higher nice value than X, which indicates that X has a higher priority than xscreensaver.
[edit] Effect of Niceness on Portage
Now, how do we make this work to our advantage when using Portage?
If you keep using your computer while compiling packages you will notice that your box is less responsive than usual. This is caused by having two "groups" of processes with the same nice priority: your usual running processes, and emerge (and its child processes). Now, if you could renice emerge and its children to a higher nice value (i.e. lower priority), compiling would take somewhat longer, but your workstation will be as responsive as before. That's what the PORTAGE_NICENESS variable in /etc/make.conf is for:
[edit] Setting Portage Niceness
To set the niceness of Portage add the following to: /etc/make.conf
| File: /etc/make.conf |
PORTAGE_NICENESS=15 |
You can generally "renice" individual processes from the commandline, (e.g. renice 0 -p 8148 to prioritize xscreensaver in the above example), but this will not work with emerge, as Portage reads the PORTAGE_NICENESS setting from /etc/make.conf once and executes all child processes with the specified nice value.
Edit - There is actually a way to "Renice" Portage while it is running. I have done it several times and never had an issue. There are 3 steps:
- Open a new terminal/tab/session.
- Edit /etc/make.conf and set PORTAGE_NICENESS="YOURDESIREDNICENESS"
- Run "Top" in the new session. Note the Process ID for the "Emerge" Command. You might need to watch for a few minutes as it only is using resources when actually emerging. Once you have found out what the process ID is you can do CTRL+C to quit top, or open a new session - I prefer to open a new session as I can then watch Top to verify it worked properly.
In the new window run the command renice YOURDESIREDNICENESS -p 8148, where the number after -p is the process ID (as explained earlier in this article).
I have used this method to "renice" portage to make things emerge faster about 50 times. I have never once had an issue with it. Both on ~x86/~x86_64 and x86/x86_64.
