Portage niceness

From Gentoo Wiki
(Redirected from User:Sam/PORTAGE NICENESS)
Jump to:navigation Jump to:search

This article describes some knobs available for system administrators to help manage Portage's resource usage.

Note
Starting with sys-apps/portage-3.0.35 the preferred way to de-prioritize Portage build jobs is by using scheduling policy configuration

Background

Priority and nice values

The priority value (PR) of a process ranges from 0 to 139, giving high to low priority respectively. Real time process occupy 0 to 99 and user processes range of 100 to 139.

User process priority is defined in terms of the nice level (NI) plus 20 (NI + 20). The nice level therefore ranges from -20 to 19, which corresponds to a user process priority of 0 to 39 and a PR value of 100 to 139. For example, giving a process a nice value of 0 translates into a PR of 120.

Controlling priority

Linux has a few options to control system responsiveness by limiting a process' use of resources, including nice (which is POSIX, not Linux-exclusive), ionice, and chrt. The interaction between these is complicated and it's usually hard to reason about.

In short:

  • nice controls priority with regard to the CPU scheduler
  • ionice controls priority with regard to the disk I/O scheduler
  • chrt is like an extended nice - it can change attributes of the process(es) which the CPU scheduler utilizes, rather than just the simplistic 'niceness' level, like priority/task class.

Resources online also cover the distinction between nice and chrt.

In any case, all three are valuable tools in making Portage run smoothly in the background without interfering with general system usage from other processes. Anecdotally, chrt seems to make the most difference.

Configuration

Note
The /etc/portage/make.conf variables mentioned here don't allow running multiple commands by themselves, hence the use of a wrapper script. This issue is tracked as bug #565418.

Enable both PORTAGE_NICENESS and PORTAGE_IONICE_COMMAND in /etc/portage/make.conf:

FILE /etc/portage/make.conf
# Lowest priority
PORTAGE_NICENESS="19"
# Call the wrapper script which handles ionice and chrt (priority)
PORTAGE_IONICE_COMMAND="/usr/local/bin/io-priority \${PID}"

Create the wrapper script to handle both ionice and chrt:

FILE /usr/local/bin/io-priority
#!/bin/bash
PID=${1}

# Could use `ionice -c 2 -n 7 -p ${PID}` to be slightly less aggressive.
ionice -c 3 -p ${PID}
chrt -p -i 0 ${PID}

Make the script executable so emerge can use it:

root #chmod +x /usr/local/bin/io-priority

Scheduling policy

Note
The scheduling policy control is supported starting with sys-apps/portage-3.0.35

Using Portage's scheduling policy, it is possible to define what scheduling policy the Linux kernel will apply to emerge itself and all the build jobs. System administrators who wish to minimize Portage's impact on system responsiveness should set scheduling policy to idle. This will significantly reduce the disruption to the rest of the system by scheduling Portage processes as extremely low priority. The 'idle' policy is order of magnitude lower than anything running with PORTAGE_NICENESS set to level of 19.

For example, to set the idle scheduling policy:

FILE /etc/portage/make.confSet PORTAGE_SCHEDULING_POLICY to idle
# Extremely low priority
PORTAGE_SCHEDULING_POLICY="idle"
Note
The 'idle' scheduling policy does not support nice levels, meaning one can just set PORTAGE_SCHEDULING_POLICY to idle and omit setting the PORTAGE_NICENESS variable all together.

For more information about Portage's scheduling ability search for PORTAGE_SCHEDULING_POLICY in man 5 make.conf.

See also