Syntax coloring

sexta-feira, 27 de março de 2015

Java / GWT development with tmpfs (or, why is my development slower because I've switched to Arch Linux)

I've recently switched from Ubuntu to Arch Linux (Antergos, really, as it provides a decent installer and nice defaults, and is just Arch in the end).
Arch uses systemd (the controversial init system that has caused lots of debates, but I have personally loved it), and since the upcoming 15.04 version, Ubuntu will use it too.
And systemd by default mounts the /tmp directory files using a tmpfs, which is mounted on RAM, limited by default to half the physical available memory. Also, in my installation (don't know if this is Arch's or Antergos' default), the /etc/fstab file also had the /tmp to be mounted as tmpfs.
This might be nice for most people, but if you run applications that store huge amounts of data in /tmp, it can be terrible.
In my case it is GWT which writes hundreds of megabytes to the temporary folder.
Result? When GWT is compiling Java to JavaScript code, things get SLOOOOOW, because:
  • Eclipse uses1.0-1.5GB of RAM
  • The GWT SuperDevMode, together with the running application, takes another 1.0-1.5GB
  • Chrome uses 1.0-2.0GB of RAM with several open tabs (and when dev tools is open, it eats a lot of RAM too)
Counting up to 4GB (max) of tmpfs, and the desktop environment (Cinnamon in my case), Skype, DropBox and others, my 8GB quickly get short.

At least I found that I can improve things by disabling mounting /tmp as tmpfs.
To do that I've resorted, as usual, to the excellent Arch Wiki (by the way, one of the best pieces of documentation for any project I've ever seen):

I have removed the line in /etc/fstab which declares /tmp as tmpfs and created the /etc/tmpfiles.d/tmp.conf file with the following content:

# see tmpfiles.d(5)
# always enable /tmp folder cleaning
D! /tmp 1777 root root 0

# remove files in /var/tmp older than 10 days
D /var/tmp 1777 root root 10d

# namespace mountpoints (PrivateTmp=yes) are excluded from removal
x /tmp/systemd-private-*
x /var/tmp/systemd-private-*
X /tmp/systemd-private-*/tmp
X /var/tmp/systemd-private-*/tmp

Then we need to tell systemd to not mount /tmp as tmpfs automatically, with the following command:
systemctl mask tmp.mount

Afterwards, just rebooted the system and.... magic! I can nicely work with GWT compilation again.

As Ubuntu 15.04 will switch to systemd, and systemd by default mounts /tmp as tmpfs even without anything defined in /etc/fstab, this might affect Ubuntu too in the future. The same is true to other major distributions.