Using a RAM disk as /tmp on FreeBSD

Since I switched my old server to my desktop, I got a desktop with 4G RAM, and I’m running, of cause FreeBSD-amd64 on it.

However after several days of usage I found I can only use 2G~3G memory on typical days. The rest are free or intact. This might because I’m still using the config files I tweaked for my old notebook, where I have only 256M memory. I was thinking once to switch back to FreeBSD-i386 to get the Binaries like Google Earth or win32-codecs, or something that couldn’t compile on amd64 like audio/beep or textproc/sdcv.

But I’ve got another idea: I could use the extra RAM to build a RAM disk, and mount it on /tmp. Thus I could take advantage of this much faster /tmp. Of cause all the content on a RAM disk is lost if I do a reboot, but I already have

clear_tmp_enable="YES"    # Clear /tmp at startup.

in my /etc/rc.conf so I got nothing to lose.

And it turns to be easier to setup than I thought. Just add one line

md                      /tmp            mfs     rw,noatime,-s512M 0 0

into /etc/fstab and do a reboot. Among other things the “-s” option tells how big I want the RAM disk to be. And I think 512M is good for me. Also a RAM disk won’t take all the 512M memory all the time. This is just the max size of the RAM disk. And when I have only a little files in /tmp, it takes only a little RAM. Check md(4) for all the details.

Tags:

Post a Comment

You could use <code type="name"> to get your code colorized

Your email is never published nor shared. Required fields are marked *

Close
E-mail It