<div class="sect1"> <h2 id="_whats_going_on">What’s going on?</h2> <div class="sectionbody"> <div class="paragraph"> <p>Like all modern operating systems, Linux is borrowing unused memory for disk caching. This makes it look like you are low on "free" memory, but you are not! Everything is fine!</p> </div> </div> </div> <div class="sect1"> <h2 id="_why_is_it_doing_this">Why is it doing this?</h2> <div class="sectionbody"> <div class="paragraph"> <p>Disk caching makes the system much faster and more responsive! There are no downsides, except for confusing users who are new to computing, and unfamiliar with the concept of a filesystem cache. It doesn’t generally take memory away from applications.</p> </div> </div> </div> <div class="sect1"> <h2 id="_what_if_i_want_to_run_more_applications">What if I want to run more applications?</h2> <div class="sectionbody"> <div class="paragraph"> <p>If your applications want more memory, the kernel will just take back a chunk that the disk cache borrowed. Disk cache can always be given back to applications immediately! You are not low on ram!</p> </div> </div> </div> <div class="sect1"> <h2 id="_do_i_need_more_swap">Do I need more swap?</h2> <div class="sectionbody"> <div class="paragraph"> <p>Probably not; disk caching primarily borrows the ram that applications don’t currently want. If applications want more memory, the kernel will take it back from the disk cache. Linux <em>can</em> push application memory into swap if that memory is accessed less often than the filesystem cache, but this will typically improve performance, not hurt it.</p> </div> </div> </div> <div class="sect1"> <h2 id="_how_do_i_stop_linux_from_doing_this">How do I stop Linux from doing this?</h2> <div class="sectionbody"> <div class="paragraph"> <p>You can’t completely disable disk caching, (but you can tune Linux’s "swapiness"). The only reason anyone ever wants to disable disk caching is because they think it takes memory away from their applications, which it doesn’t! Disk cache makes applications load faster and run smoother, but it NEVER EVER takes memory away from them! Therefore, there’s absolutely no reason to disable it!</p> </div> <div class="paragraph"> <p>If, however, you find yourself needing to clear some RAM quickly for some reason, like benchmarking the cold-start of an uncached application, you can force linux to nondestructively <a href="https://linux-mm.org/Drop_Caches">drop caches</a> using <code>echo 3 | sudo tee /proc/sys/vm/drop_caches</code>.</p> </div> </div> </div> <div class="sect1"> <h2 id="_why_do_top_and_free_say_that_so_little_ram_is_free_if_it_is">Why do top and free say that so little ram is free if it is?</h2> <div class="sectionbody"> <div class="paragraph"> <p>This is just a difference in terminology. Both you and Linux agree that memory taken by applications is "used", while memory that isn’t used for anything is "free".</p> </div> <div class="paragraph"> <p>But how do you count memory that is currently used for something, but can still be made available to applications?</p> </div> <div class="paragraph"> <p>You might count that memory as "free" and/or "available". Linux instead counts it as "available":</p> </div> <table class="tableblock frame-all grid-all stretch"> <colgroup> <col style="width: 33.3333%;"> <col style="width: 33.3333%;"> <col style="width: 33.3334%;"> </colgroup> <thead> <tr> <th class="tableblock halign-left valign-top">Memory that is</th> <th class="tableblock halign-left valign-top">You’d call it</th> <th class="tableblock halign-left valign-top">Linux calls it</th> </tr> </thead> <tbody> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">used by applications</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Used</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Used</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">used, but can be made available</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Free (or Available)</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Available</p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">not used for anything</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Free</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock">Free</p></td> </tr> </tbody> </table> <div class="paragraph"> <p>This "something" is (roughly) what top and free calls "buffers" and "cached". Since your and Linux’s terminology differs, you might think you are low on ram when you’re not.</p> </div> </div> </div> <div class="sect1"> <h2 id="_how_do_i_see_how_much_free_ram_i_really_have">How do I see how much free ram I really have?</h2> <div class="sectionbody"> <div class="paragraph"> <p>To see how much ram your applications could use without swapping, run <code>free -m</code> and look at the "available" column:</p> </div> <div class="literalblock"> <div class="content"> <pre> $ free -m total used free shared buff/cache available Mem: 1504 636 13 0 855 792 Swap: 2047 6 2041</pre> </div> </div> <div class="paragraph"> <p><span class="small">(On installations from before 2014, look at "free" column in the "-/+ buffers/cache" row instead.)</span></p> </div> <div class="paragraph"> <p>This is your answer in MiB. If you just naively look at "free", you’ll think your ram is 99% full when it’s really just 42%!</p> </div> <div class="paragraph"> <p>For a more detailed and technical description of what Linux counts as "available", see <a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773">the commit that added the field</a>.</p> </div> </div> </div> <div class="sect1"> <h2 id="_when_should_i_start_to_worry">When should I start to worry?</h2> <div class="sectionbody"> <div class="paragraph"> <p>A <strong>healthy Linux system</strong> with more than enough memory will, after running for a while, show the following expected and harmless behavior:</p> </div> <div class="ulist"> <ul> <li> <p><code>free</code> memory is close to <code>0</code></p> </li> <li> <p><code>available</code> memory (or "free + buffers/cache") has enough room (let’s say, 20%+ of total)</p> </li> <li> <p><code>swap used</code> does not change</p> </li> </ul> </div> <div class="paragraph"> <p><strong>Warning signs</strong> of a genuine low memory situation that you may want to look into:</p> </div> <div class="ulist"> <ul> <li> <p><code>available</code> memory (or "free + buffers/cache") is close to zero</p> </li> <li> <p><code>swap used</code> increases or fluctuates</p> </li> <li> <p><code>dmesg | grep oom-killer</code> shows the OutOfMemory-killer at work</p> </li> </ul> </div> </div> </div>