Portage TMPDIR on tmpfs
From Gentoo Linux Wiki
Contents |
[edit] Introduction
When emerging a package, Portage creates many temporary files in PORTAGE_TMPDIR (defaults to /var/tmp) and transfers a lot of temporary data to and from the filesystem, usually on a typical harddrive. tmpfs, or virtual memory file system, is a segment of your RAM that acts as regular "storage" memory. Mounting a tmpfs to a directory where there's a lot of I/O activity saves the data the trip to the actual harddrive and therefore speeds up I/O heavy processes, like compiling. A tmpfs mounted on PORTAGE_TMPDIR, keeping the temporary data in RAM, will thus lower compile time.
[edit] Requirements
You need to have a kernel with swap and Virtual memory file system support enabled. Almost all default kernel configurations have these enabled.
| Linux Kernel Configuration: Enable the Virtual memory file system |
File systems --->
Pseudo filesystems --->
[*] Virtual memory file system support (former shm fs)
|
[edit] fstab
Add the tmpfs entry to /etc/fstab,
tmpfs /var/tmp/portage tmpfs size=500M,mode=0777 0 0
Note the size option, this is the size limit of the filesystem residing in memory (meant as RAM and eventually swap, like any other process in the system). Writing only one byte more that size will result in a 'no space left' error.
For one single merge 500MB are OK most of the time. If you have multiple merges running or you compile big packages from source you should set it to 1GB or even 2GB to be on the safe side. To compile Open Office you need 4 to 5 Gigabytes of space available. You will need more than 2GB to compile mail-client/mozilla-thunderbird-3.0. You will also need more than 1GB to compile sys-devel/gcc-4.3.2-r3 or kde-base/kdelibs-4.2.4(1.8GB with the doc USE flag enabled).
If you create an entry without the size argument, the limit will be set to half of your RAM. Be sure to have enough swap space to handle the size of your full tmpfs + anything you're likely to be running - amount of physical RAM. [1]
Mount the tmpfs,
[edit] Automation
Here is a little script that you can put into /usr/local/sbin/ if you only want to use tmpfs for certain packages
- this doesn't need the line in /etc/fstab
- checks if /var/tmp/portage is already mounted (then quits, because it would confuse the other emerge process)
- mounts tmpfs to /var/tmp/portage
- runs emerge
- unmounts /var/tmp/portage
#!/bin/bash
MEMSIZE=800M
mounted=false
. /etc/init.d/functions.sh
mounttmpfs() {
mount -t tmpfs -o size=$MEMSIZE,nr_inodes=1M tmpfs /var/tmp/portage
mounted="true"
}
compile() {
einfo "running emerge ${*}"
emerge ${*}
}
unmount() {
ebegin "unmounting tmpfs"
umount -f /var/tmp/portage
eend $?
}
ebegin "Mounting $MEMSIZE of memory to /var/tmp/portage"
if [ -z "$(pgrep -f /usr/bin/emerge)" ];then
if [ -z "$(mount | grep /var/tmp/portage)" ];then
mounttmpfs
else
eerror "tmpfs already mounted!"
exit 0
fi
else
eerror "emerge already running!"
exit 0
fi
eend $?
# the next line would change the cpu-governour, if available, to the highest frequency
#[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ] && echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# run emerge
compile $@
# unmount tmpfs
$mounted && umount /var/tmp/portage
# and set the scheduler back to "ondemand"
#[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ] && echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
