Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

After seeing the comment by Anonymous on the question How is the /tmp directory cleaned up?, I found that it would be a great idea to implement on my system, since I have 16GB of RAM and I never used all of it.

My temporary files never get written to the disk. They get written to a RAM disk. I did put tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0 in /etc/fstab.

My question is:

Can I set a maximum value for RAM Usage for /tmp? And in that case, what would happen if the maximum amount got exceeded, would it write into the hard-disk drive?

I have read this solution which states:

mkdir -p /tmp/ram
sudo mount -t tmpfs -o size=512M tmpfs /tmp/ram/

But in my understanding, this won't be a permanent solution. If I need it to be permanent, it has to be added to the /etc/fstab configuration file.

If this is the correct solution, how can I transform that mount command into a line in /etc/fstab?

share|improve this question
    
this is also a good idea if you have and SSD as you will not 'consume' it with not useful writings ... –  Postadelmaga Apr 2 at 10:47

1 Answer 1

up vote 23 down vote accepted

You are absolutely right. The according fstab entry would look like this:

tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=512M 0 0

Please note:

As tmpfs gets filled up, it will behave as any physical harddrive by giving an "not enough space" error. While rebooting (and thus emptying the cache) will fix this, you may run into trouble when a single operation consumes more space to begin with than there's space on tmpfs. In this case your computer will start to swap from ram to disk, which will make your system crawl to a halt, given you've got a swap partition to begin with, of course.

Considering this, a size of 512MB might be far too less nowadays, since much more ram is in existence in modern machines and it has become much cheaper. Since you've already got 16GB of ram, using the default value of half your ram for tmpfs should more than suffice for almost all scenarios. To use the default value, simply leave out the size=512M entry in your /etc/fstab file.

Another note:

You can quite as easily mount other system folders into ramdisk as well, such as

/var/cache

/var/games

/var/log/apt (use only defaults,noatime without mode= or nosuid)

But beware: the same rules apply as above, running out of space might cause major trouble. E.g. imagine running out of space for /var/log/apt will render you unable to install any programs! Furthermore, loading /var/log folders into ramdisk will delete all your log files upon reboot, so you won't be able to debug your system if anything unexpected happens. So use these settings at your own risk!

Editorial note: I removed the /run in tmpfs mount option since this folder and its subfolders are already mounted in tmpfs by default.

share|improve this answer
2  
If i'm not wrong, /var/tmp/ is for keeping files after reboot. Thats the main difference between this and /tmp/ , so YOU should not move /var/tmp to ram. –  lancemark May 27 at 13:20
    
I checked that and you seem to be right. I scratched it from the answer. Thanks for clearing that up! –  FuzzyQ May 27 at 14:13
1  
I'd add the nodev option also. –  Mausy5043 Jun 12 at 19:24
    
Thanks for the hint! I added security related mount options nosuid, nodev and noexec. –  FuzzyQ Jun 13 at 12:36
1  
If Ubuntu runs out of 4GB tmpfs, will it use my 20GB SWAP partition? –  loostro Jun 24 at 16:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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