Gentoo Wiki




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.

Priority Example

Run top from a terminal on your host and pay special attention to the PR and NI columns:

File: Sample top output
 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.

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:

Setting Portage Niceness

To set the niceness of Portage add the following to: /etc/make.conf

File: /etc/make.conf

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:

  1. Open a new terminal/tab/session.
  2. Edit /etc/make.conf and set PORTAGE_NICENESS="YOURDESIREDNICENESS"
  3. 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).

Note: As an alternative to step 3, if you are using top instead of ps anyways: Run top as root, press "r" when you see the emerge process and simply set the new niceness level. And since you at it, you should set the child processes (at least make or similar) of this emerge run to the same level, or else the the new level will be applied as early as the next package emerging.

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.


Retrieved from ""

Last modified: Sun, 07 Sep 2008 09:49:00 +0000 Hits: 13,569