used does not mean what you think it means
Today I wanted to see how close a Linux machine was to being out-of-memory.
So I ran
free -m, like this
$ free -m total used free shared buffers cached Mem: 3764 3004 759 0 362 1546 -/+ buffers/cache: 1096 2668 Swap: 0 0 0
Then I did
used/total, and got 80%.
Panic! 80% of the memory is used, and only 20% remains.
I’ve made this error before.
Thousands before me have made the same error.
used/total, is not representative of the machine’s memory use.
The reason is that
used does not mean what you think it means.
You think it means “all memory allocated by system processes”.
used includes this,
but it also includes other categories of memory:
“buffers” and “cache”.
What are these?
Unused memory is wasted memory,
so the Linux kernel attempts to use this memory to improve performance.
Specifically, Linux uses it to cache data on disk.
Disk data is cached in the “page cache”.
buffers+cache is the size of the page cache.
The distinction between “buffers” and “cache” isn’t very important.
If Linux runs out of “free” memory,
the page cache will be sacrificed
to make room for application memory.
buffers+cache really count as more memory available to your applications.
(But bear in mind that performance may degrade from the lack of page cache.)
For a more helpful assessment of your system’s memory, look at the line below:
$ free -m total used free shared buffers cached Mem: 3764 3004 759 0 362 1546 + -/+ buffers/cache: 1096 2668 Swap: 0 0 0
Accounting for buffers+cache,
your memory usage is
1096/3764 = 29%.
Quite a difference!
More by Jim
- Your syntax highlighter is wrong
- Granddad died today
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- I hate telephones
- The sorry state of OpenSSL usability
- The dots do matter: how to scam a Gmail user
- My parents are Flat-Earthers
- How Hacker News stays interesting
- Project C-43: the lost origins of asymmetric crypto
- The hacker hype cycle
- The inception bar: a new phishing method
- Time is running out to catch COVID-19
- A probabilistic pub quiz for nerds
- Smear phishing: a new Android vulnerability