Portage tips

This article explains how to enable several non-default Portage tweaks in order to compile and search faster, safer and more effectively.

This article does not explain usage of Portage itself (nor USE flags usage) and its content is possibly simplified.

Emerging multiple packages at once
emerge --jobs=4 --update --deep --newuse world Since large --jobs values can cause heavy load, especially when combined with the --jobs option in MAKEOPTS, it's a good idea to use --load-average.
 * -j --jobs allows emerge to unpack, configure, and build multiple packages simultaneously. It is not to be confused with the --jobs option in MAKEOPTS, which controls multiple jobs in make for compiling individual packages in parallel.  Portage will concurrently process up to the specified number of packages, provided they not are dependent on each other. This option can be specified either in EMERGE_DEFAULT_OPTS in  or as command line argument:
 * --load-average specifies that no new builds should  be  started  if  there  are other  builds  running  and the load average is at least LOAD (floating-point number). This prevents your system from overloading by multiple compilations at once and is functionally equivalent to the --load-average option in MAKEOPTS.  Note however that the short -l option does not correspond to --load-average in emerge like it does in make (in emerge, -l is equivalent to --changelog).

The following example (used on a dual-core processor) instructs Portage to process up to 2 packages at once, starting a new job only if the system load is under 1.85. Each of those build processes is allowed up to 3 make jobs in parallel, starting a new job only if the system load is under 1.85.

Portage niceness
Emerge generally consumes a lot of available system resources. Following trick may help you make emerge more stable when you keep working on your system during compilation. The price for this is slightly lower speed as Portage gets lower (higher) priority. To modify the priority of Portage, add the following line to your /etc/portage/make.conf:

You may change the value from -20 to 19, higher values mean lesser priority. The default priority is 0. You should not set the value below 0, as compilations could cut almost all CPU/memory resources. Also be aware of setting niceness too high, which may result in priority inversion problem.

Parallel fetch
The parallel fetch feature allows emerge to download sources in background while compiling, which can greatly speed up average emerge times, especially on computers with slow internet connections. This may potentially produce errors during compilation if the internet connection breaks, those are safe to ignore. Append this line to /etc/portage/make.conf

Choosing right mirror
[ Mirror select tool ] [ Avoid slow mirrors ]

mirrorselect ensures using the fastest and closest mirror to your location in order to speed up downloads. This tool appends lines automatically to.

Prelinking
This is not a speed up of portage, but of applications, enabled by a portage option.

By preparing dynamic linking beforhand, it may speed up the start of some applications by up to 50% (especially KDE).

Using Portage >= 2.0, prelink is enabled by default after emerging the prelink package. Packages compiled by Portage will be from now on automatically prelinked. To prelink already installed packages, you will need to run:

You may want to rerun this command from time to time as software that is not compiled with portage will not be prelinked by default (you may add prelink to cron monthly job).

GCC
[ Safe Cflags ]

Setting optimized compiler flags for your CPU can make compilation faster and make your programs run faster despite their commonly increased size. Be aware that some optimizations may cause incompatibility of software compiled on your computer with other computers having other types of CPUs. You may add those to /etc/portage/make.conf

ICC
[ Intel C/C++ Compiler HOWTO ] [ | Gentoo wiki-archives article about ICC ]

Wise usage of Intel compiler may help you speed up certain software significantly (up to 30% in some mathematical software). Biggest disadvantage of ICC that it does not support code that is heavily optimized for gcc, therefore it's impossible to compile the entire system with it. Using the guide in the link above it's possible to selectively build safe packages.

Compilation process optimization on multicore systems
Option MAKEOPTS="-jX" optimizes compiling to use multiple concurrent make processes. X is a numerical value. In general, a good value is the number of available cores (multiplied by 2 if you have HT support) + 1. Setting the value far beyond the real number of your cores is contra productive, same as setting a lesser value. Keep in mind that the more processes you have running, the more CPU processing power will be consumed by Portage and your system may become unresponsive.

