Portage TMPDIR on tmpfs

When emerging packages it is possible to build them in tmpfs (RAM) space instead of having build files pushed and pulled to Hard Disk Drive (HDD) or Solid State Drive (SSD) space. Building in tmpfs both speeds up emerge times and reduces HDD/SSD wearing. For system's containing SSDs, it is generally a good idea to have Portage compile using tmpfs (RAM) instead burning up precious SSD write cycles (especially on something like compiling software).

fstab Configuration
Mount Portage's  to tmpfs by adding the following to the system's  config file:

Adjust the  parameter  to the desired amount of RAM. Systems with large amounts of RAM can increase the number quite significantly.

After has been modified, mount Portage's TMPDIR to RAM by running the mount command followed by the directory location outline in :

Considering tmpfs' Size
The system's tmpfs space should be large enough to handle the largest packages to be compiled on the system. If the tmpfs space were to ever become completely full then the emerge will fail. Most packages do not need more than 1 GB of tmpfs space their compiles, but there are few very large packages. If you have a lot of RAM, setting be careful to include enough tmpfs space when installing the following packages:


 * 10GBs or so.


 * More than 2GBs.


 * More than 4 GiB.

Per-Package Choices at Compile Time
Portage can be configured to build large packages outside of the tmpfs space on a per-package basis.

Create a file to tell Portage where to place the temporary files directory:

Create a separate temporary file directory outside of the tmpfs mount location:

Create a special Portage file called !/etc/portage/package.env in and list all the packages that are too large to be compiled using tmpfs:

Temporarily Increase TmpFs Size
First, a warning on tmpfs size from Linux kernel's Documentation/filesystems/tmpfs.txt

size: The limit of allocated bytes for this tmpfs instance. The default is half of your physical RAM without swap. If you oversize your tmpfs instances the machine will deadlock since the OOM handler will not be able to free that memory.

There is a rule of thumb: always leave-out at least 1G space.

You can resize your tmpfs by doing.

This will not persist into the next boot.

It *should* be safe to enlarge the tmpfs during an emerge, though it's doubtful that you'll ever have to do that. If anything, emerge will tell you the tmpfs is too small, you can enlarge it or add the exception to /etc/portage/package.env, and then emerge again.

Save an emerge and Resume Later
Example: emerging net-libs/webkit-gtk can take a long time. I want to reboot into another OS and resume this ebuild at a later time.


 * I use genlop from app-portage/genlop to inspect my current emerge.


 * I ctrl-C out of the current emerge
 * since I am rebooting, I'll have to use cp -a or tar -cpf to save /var/tmp/portage/* while preserving permissions. Otherwise the tmpfs contents will be lost; You may want to inspect the memory size of /var/tmp/portage by using du:


 * reboot, do other stuff, come back
 * restore /var/tmp/portage/*
 * resume the ebuild -- DO NOT use the ebuild found in /var/tmp/portage/*path-to-package*/build-info/*packagename-ver*.ebuild. It seems to cause immediate failure. Use the ebuild in /usr/portage/*path-to-package*/*packagename-ver*.ebuild.

Happy hacking :)