To see your currently available memory, execute the following command in your terminal:
When reading the output of this command, always read the buffers / cache +- section for a true indication of available memory.
This is because Linux employs disk caching, for example, when an application is launched (cPanel, Apache etc) this is what happens:
- Application is initially stored on non-volatile medium (i.e. disk)
- On first application launch, all application data is pulled from disk into memory
- Application data from memory is pulled into CPU L1 or L2 cache
- CPU fetches instructions from l1 or l2 cache
- Application is executed
When the application is run a second or third time, the CPU will always check to see if it has a copy of the instructions from its l1 or l2 cache.
So, as you can see, the ‘free memory’ on the top line of free -m is not a good indication of available memory, because this is the memory that is not currently utilised by the cache.
1. If all that memory is cached, how do other applications run?
Good question, this cached memory can be evicted at any time for latter applications to run.
2. What is the CPU L1 and L2 cache?
The L1 cache is the fastest CPU cache and it usually comes within the processor chip itself (therefore closer than normal system memory)
The L1 cache typically ranges in size (anywhere from 8KB to 64KB) and uses high-speed SRAM (static RAM) instead of DRAM (dynamic RAM) which is slower and typically used for the main system memory.
The L2 cache comes between L1 and system memory and is larger than the primary cache (level 1) and is typically 64KB to 4MB in size. As the L2 cache is larger and not usually stored within the CPU chip itself, the latency is far greater and the search for the cached instructions takes longer because its bigger in size.