Using tmpfs with portage
See: Portage TMPDIR on tmpfs

By default, Portage stores its temporary files on a hard drive. This article explains how to use a RAM filesystem, tmpfs.

Using ccache
See: ccache For years there has been widespread overestimate for ccache effect. Read the above article carefully.

Filesystem for /usr/portage
There's some choices for the filesystem of :
 * squashfs. Faster and takes less disk space.
 * Reiserfs, with appropriate options. Notice that most files are small, and reiserfs excels in such case, but at the cost of cpu power.
 * Ext2.

The key for the latter two is that journaling is not necessary for /usr/portage.

A paragraph of the old wiki suggests, but the performance dependency on the blocksize varies among HDDs. (It's true that a smaller blocksize takes less disk space.)

SQLite Cache
[ Portage SQLite Cache ]

Using SQLite cache backend can speed up dependency calculations when running emerge or eix. This article explains how to enable the Portage SQLite cache back-end.

Portage and python3
If you have python3 installed, you may want to emerge Portage using the USE flag. This is reported to speed up portage processing tasks on average by 15% (some claims up to 30%).

Portage cgroups
[ Portage cgroups ]

Ag provided simple bash script which will integrate cgroups to portage. This can be especially useful with Systemd which is heavily based on cgroups for scheduling tasks. To use cgroups system-wide (or rather shell-wide), check this article.

eclean
eclean is  small  tool  to  remove obsolete portage sources files and binary packages. Used on a regular basis, it prevents your DISTDIR and PKGDIR directories to infinitely grow. By default, eclean will protect all distfiles or binary packages corresponding to some ebuilds available in the Portage tree.

To use eclean, gentoolkit package has to be installed:

If using the or  option, eclean will only protect files corresponding to some currently installed package (taking  their exact version into account).

To view old distfiles and binary packages which would be removed, run following command:

To remove unneeded packages and distfiles run the same command as above without the  or  option:

Sandbox
[ Sandbox explained ]

The sandbox is a control mechanism used by Portage, originally to aid in debugging of ebuilds. Its main purpose is to provide a safe and protected environment for running programs whose functions are not entirely known. Essentially it provides an environment where building of packages can occur without interfering with the operation of the rest of the system. It basically prevents the build process from getting out of control. By now, the reasons should be clear why having ebuilds written outside of the sandbox can be problematic.

Append following line to /etc/make.conf

Using BINHOST
[ Using Portage BINHOST ]

BINHOST is a portage feature that makes binary packages available to download from outside host, rather than compile them. This option is directly supported with Portage, however Gentoo has no official servers for this purpose.

Distcc
[ Article about distcc integration with portage ]

Distcc is a program designed to distribute compiling tasks across a network to participating hosts. Article above explains how to set it up with full Portage integration.

FEATURES list
For a full list of FEATURES refer to the make.conf man page. To see which FEATURES are enabled run:

Doc compression control
Files under, , and are (almost) always compressed using bzip2. You can disable it by setting in. See for more.

How NOT to compress (tex)info files
Taken from this forum thread.

"Info" files under are compressed when emerged, but you can suprress it. It'll result in faster browsing and searching, especially for big files like emacs and elisp.

To achieve it, you have to hack two files, and  in the same dir.

First,. Comment out the last line, as: For, search for the word "--dequeue", and before the first line with "find", insert: rm -f "${ED}/info.ecompress.dir"
 * 1) exec ecompressdir --queue "${infodir}"

To protect these file from changes at re-emerge of portage, set, too, in : CONFIG_PROTECT="your/own/other/files /usr/lib/portage/bin/ebuild-helpers/ecompressdir /usr/lib/portage/bin/ebuild-helpers/prepinfo"

Of course, it'll take extra HDD space, about 5 times or so.

Theory: Hacking takes effect only for explicit. OTOH has to be modified, too; it automatically compresses all files under, together with /usr/share/man and /usr/share/doc.