20

I have loads of RAM and I use very little. I also do record some screencasts with gtk-recordmydesktop, which by default saves to /tmp while recording. I assumed that it would mean storing to RAM as much as possible, but then I actually checked and found that /tmp isn't mounted with tmpfs. Why is that?

Lekensteyn
  • 174,277

3 Answers3

19

I think you answered your own question. A lot of programs use /tmp for storing temporary files, and they can be huge.

For example Brasero defaults to that directory to store a CD/DVD's image file, which can be 4.7 GB of size. It's not worth risking a serious slowdown (or a system lockup) in an out of memory situation if your RAM and swap get full.

For advanced users it's no problem to change some applications' defaults and mount /tmp as tmpfs. For general use it's just not worth the risk I guess.

arrange
  • 14,959
  • 1
    And, I think you might get a little angry and curse the developers if you recorded a few great screencasts and then, after a power outage or system hitch, lost them all. ;) – arrange Sep 25 '11 at 20:12
  • And the stuff in /tmp might even reside in the RAM and never touch the disk if you use ext4. – LasseValentini Sep 25 '11 at 21:00
  • @Fraekkert: What do you mean? Why ext4? Why never? Can you elaborate please? – arrange Sep 25 '11 at 21:20
  • 1
    It's not unique to ext4, but it's because of Delayed allocation. Essentially it means that files are not necessarily written to disk just because a program tells the os to do so. Instead it is kept in the ram for quick access. If the file is deleted relatively quickly thereafter, it would never reach the disk. Have a look at wikipedia if you need more info. – LasseValentini Sep 26 '11 at 07:10
  • @Fraekkert: I think the commit time is 5 secs for ext4, and the allocation is delayed until next commit, so it doesn't help much in this case, does it? – arrange Sep 26 '11 at 11:52
  • Hmm, generally speaking, under ext4 it is 30 seconds, not 5. So if you remove the file within 30 secs, it might not be actually written out to disk. Thanks for the pointers. – arrange Sep 26 '11 at 20:18
  • 1
    For reference, here is a comment explaining the 5/30 seconds topic in detail: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/317781/comments/45 – lxgr Sep 23 '12 at 07:41
11

What about zram compression ?

The available space is more than 256 Mbytes, it depends on files' type.

modprobe zram num_devices=1 
# max ram usage = 256 Mbytes
echo 262144 > /sys/block/zram0/disksize
mke2fs -q -m 0 -b 4096 -O sparse_super -L zram /dev/zram0
mount -o relatime,noexec,nosuid /dev/zram0 /tmp
Massimo
  • 280
8

There was an idea to use tmpfs while it has enough space, and write to disk when you run out of space: http://www.bigdbahead.com/?p=137 However, it never really took off. I've managed to get it working, but the FUSE overhead defeats any benefit of using tmpfs: http://shnatsel.blogspot.com/2011/11/miniwheatfs-aka-reliable-ramdisks.html

Shnatsel
  • 1,188