In this video we'll try to understand Linux memory usage.
So how does it work?
Well, a significant portion of RAM in general is used for caching.
And that's convenient.
Your Linux server is reading files from disk
and it's keeping them in RAM as long as the RAM is not needed for anything else.
The benefit is that the next time you need access to the same file
it can be fetched from RAM, which is a lot faster than fetching it from disk.
As a very generic guideline,
a healthy system should have at least 20% of RAM available as free or cached memory.
But there are many exceptions that might justify that you do it differently.
To find current memory usage information, you can use the free utility.
And detailed cache usage can be read from PROC MEMINFO.
If ever you want to optimize memory, you can use SWAP.
As an overflow buffer of emulated RAM on disk where inactive anonymous memory can be parked.
And then there is the out-of-memory killer.
That's a nasty process, part of the Linux kernel,
that will become active and terminate processes on a system that is running low on memory.
There's only one thing that you must understand about the out-of-memory killer.
If ever in your logs you see the ohm killer, you need to add more memory. Period.
Let's check this out a bit.
So here we have 3-M.
And what do we see?
Well, we still have 513 MB of free memory.
And here we can also see that we have 2 GB of available memory.
And available memory is where all the inactive cache is considered as available as well.
And if you want more information about that, well, have a look at slash PROC slash MEMINFO.
Because there you see the active parameters.
And the parameter that really matters here is the inactive file.
That's your inactive cache.
And at the moment more memory is needed.
The inactive cache can be dropped immediately.
Related to that, there's also inactive anonymous memory.
That's your inactive application memory.
And that memory is candidate to being moved to swap.
You learned about that earlier.