How to speed up things by using tmpfs

root's picture

You may know (or not) that /dev/shm/ is a direct read/write access to your memory (RAM). So everything you copy to that place is in fact stored in your RAM, hence, it is turbocharged fast!

By default, the size of /dev/shm/ is half the memory size so if you have 8G of ram, this filesystem will have 4G:

core:shm# df -h .
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 4.0G     0  4.0G   0% /dev/shm
core:shm# cat /proc/meminfo | grep MemTotal
MemTotal:        8190552 kB

If you want to make this fs bigger (do it at your own risk - remember, this is in your RAM):

core:shm# mount -o remount,size=6G /dev/shm

Heck, you can also create a different volume group like the default one:

core:shm# mkdir -p /my/superfast/application/ramstorage
core:shm# mount -t tmpfs -o size=500M,mode=0744 tmpfs /my/superfast/application/ramstorage

If you want this after reboot, do not forget to add it to /etc/fstab:
tmpfs /my/superfast/application/ramstorage tmpfs size=500M,mode=0777 0 0

Play as much as you want but remember something very important: tmpfs is volatile memory so after reboot everything will disappear from there (will be gone forever). You may have to tweak things a bit like for example copy the stuff to hard disk on shutdown and put them back on startup. Of course, if you need that temporary file up2date, to back it up from time to time.

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root