Linux: Show Free Memory

By Xah Lee. Date: . Last updated: .
linux memory free
linux free -h, show free memory.

free shows how much memory is free.

The same info is shown in top command. [see Linux: Monitor Processes: top]

The command htop shows a visual representation. [see Linux: Monitor Processes, htop]

linux htop 2017 01 02
Linux htop command.

Understanding Memory

Cache is disk data in RAM. Linux uses RAM as cache for file data (from hard-disk). (Because RAM's IO speed is a thousand times faster than hard disk, so Operating System will load disk data to RAM as cache)

Swap is the disk space used for virtual memory purposes. Linux uses non-volatile storage device (e.g. hard-disk, flash-memory) as virtual memory. The virtual memory on hard-disk is called swap space. Virtual memory means the perm storage is used as temp space for RAM. So, when your RAM is full, the Operating System can off-load parts of it currently not used data to disk, therefore free up memory for application that needs it.

Here's manual from man free:

DESCRIPTION

free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/mem‐ info. The displayed columns are:

total Total installed memory (MemTotal and SwapTotal in /proc/meminfo)

used Used memory (calculated as total - free - buffers - cache)

free Unused memory (MemFree and SwapFree in /proc/meminfo)

shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, available on kernels 2.6.32, dis‐ played as zero if not available)

buffers Memory used by kernel buffers (Buffers in /proc/meminfo)

cache Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo)

buff/cache Sum of buffers and cache

available Estimation of how much memory is available for starting new applications, without swap‐ ping. 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 ker‐ nels 2.6.27+, otherwise the same as free)