0

This is the output of free -h command on my Ubuntu 18.04 laptop:

$ free -hg
              total        used        free      shared  buff/cache   available
Mem:            11G        4,2G        3,4G        801M        4,0G        6,3G
Swap:           11G          0B         11G

From what I understand after a short research using mostly stackexchange sites (e.g. this elaboration), the main difference between free and available memory is that free is actually free and available can become free if the need arises.

What is the process via which the available memory is allocated to a task that creates the relevant need?

Does flushing dirty pages and freeing up cache (to allocate the memory freed up to a process that requires it) constitute part of such a process?

In such a case I assume available should always be > cache.

Stephen Kitt
  • 434,908
pkaramol
  • 2,799
  • 6
  • 47
  • 79

1 Answers1

4

It’s a bit more complicated than that. Available memory is memory which is immediately reclaimable, i.e. can be re-purposed without losing data, minus certain thresholds below which the system swaps. This doesn’t include dirty pages, since they need to be written out, and that can take a lot of time.

See the above link for details. In particular, the existence of thresholds, and the fact that “buff/cache” includes dirty pages, means that there is no guarantee that the available memory is larger than the amount given under “buff/cache”.

Stephen Kitt
  • 434,908
  • However can't the mmanagement module free memory from inactive(file), thus by flushing cache to hard disk? "inactive :The amount of inactive memory (in KB), or memory that has not been used for a while and is eligible to be swapped to disk." (from: https://bit.ly/2OTM4VW) – pkaramol Nov 17 '18 at 20:17
  • 1
    “Inactive(file)” represents the inactive part of the page cache, i.e. file-backed memory which hasn’t been used recently. It isn’t dirty, so it can be discarded at any time (the data is stored elsewhere already). – Stephen Kitt Nov 17 '18 at 22:17