I'm using 2G of tmpfs for /tmp dir to increase performance for java unit-testing: they are performing IO operations intensively in /tmp.
Here is my tmp section from /etc/fstab file:

tmpfs /tmp tmpfs rw,noatime,size=2G,nodev,mode=1777,noexec,nosuid,rootcontext=system_u:object_r:tmp_t 0 0

Almost always it's working fine, but sometimes I need more than 2G disk space in /tmp. It usually happens when some application downloading updates. In this case performance is not critical for me, so I'd like to write it to physical volume or loopback file.

Is it possible to use tmpfs if /tmp dir size is less than 2G and extend it with other file system when required?

  • 1
    Could the program not perform the download in another path? – Kusalananda Sep 23 '17 at 10:58
  • @Kusalananda no, I can't control this programs – g4s8 Sep 23 '17 at 11:00
  • If the program downloads into a directory under /tmp, symlink it to somewhere else? – Kusalananda Sep 23 '17 at 11:19
  • 2
    Related: tmpfs does not overflow to swap. – Stephen Kitt Sep 23 '17 at 11:23
  • 2
    Can you change the paths used by the unit tests for their temporary files? (Probably using java.io.tmpdir...) That way you could have /tmp as a regular filesystem, big enough for the applications downloading updates, and a tmpfs just for your unit tests. – Stephen Kitt Sep 23 '17 at 11:58

If you just need to change tmpfs size, you can remount it on-line with new size:

mount -o remount,size=<new size> /tmp

Also, have a sufficiently large swap on your system. When available free RAM is low, memory (including tmpfs) will be paged to swap.

Swap won't be slowing your system, kernel swaps the least used and cached first and the balance can be adjusted with vm.swappiness parameter. For a good explanation for vm.swappiness, see Why is swappiness set to 60 by default?. If the system starts to slow due active pages being swapped, the cause is not swap; the reason is that your system is running out of RAM.

You can increase total swap space by creating a swap file (note: you can't place a swap file on btrfs file system). Create and allocate a new file with dd and set it up as swap area with mkswap. Make sure the swap file is not world readable, you don't want to leak your memory contents.

dd if=/dev/zero of=<swap file> bs=1M count=<size>
chmod 600 <swap file>
mkswap <swap file>

And to enable it:

swapon <swap file>

You can also add the swap file to fstab to make it available automatically.

  • Thanks for anwer, but it doesn't satisfy me, because it makes all other applications slow. I want to control tmpfs size that used by /tmp – g4s8 Sep 23 '17 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.