WittCode💻

Linux - Memory Monitoring with free Command

By

Learn how to analyze and monitor a Linux computer's memory using the free command. We will also go over what swap memory is and available vs free memory.

Table of Contents 📖

The free Command

The Linux free command is used to display memory statistics of a system.

free --mega
              total        used        free      shared  buff/cache   available
Mem:           1048         360           8          11         679         676
Swap:           262          13         249

INFO: Specifying the --mega flag outputs the values in megabytes (MB). The default unit is kilobytes (KB).

This command outputs two sections: Mem and Swap.

The Mem Section

First lets focus on the Mem section. This is the measurement of the total physical RAM on the computer. The Mem statistic is often used to detect memory related issues on the system. Here is a run down of the fields:

  • total - Total physical memory on the system.
  • used - Memory being used by running processes. Equal to total - free - buffers/cache.
  • free - Memory that is free to be used by other processes.
  • shared - Memory used by the tmpfs file system. This file system keeps all its files in memory to improve system performance.
  • buff/cache - Memory that the operating system uses to store recently used data, improving performance of the system.
  • available - Estimate of how much memory is still open for use.

SUCCESS: Free and available memory sound similar. However, free is the amount of physical memory not being used. Available is the amount of physical memory not being used along with memory that is currently in use but can be reclaimed when needed or allocated to a new/existing process.

Swap Memory

The Swap metric shows statistics on swap memory. Swap is a mechanism that allows computers to use extra memory by creating a file/partition on a storage volume. This creates a backup option when the sytem's physical memory is full. In this case, data is transferred from RAM to the swap space so the computer can keep running smoothly.

Human Readable Format

A cool flag of the free command is the -h flag which outputs everything in a human readable format.

free -h
              total        used        free      shared  buff/cache   available
Mem:           1.0G        351M        9.1M         11M        663M        661M
Swap:          256M         12M        243M