{"id":260563,"date":"2021-05-27T19:00:29","date_gmt":"2021-05-27T16:00:29","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-enlarge-tmpfs-space-in-linux-cloudsavvy-it\/"},"modified":"2021-05-27T19:00:29","modified_gmt":"2021-05-27T16:00:29","slug":"how-to-enlarge-tmpfs-space-in-linux-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-enlarge-tmpfs-space-in-linux-cloudsavvy-it\/","title":{"rendered":"#How to Enlarge tmpfs Space in Linux \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a23a299d37a5\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a23a299d37a5\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-enlarge-tmpfs-space-in-linux-cloudsavvy-it\/#What_Is_tmpfs\" >What Is tmpfs?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-enlarge-tmpfs-space-in-linux-cloudsavvy-it\/#Your_Current_tmpfs_Size\" >Your Current tmpfs Size<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-enlarge-tmpfs-space-in-linux-cloudsavvy-it\/#Enlarging_tmpfs_on_Your_System\" >Enlarging tmpfs on Your System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-enlarge-tmpfs-space-in-linux-cloudsavvy-it\/#Wrapping_up\" >Wrapping up<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Enlarge tmpfs Space in Linux \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-4038\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Bash Shell\" width=\"1400\" height=\"600\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Have you ever heard of tmpfs in Linux? It is that small temporary file system residing within memory and installed by default on Linux distributions. Ultra-fast but usually limited in size. Can one grow it easily? Find out &amp; more!<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_tmpfs\"><\/span>What Is <i>tmpfs<\/i>?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Everything inside of a computer has a certain native speed of operation. It starts with the CPU (the Central Processing Unit) in your computer, which has a set of L1-Lx caches (Level 1 to Level x), which are very small (for example, 16Kb) but ultra-fast (and likely ultra-expensive).<\/p>\n<p>After the CPU caches, there are the main memory banks, which are still much faster (and byte-for-byte more expensive) than hard disk and so on. As you can see, it\u2019s about cost versus size versus speed. The <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a> rule is that the cost goes up as speed goes up and that the size will come down to limit the cost, etc.<\/p>\n<p>If you would store all of your data inside the main memory chips of your computer, which is technically ultra-possible and rather easy to do, your work would literally <i>fly<\/i> compared to when you\u2019re using disk alone, as memory chips are much faster than most hard disk drives.<\/p>\n<p>There are, however, some technical limitations with this. Once you shut down your computer, your files will be gone. An unrecoverable <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>lication crash could be enough to make you have to restart your computer and lose your files. Also, you could never shut down your computer again, unless it had some advanced feature (which doesn\u2019t exist as far as I know) to maintain your files in the memory chips, similar to a BBU-supported (Battery Backup Unit) cache on a raid controller.<\/p>\n<p>Note that there is, however, one similar (but not identical) feature to this that you might already be using: When you suspend your system to RAM (using <i>sleep<\/i> or other likewise terminology employed by operating systems), some power will be continually provided to your memory chips to maintain their current data.<\/p>\n<p>Then, when you resume your system, you will be able to continue where you left off. But shutting down while maintaining memory contents is generally not used with computers. It might potentially be used by smart tablets, although one could argue that such states are not true shutdown states, but rather, low-power states.<\/p>\n<p>Having clarified how, generally speaking, it\u2019s likely not a solid idea to save your files to memory chips, there are some other uses where it could come in handy. For example, when doing testing\/quality assurance against programs, you are likely going to be starting and shutting down the program under test many times.<\/p>\n<p>Such files are temporary and of little individual value (unless a bug is found, at which point, the data can be copied back to the main disk), and as such, could be stored in your memory chips. This is what <code>tmpfs<\/code> is and does: It\u2019s a temporary file system inside your memory. Some of you might im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely object and say, \u201cThat\u2019s not true,\u201d and you would be correct. Read on.<\/p>\n<p>Those who would have objected might have immediately made the assertion that the <i>tmpfs<\/i> space is not guaranteed to be in memory, and this is true. You can see <code>tmpfs<\/code> as a hybrid between a true ram disk (a disk created in volatile memory) and actual permanent disk storage. In certain cases, the Linux kernel will swap out tmpfs content into the system swap space, which could be on disk. This is done transparently (without user interaction being necessary).<\/p>\n<p>If you want to learn more about setting up a ramdisk instead, see our How to Create a RAM Drive in Linux guide.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Your_Current_tmpfs_Size\"><\/span>Your Current <i>tmpfs<\/i> Size<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that we have <code>tmpfs<\/code> space better defined, let\u2019s take a look at the current size of your <code>tmpfs<\/code> space. You might think of the <code>tmpfs<\/code> system like a virtual, temporary, volatile drive. You can see the space in use using <code>df -h<\/code> (file system disk space usage (<code>df<\/code>) in human-readable format, thanks to the <code>-h<\/code> option):<\/p>\n<pre>df -h | grep -Ei 'shm|size'&#13;\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10364\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/03\/3465600b.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Checking the current tmpfs usage using df -h\" width=\"531\" height=\"70\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here, we use <code>df -h<\/code> (explained above) combined with a pipe (<code>|<\/code>) to send the resulting output from the <code>df -h<\/code> to a <code>grep<\/code>, which uses an extended (<code>-E<\/code>) regex format in a case-insensitive manner (<code>-i<\/code> or simply <i>i<\/i> when combined with another option) to select the top title (which includes the word <code>Size<\/code>) and any line that includes the text <code>shm<\/code>.<\/p>\n<p>The reason that we grep for <code>shm<\/code> is that almost always, as we can also see in the output here, the tmpfs space is mapped to the file system directory <code>\/dev\/shm<\/code>. If the above command doesn\u2019t generate any output, simply execute <code>df -h<\/code> and review the total results to look for <code>tmpfs<\/code> space, if any.<\/p>\n<p>Note that by default, the operating system will also allocate\/set some tmpfs spaces, which might, for example, be mapped\/mounted to the <code>\/sys\/fs\/cgroup<\/code>, <code>\/run<\/code> and <code>\/run\/lock<\/code> directories. Please do not try and modify these.<\/p>\n<p>As for the <code>\/dev\/shm<\/code> and other directories, please note that seeing these folders in the operating system directory structure [tree] doesn\u2019t mean that the files are actually\/physically stored in-disk in some <code>\/dev\/shm<\/code> directory!<\/p>\n<p>It simply means that, according to and in line with the standard Linux way of being able to mount drives (or in this case, tmpfs) to any directory in the file system hierarchy, if there were files in such a directory prior to the mounting, they would simply not be visible until the mount point was dropped.<\/p>\n<p>On this particular system, the <code>tmpfs<\/code> space is 32GB, and almost all of that is unused. The little that is in use (166MB) is the directory meta\/index table itself, which is invisible to users, but in place to be able to store files into the file system structure. The size of the <code>tmpfs<\/code> is, by default, half of the system memory for given operating systems.<\/p>\n<p>This is a fairly large <code>tmpfs<\/code> and would only be technically justified, to some extent, on a system with, for example, 40GB or more of physical memory, although, depending on the circumstances, a particular use case might warrant other setups. In general, I recommend keeping the <code>tmpfs<\/code> space less than, let\u2019s say, 70-80% of the memory, and that percentage would be significantly lower if RAM (<i>Random Access Memory<\/i>, another shorthand or way to refer to your system memory) was small to start with.<\/p>\n<p>The reason for this is that you want to leave enough memory space available for running other programs, operating systems, and software services.<\/p>\n<p>For example, you wouldn\u2019t want to allocate 80% of memory if your system had 2GB of memory, as this would likely leave way too little for other things to operate correctly or at all. If, on the other hand, you have a hefty 256GB of memory, even 90% of that (230.4GB) would leave a nice 25GB available, which\u2014depending on the use case\u2014might (or might not) be plenty.<\/p>\n<p>In summary, I recommend that you always tune the size of <code>tmpfs<\/code> depending on 1) how much space you really need in tmpfs, 2) how much memory is in your system, and 3) how much actual memory other applications are using besides tmpfs (including your operating, services, etc.). Experience with all of these things helps here.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Enlarging_tmpfs_on_Your_System\"><\/span>Enlarging <i>tmpfs<\/i> on Your System<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that we know the size of the current <code>tmpfs<\/code> volume and what size to give it in the future using some of the considerations provided in the last paragraph above, we can take a look at enlarging (or shrinking) our <code>tmpfs<\/code> space.<\/p>\n<p>Doing so is quite easy. All we have to do is, rather than having the operating system automatically configuring the <code>\/dev\/shm<\/code> tmpfs space for us, define it statically instead in the regular <code>\/etc\/fstab<\/code> file, which controls drive mappings at startup. We simply add:<\/p>\n<pre># &lt;file system&gt; &lt;mount point&gt; &lt;type&gt; &lt;options&gt;                                       &lt;dump&gt; &lt;pass&gt;&#13;\ntmpfs           \/dev\/shm      tmpfs  defaults,rw,nodev,nofail,noatime,nosuid,size=2G   0      0&#13;\n<\/pre>\n<p>to the <code>\/etc\/fstab<\/code> file. Do not copy the first remarked (<code>#<\/code> prefixed) line, as that will already be there. Also, change the <code>2G<\/code> (2GB) size to your calculated\/estimated requirement for tmpfs size. It\u2019s likely not helpful to set this close to or over the size of available memory, as we explained earlier.<\/p>\n<p>The header markings in the <code>\/etc\/fstab<\/code> file clarify the meanings of the fields, and you can find more information in the <code>fstab<\/code> manual, which can be obtained by typing <code>man fstab<\/code>. Basically, we\u2019re asking the operating system to mount a <code>tmpfs<\/code> file system (The location of the system is in memory, so rather than specifying a device, we indicate <code>tmpfs<\/code>.) and that of the type <code>tmpfs<\/code>, mounted at <code>\/dev\/shm<\/code>.<\/p>\n<p>We also set a number of options. You\u2019ll likely want to leave the <code>defaults,rw,nodev,nofail<\/code> at a minimum (Use defaults, read\/write access, no physical device present, and do not fail to start the operating system if this mount somehow fails.).<\/p>\n<p>You could also choose to leave the optimizations options <code>noatime,nosuid<\/code> if you like (which is ideal for testing\/QA setups, as it will make it faster while keeping less information about files on the tmpfs space), or you can remove those (and their matching commas). Also, leave (and change\/specify the size) the <code>size=xG<\/code> parameter. Finally, we have a rather standard <code>0 0<\/code> for <code>dump and pass<\/code> (ref <code>man fstab<\/code> for more info on these two options).<\/p>\n<p>Once the change has been made, simply restart your system and execute <code>df -h<\/code> to verify that your <code>\/dev\/shm<\/code> tmpfs space is now at the new size that you set it to be. If something went amiss, simply check <code>dmesg<\/code> (typed at your command prompt) and scan upward for any red error messages (You likely have to scroll.) to find out what went amiss. Even though something went amiss, the system should have started fine anyway, provided that you didn\u2019t remove the <code>nofail<\/code> option.<\/p>\n<p>For Ubuntu users, there is, however, a possible <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/bugs.launchpad.net\/ubuntu\/+source\/mountall\/+bug\/610869\">nofail bug<\/a> to be aware of. There used to be an alternative <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/unix.stackexchange.com\/questions\/53456\/what-is-the-difference-between-nobootwait-and-nofail-in-fstab\">nobootwait<\/a> option [instead], although it\u2019s not clear whether this is still usable and if so, on what versions of Ubuntu and its derivatives [only]. As a final alternative to test, provided that SystemD is being used, one could consider using the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/unix.stackexchange.com\/a\/513590\/241016\">x-systemd.device-timeout=10<\/a> timeout, where 10 is the number of seconds one is willing to wait during startup.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Wrapping_up\"><\/span>Wrapping up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In this article, we took a thorough look at <code>tmpfs<\/code> sizing, keeping in mind the use case and other factors.<\/p>\n<p>We also explained <code>tmpfs<\/code> in detail, discovered how to find the current size of the machine\u2019s <code>tmpfs<\/code> file system, and finally looked at how to resize tmpfs.<\/p>\n<p>Enjoy using tmpfs!\n<\/p><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/10362\/how-to-enlarge-tmpfs-space-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Enlarge tmpfs Space in Linux \u2013 CloudSavvy IT&#8221; Have you ever heard of tmpfs in Linux? It is that small temporary file system residing within memory and installed by default on Linux distributions. Ultra-fast but usually limited in size. Can one grow it easily? Find out &amp; more! What Is tmpfs? Everything inside&#8230;<\/p>\n","protected":false},"author":1,"featured_media":260564,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-260563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/260563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=260563"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/260563\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/260564"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=260563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=260563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=260563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}