How to Read Memory in Linux (buffers / cache)

To see your currently available memory, execute the following command in your terminal:

free -m

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:

  1. Application is initially stored on non-volatile medium (i.e. disk)
  2. On first application launch, all application data is pulled from disk into memory
  3. Application data from memory is pulled into CPU L1 or L2 cache
  4. CPU fetches instructions from l1 or l2 cache
  5. 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.

FAQ

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.

Advertisements

Author: drewsymo

Developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s