42

The output of the free command that I fired on my Linux host is as below:

free
              total        used        free      shared  buff/cache   available
Mem:      263846320    47746620     3290072     1140808   212809628   214382420
Swap:             0           0           0

I am not able to figure out what this available part is specifying. The free memory is very less shown i.e around 1.24% even though the total memory is way high and used memory is around 18.09% only.

free -h
              total        used        free      shared  buff/cache   available
Mem:           251G         45G        3.1G        1.1G        202G        204G
Swap:            0B          0B          0B

Does it mean I won't be able to start more applications as free memory is very less? The used memory is 18% only. So shouldn't free memory be 82% and not 1.24% as the command is showing above?

I am confused. Can anyone help?

Ravi Sethia
  • 85
  • 2
  • 9
Nishant Lakhara
  • 2,295
  • 4
  • 23
  • 46

1 Answers1

31

Modern operating systems go out of their way to keep as little memory free as possible. Memory that is free is actually harder to use because it has to be transitioned from free to in use. Memory that is already in use, that is, memory that is available but not free, can easily be switched to another use.

All this is normal. Free memory is wasted and does not make your system faster.

If you're thinking "but I want my memory free now so I can use it later", realize that this makes no sense. You can't save memory for later. A system with 4GB that uses 2GB today can't use 6GB tomorrow. You can use your memory both now and later. There is no tradeoff here -- using memory is free. The only alternative to using memory is wasting it. Why would you want your system to waste more memory?

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
  • 33
    Not informational answer, doesn't contain technical information, which is: Available = Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free) – Daniel Garmoshka Apr 27 '18 at 14:57
  • 5
    @DanKey That information is more likely to mislead than to educate because it doesn't take into account memory that the kernel is holding that it can discard to make memory available for new applications. In many realistic situations, that's so far off as to be useless. (Imagine if 80% of used memory is filesystem *metadata* cache, which does happen.) Very dangerous to think you know something you really don't. – David Schwartz Apr 27 '18 at 15:17
  • 3
    so give constructive information like "memory that the kernel is holding that it can discard to make memory available for new applications", instead of emotional "Free memory is wasted" or misleading "You can't save memory for later", because free memory exactly awaits for later use – Daniel Garmoshka Apr 27 '18 at 16:54
  • 4
    @DanKey That's not constructive because it leads to a fragmented and confused understanding. It is much more helpful to keep it simple rather than trying to give someone a complete understanding in a few paragraphs. Also, Used memory awaits later use just as free memory does. *All* memory awaits later use. – David Schwartz Apr 27 '18 at 22:35
  • 1
    Regarding "Estimation of how much memory is available for starting new applications". Lets say an existing process suddenly requires a lot more memory, will memory from the "available" category be allocated to the application, or will the process exhaust the supply of "free" memory then be killed by the kernel? – Bijan Massoumi May 18 '20 at 23:31
  • 1
    @BijanMassoumi Neither. That question is based on a fundamental misunderstanding about how memory works. For example, when you say "an existing process suddenly requires a lot more memory", that is ambiguous about what the process needs. For example, if it request a lot of memory with a call to `malloc`, it makes no difference how much RAM is free since they come from different pools. (It may help to think of RAM like money in the bank and `malloc` like writing a check. Swap space like a line of credit.) – David Schwartz May 19 '20 at 01:48