Using tmpfs RAM disk and noatime option to speed up performance in GNU/Linux

in #linux7 years ago (edited)

Most GNU/Linux distributions make it relatively simple to take advantage of the speed of RAM, and it can vastly improve the speed of the process of downloading & extracting, upgrading & installing files on the system. It can also improve the performance of programs which make use of on-disk caching and temporary files.

By default, many operations such as package downloading, installation, and data caching are writing & reading to/from the disk (and archives are downloaded to disk, extracted from disk to disk).

Downloading and writing directly to RAM instead (and extracting archives from RAM to disk) can be utilised to speed up package manager data for installs and upgrades, and also writing and reading from ~/.cache and /tmpmounted into RAM on systems where it would usually be writing and reading the disk. RAM operations can be orders of magnitude faster than disk operations.

A lot of people these days have a lot of RAM in their system, and this is a great way to put it to work. Using the noatime mount option will also improve disk performance.

It can be easily implemented by simply editing the /etc/fstab file.
Here is an example /etc/fstab file for reference:

# <fs>      <mount point>           <type>  <options>                                       <dump><pass>
# the root fs
/dev/sda1   /                       jfs     noatime,errors=remount-ro                       0       1

# the tmpfs RAM mounts
tmpfs       /var/cache/apt          tmpfs   size=4g,noatime,mode=0755,uid=0,gid=0           0   0
tmpfs       /tmp                    tmpfs   size=4g,noatime                                 0   0
tmpfs       /var/tmp                tmpfs   size=4g,noatime                                 0   0
tmpfs       /home/alice/.cache      tmpfs   size=4g,noatime,mode=0700,uid=1000,gid=1000 0   0
tmpfs       /home/bob/.cache        tmpfs   size=4g,noatime,mode=0700,uid=1001,gid=1001     0   0
tmpfs       /ram                    tmpfs   size=8g,noatime,mode=0700,uid=1000,gid=1000     0   0
  • note: please modify accordingly to your system (depending on package manager, user home folder locations, permissions, and uid/gid)

  • to find the uid and gid of the user alice for example, use id alice and it will show the uid and gid of alice.

after rebooting, the new mounts will fully take effect. (you can enable them using mount without a reboot, but it may be best to reboot to start a fresh cache, etc.)

In the above example we are mounting various folders into tmpfs, which is effectively the system RAM.

  • mounting /var/cache/apt as tmpfs, the apt package manager will be downloading all archives to RAM, and extracting them from RAM to disk. This speeds up installations and upgrades.

  • mounting /tmp,/var/tmp and ~/.cache as tmpfs, various running programs will be using RAM as the cache and temp, instead of the disk (some distros may already have /tmp mounted as tmpfs). This speeds up application performance.

  • mounting /ram as tmpfs, gives us a general folder to use as RAM disk, with a size of 8GB. This can be used to download files, archives to extract to disk, etc., where the speed of RAM is desirable.

  • the size=[x] option will specify how much RAM can be used for each mountpoint.

  • the mode=[xxxx] option will set the directory permissions (who can read, write, and execute)

  • using the noatimeoption will eliminate needless disk operations, improving all disk performance. (see here for a short explanation of noatime benefits: http://en.tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap6sec73.html ) ... noatime also implies nodiratime -- you do not need both, noatime is effectively both.

This can be modified and tailored to suit your needs, and can be adapted to any GNU/Linux system which supports the tmpfs filesystem.

Just make sure to have a lot of RAM, and to clear the package manager files and cache/tmp files from time to time, to prevent the RAM from becoming full. Because it is RAM, these clearing operations will also be lightning fast.

  • invoking sync && echo 3 > /proc/sys/vm/drop_caches as root can be used to further free up the RAM after removing package manager archives and temp files, etc. See the drop_caches section of the official kernel.org documentation for more information on using the /proc/sys/vm/ sysctl files: https://www.kernel.org/doc/Documentation/sysctl/vm.txt

Any comments or suggestions? Please comment!

If you found this useful, please upvote and share!

ZEN: znSTMxvU3AizLV9cAm4iNPT5uLoJ2wbfHy9
MONA: MHPv3DnyoY3xXGQkgDrHhvXuiCChnTUZjT
BTC: 1EwGXrmGdiD6Xd8uPnmRufyoWowJ7qpkJ1

Sort:  

Congratulations @hairetikos! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @hairetikos! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!