1 00:00:00,000 --> 00:00:10,000 In this video we'll try to understand Linux memory usage. 2 00:00:10,000 --> 00:00:12,000 So how does it work? 3 00:00:12,000 --> 00:00:16,000 Well, a significant portion of RAM in general is used for caching. 4 00:00:16,000 --> 00:00:18,000 And that's convenient. 5 00:00:18,000 --> 00:00:21,000 Your Linux server is reading files from disk 6 00:00:21,000 --> 00:00:26,000 and it's keeping them in RAM as long as the RAM is not needed for anything else. 7 00:00:26,000 --> 00:00:30,000 The benefit is that the next time you need access to the same file 8 00:00:30,000 --> 00:00:36,000 it can be fetched from RAM, which is a lot faster than fetching it from disk. 9 00:00:36,000 --> 00:00:39,000 As a very generic guideline, 10 00:00:39,000 --> 00:00:45,000 a healthy system should have at least 20% of RAM available as free or cached memory. 11 00:00:45,000 --> 00:00:50,000 But there are many exceptions that might justify that you do it differently. 12 00:00:51,000 --> 00:00:56,000 To find current memory usage information, you can use the free utility. 13 00:00:56,000 --> 00:01:00,000 And detailed cache usage can be read from PROC MEMINFO. 14 00:01:00,000 --> 00:01:04,000 If ever you want to optimize memory, you can use SWAP. 15 00:01:04,000 --> 00:01:09,000 As an overflow buffer of emulated RAM on disk where inactive anonymous memory can be parked. 16 00:01:09,000 --> 00:01:12,000 And then there is the out-of-memory killer. 17 00:01:12,000 --> 00:01:15,000 That's a nasty process, part of the Linux kernel, 18 00:01:15,000 --> 00:01:20,000 that will become active and terminate processes on a system that is running low on memory. 19 00:01:20,000 --> 00:01:25,000 There's only one thing that you must understand about the out-of-memory killer. 20 00:01:25,000 --> 00:01:30,000 If ever in your logs you see the ohm killer, you need to add more memory. Period. 21 00:01:30,000 --> 00:01:33,000 Let's check this out a bit. 22 00:01:33,000 --> 00:01:35,000 So here we have 3-M. 23 00:01:35,000 --> 00:01:37,000 And what do we see? 24 00:01:37,000 --> 00:01:41,000 Well, we still have 513 MB of free memory. 25 00:01:41,000 --> 00:01:45,000 And here we can also see that we have 2 GB of available memory. 26 00:01:45,000 --> 00:01:52,000 And available memory is where all the inactive cache is considered as available as well. 27 00:01:52,000 --> 00:01:58,000 And if you want more information about that, well, have a look at slash PROC slash MEMINFO. 28 00:01:58,000 --> 00:02:01,000 Because there you see the active parameters. 29 00:02:01,000 --> 00:02:06,000 And the parameter that really matters here is the inactive file. 30 00:02:06,000 --> 00:02:08,000 That's your inactive cache. 31 00:02:08,000 --> 00:02:10,000 And at the moment more memory is needed. 32 00:02:10,000 --> 00:02:13,000 The inactive cache can be dropped immediately. 33 00:02:13,000 --> 00:02:17,000 Related to that, there's also inactive anonymous memory. 34 00:02:17,000 --> 00:02:19,000 That's your inactive application memory. 35 00:02:19,000 --> 00:02:23,000 And that memory is candidate to being moved to swap. 36 00:02:23,000 --> 00:02:25,000 You learned about that earlier.