Archive for May, 2009

Optimizing Portage compiling on Gentoo with ccache + shm.

I knew about ccache long time ago, also knew about shm (shared memory) on Linux but I realized that I could:

1. Mount my tmp partition on shm, so all the temporary files would be written on RAM, instead of HDD.

2. Now I set the ccache directory to my tmp directory, this way the ccache files will be written directly to RAM, gaining a better performance than usual.

Now add the following lines to /etc/fstab:

/dev/shm                /tmp              tmpfs           defaults,size=80m,auto 0 0

/dev/shm                /var/tmp          tmpfs           defaults,size=80m,auto 0 0

It is defining 80MB for maximum RAM usage by temporary files, you can define more or less memory, as you wish, of course. The flag “auto” defines that these partitions should be loaded automatically at the boot time.

Now add the folowing line for the /etc/make.conf:

CCACHE_DIR=”/tmp/ccache”

This way, ccache will write to your RAM. Now you can try recompiling your whole system with emerge for a test, you’re gonna realize that your HDD won’t get much stress when compiling the sources, since all the temporary files generated during the compiling process are now written directly to RAM.

I will not get into deeper details about ccache and shm, so I suggest you to read the “references”, if you want to know some more.

References:

#man ccache

http://fscked.org/writings/SHM/shm-1.html#ss1.1

http://en.gentoo-wiki.com/wiki/Ccache

http://blog.flameeyes.eu/2008/06/21/debuking-ccache-myths

http://ccache.samba.org/ (official website)

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=3#doc_chap3

http://www.tuxfiles.org/linuxhelp/fstab.html (fstab tutorial)

How to keep running processes in background after disconnecting in a remote session

Maybe most of you know about it, but I think it would be nice to mention something about this tool anyway.

For example, when you are in a remote box through SSH (or telnet, etc) , you may want to download a big file from another remote location using wget, but for any reason you cannot stay connected until the download gets finished, so you can use the “nohup” command to keep track of this situation.

All the output will be written to a specified file (torrent.out in our example), if you don’t specify it, then it will gonna be named as “nohup.out”.

Usage example:

#nohup transmissioncli stuff.torrent > torrent.out  &

You can still watch the output in real time using the following command:

#tail -f torrent.out

When you think you got enough of it, just “ctrl c” and disconnected from the remote server. Then tomorrow you can connect again and check your process status output again using “tail -f torent.out” again.

Very useful, eh?! 😉

References:

#man nohup