LinuxCommandLibrary

free

Display amount of free and used memory

TLDR

Display system memory

$ free
copy

Display memory in Bytes/KB/MB/GB
$ free -[b|k|m|g]
copy

Display memory in human-readable units
$ free [[-h|--human]]
copy

Refresh the output every 2 seconds
$ free [[-s|--seconds]] 2
copy

SYNOPSIS

free [options]

PARAMETERS

-b, --bytes
    Display the amount of memory in bytes.

-k, --kilo
    Display the amount of memory in kilobytes (this is the default unit).

-m, --mega
    Display the amount of memory in megabytes.

-g, --giga
    Display the amount of memory in gigabytes.

-h, --human
    Show all output fields automatically scaled to the shortest three-digit unit and display unit suffixes (e.g., M, G, T). This is highly recommended for readability.

-t, --total
    Display a line showing the total of physical and swap memory combined.

-s <delay>, --seconds <delay>
    Repeat the display every delay seconds. This allows for continuous monitoring.

-c <count>, --count <count>
    Update the display count times, then exit. Often used in conjunction with -s.

-w, --wide
    Wide output format. This can prevent truncation of numbers.

-o, --old
    Don't display the "buffers/cache" line. This option makes the output compatible with older versions of free.

-v, --version
    Display version information and exit.

DESCRIPTION

The free command in Linux is a utility used to display the total amount of free and used physical memory and swap space in the system. It provides a quick snapshot of the system's current memory status, which is crucial for monitoring performance and diagnosing memory-related issues. The command retrieves its information from the /proc/meminfo pseudo-filesystem, which is maintained by the Linux kernel.

Beyond just physical RAM and swap, free also reports on memory categorized as shared, buffers, and cache. Modern versions of free, especially when used with the -h (human-readable) option, include an "available" memory column. This column is particularly important as it attempts to show how much memory is available for new applications without needing to swap, taking into account reclaimable memory from caches and buffers. Understanding the output of free helps administrators and users gauge memory pressure, identify potential bottlenecks, and ensure optimal system operation.

CAVEATS

One common misconception when interpreting free output, especially with older versions or without the available column, is that the free column alone represents all usable memory. Linux actively uses available RAM for disk caching (buffers and cache) to improve performance. This memory is not truly "used" in the sense that it's unavailable for applications; it can be quickly reclaimed if an application needs it.

The available column (introduced in Linux kernel 3.14 and visible with free -h on modern systems) provides a more accurate representation of how much memory is truly available for new application processes without swapping. Users should rely on the available column for a realistic view of usable memory.

UNDERSTANDING <B>FREE</B> OUTPUT COLUMNS

The typical output of free includes several columns, each providing insight into memory usage:

total: The total amount of installed physical memory (RAM) or swap space.
used: The total amount of memory currently in use by the system, including applications, kernel, and buffers/cache.
free: The amount of memory that is completely unused and immediately available.
shared: Memory used by tmpfs (shared memory and RAM disks) and shared libraries.
buffers: Memory used by kernel buffers, primarily for disk block I/O operations.
cache: Memory used as page cache by the kernel for filesystem data (e.g., recently accessed files).
buff/cache: (Often combined in newer versions) The sum of memory used for buffers and cache. This memory is generally reclaimable.
available: (Modern free versions, especially with -h) An estimate of how much memory is truly available for starting new applications without swapping. This value considers both the free memory and memory that can be reclaimed from buffers and cache without significant performance penalties.

HISTORY

The free command is a standard utility provided by the procps (or procps-ng for newer systems) package, which is a collection of utilities that provide system information from the /proc filesystem. Its origins trace back to the early days of Linux, relying on the kernel's /proc/meminfo interface for memory statistics.

A significant development in the command's evolution was the addition of the "available" memory field. Before its introduction, users often misinterpreted "free" memory as only the explicitly unused RAM, leading to confusion about why systems with large amounts of cached memory appeared to be "running out of memory." The "available" field, which accounts for reclaimable cache/buffer memory, was a crucial improvement in providing a more accurate and intuitive understanding of system memory availability, aligning free's output with modern Linux memory management practices.

SEE ALSO

vmstat(8), top(1), htop(1), proc(5)

Copied to clipboard