Linux - Memory Usage (free Command)

Monitoring memory usage is an essential part of managing any Linux system. The free command provides a quick snapshot of how much RAM and swap memory is being used, available, cached, or free. It helps you understand system performance, detect memory leaks, and troubleshoot slow applications.


1. What Is the free Command?

The free command shows the current usage of your system's RAM and swap memory. It gives an overview of:

  • Total memory

  • Used memory

  • Free memory

  • Shared memory

  • Buffers and cache

  • Swap usage

Run it using:

free -h

The -h option shows the values in human-readable form (MB/GB).


2. Understanding free Command Output

Example output:

              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.4G        1.2G        200M        4.1G        5.0G
Swap:          2.0G        500M        1.5G

Now let’s break it down:


a) total

Total physical RAM installed in the system.

b) used

Memory currently used by applications + OS + cache.

c) free

Memory not used at all — completely idle.

d) shared

Memory shared between processes (mostly tmpfs).

e) buff/cache

This includes:

  • Buffers: For temporary data storage by the kernel.

  • Cache: File system cache used to speed up reading files.

Linux uses free RAM as cache to make the system faster.
This memory is not really “used”, because the system can free it whenever needed.

f) available

The most important column.

It shows memory that can be used without swapping, including free RAM + reclaimable cache.


3. Why Linux Shows Low Free Memory?

Many new users panic when they see low "free" memory, but this is normal.

Linux uses unused RAM for caching to boost performance.

Example:

free: 100MB
buff/cache: 4GB

The 4GB cache will be freed automatically if an application needs it.

So, “available” is the best number to check, not “free”.


4. Swap Memory in free Command

Swap is virtual memory on disk.
If RAM becomes full, Linux uses swap to avoid crashes.

Swap output example:

Swap: 2.0G  500M used  1.5G free

High swap usage may indicate:

  • RAM shortage

  • Memory-heavy applications

  • Performance slowdown


5. Useful Variations of free Command

Human-readable format

free -h

Show in MB

free -m

Show in GB

free -g

continuous monitoring every 2 seconds

watch -n 2 free -h

6. Why free Command Matters?

You can use it to:

  • Monitor RAM usage

  • Detect memory leaks

  • Check if system is overloaded

  • Understand performance bottlenecks

  • Diagnose swap-related slowdowns

It’s a key tool for system administrators, DevOps engineers, and Linux users.


In Summary

The free command is a simple but powerful tool to analyze memory usage. It helps you understand:

  • How much RAM is used, free, or cached

  • How much swap is active

  • How much memory is truly available for applications

 

Once you know how to read the output correctly—especially the available column—you gain clear insight into your system’s memory health.