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.

<p dir="auto">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). <p dir="auto">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 <code>~/.cache and <code>/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. <p dir="auto">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 <code>noatime mount option will also improve disk performance. <p dir="auto">It can be easily implemented by simply editing the <code>/etc/fstab file.<br /> Here is an example <code>/etc/fstab file for reference: <pre><code># <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 <ul> <li><p dir="auto"><strong><em>note: please modify accordingly to your system (depending on package manager, user home folder locations, permissions, and uid/gid) <li><p dir="auto">to find the <code>uid and <code>gid of the user <code>alice for example, use <code>id alice and it will show the <code>uid and <code>gid of alice. <p dir="auto">after rebooting, the new mounts will fully take effect. <em>(you can enable them using <code>mount without a reboot, but it may be best to reboot to start a fresh cache, etc.) <p dir="auto">In the above example we are mounting various folders into <code>tmpfs, which is effectively the system RAM. <ul> <li><p dir="auto">mounting <code>/var/cache/apt as <code>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. <li><p dir="auto">mounting <code>/tmp,<code>/var/tmp and <code>~/.cache as <code>tmpfs, various running programs will be using RAM as the cache and temp, instead of the disk (some distros may already have <code>/tmp mounted as tmpfs). This speeds up application performance. <li><p dir="auto">mounting <code>/ram as <code>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. <li><p dir="auto">the <code>size=[x] option will specify how much RAM can be used for each mountpoint. <li><p dir="auto">the <code>mode=[xxxx] option will set the directory permissions (who can read, write, and execute) <li><p dir="auto">using the <code>noatimeoption will eliminate needless disk operations, improving all disk performance. (see here for a short explanation of <code>noatime<code>noatime also implies <code>nodiratime -- you do not need both, <code>noatime is effectively both.<span> benefits: <a href="http://en.tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap6sec73.html" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">http://en.tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap6sec73.html ) ... <p dir="auto">This can be modified and tailored to suit your needs, and can be adapted to any GNU/Linux system which supports the <code>tmpfs filesystem. <p dir="auto">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. <ul> <li>invoking <code>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 <code>drop_caches section of the official kernel.org documentation for more information on using the <code>/proc/sys/vm/<span> sysctl files: <a href="https://www.kernel.org/doc/Documentation/sysctl/vm.txt" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://www.kernel.org/doc/Documentation/sysctl/vm.txt <p dir="auto"><em>Any comments or suggestions? Please comment! <p dir="auto"><em>If you found this useful, please upvote and share! <p dir="auto">ZEN: znSTMxvU3AizLV9cAm4iNPT5uLoJ2wbfHy9<br /> MONA: MHPv3DnyoY3xXGQkgDrHhvXuiCChnTUZjT<br /> 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!