-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.html
122 lines (103 loc) · 7.06 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Help! Linux ate my RAM!</title>
<link rel="stylesheet" href="github-markdown.css">
<link rel="stylesheet" href="normalize.min.css">
<link rel="stylesheet" href="common.css">
<style>
#blinkyblink {
animation: blinkyblink 0.8s 11;
}
@keyframes blinkyblink {
0% { border: 3px solid #D0D0D0; }
49.9% { border: 3px solid #D0D0D0; }
50% { border: 3px solid #000000; }
100% { border: 3px solid #000000; }
}
</style>
</head>
<body>
<article class="markdown-body" style="font-size: 1.1em">
<center>
<img src="atemyram.png" alt="Linux ate my RAM!">
<div id="blinkyblink" style="border: 3px solid; display: inline-block; margin: 0 auto; margin-bottom: 2em; margin-top: 1em; padding: 2em">
<h1 class="border-0" style="color: #F00000; font-size: 3em; margin: 0; padding: 0;">
Don't Panic!<br>Your ram is fine!
</h1>
</div>
</center>
<h2>What's going on?</h2>
<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>
<h2>Why is it doing this?</h2>
<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>
<h2>What if I want to run more applications?</h2>
<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>
<h2>Do I need more swap?</h2>
<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>
<h2>How do I stop Linux from doing this?</h2>
<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>
<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>
<h2>Why do top and free say that so little ram is free if it is?</h2>
<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>
<p>But how do you count memory that is currently used for something, but can still be made available to applications?</p>
<p>You might count that memory as "free" and/or "available". Linux instead counts it as "available":</p>
<table>
<thead>
<tr>
<th>Memory that is</th>
<th>You'd call it</th>
<th>Linux calls it</th>
</tr>
</thead>
<tbody>
<tr>
<td bgcolor="#FF8080">used by applications</td>
<td bgcolor="#FF8080">Used</td>
<td bgcolor="#FF8080">Used</td>
</tr>
<tr>
<td bgcolor="#FFFF80">used, but can be made available</td>
<td bgcolor="#80FF80">Free (or Available)</td>
<td bgcolor="#80FF80">Available</td>
</tr>
<tr>
<td bgcolor="#80FF80">not used for anything</td>
<td bgcolor="#80FF80">Free</td>
<td bgcolor="#80FF80">Free</td>
</tr>
</tbody>
</table>
<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>
<h2>How do I see how much free ram I really have?</h2>
<p>To see how much ram your applications could use without swapping, run <code>free -m</code> and look at the "available" column:</p>
<pre>
$ free -m
total used free shared buff/cache available
Mem: 1504 636 13 0 855 <span style="border: 1px solid"><strong>792</strong></span>
Swap: 2047 6 2041
</pre>
<p><small>(On installations from before 2014, look at "free" column in the "-/+ buffers/cache" row instead.)</small></p>
<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>
<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>
<h2>When should I start to worry?</h2>
<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>
<ul>
<li><code>free</code> memory is close to <code>0</code> </li>
<li><code>available</code> memory (or "free + buffers/cache") has enough room (let's say, 20%+ of total)</li>
<li><code>swap used</code> does not change</li>
</ul>
<p><strong>Warning signs</strong> of a genuine low memory situation that you may want to look into:</p>
<ul>
<li><code>available</code> memory (or "free + buffers/cache") is close to zero</li>
<li><code>swap used</code> increases or fluctuates</li>
<li><code>dmesg | grep oom-killer</code> shows the OutOfMemory-killer at work</li>
</ul>
<h2>How can I verify these things?</h2>
<p>See <a href="play.html">this page</a> for more details and how you can experiment with disk cache to show the effects described here. Few things make you appreciate disk caching more than measuring an order-of-magnitude speedup on your own hardware!</p>
<small><strong class="text-gray-light">LinuxAteMyRam.com was presented by <a href="http://www.vidarholen.net">VidarHolen.net</a>. This site is available <a href="https://github.com/koalaman/linuxatemyram.com">on GitHub</a> for comments and PRs.</strong></small>
</article>
</body>
</html>