How to Check Memory Usage in Linux (free, vmstat, htop Explained)

Memory monitoring is a core responsibility in Linux server administration. When applications become slow, processes crash, or servers begin swapping heavily, memory usage is often the underlying cause.

Understanding how Linux manages RAM helps administrators diagnose performance problems, detect memory leaks, and determine when infrastructure upgrades may be required.

In this guide we explain the most practical Linux tools used by system administrators to monitor memory usage on servers:

  • free
  • vmstat
  • htop

These commands are available on most Linux distributions and are widely used when diagnosing server performance issues in production environments.


Why Memory Monitoring Matters on Servers

RAM is one of the most critical resources for applications and databases. If a server runs out of available memory, the operating system may begin using swap space on disk, which is significantly slower than RAM.

When this happens, servers can become extremely slow and unresponsive.

Common symptoms of memory pressure include:

โ€ข applications slowing down

โ€ข database queries taking longer

โ€ข high swap usage

โ€ข processes being killed by the OOM (Out Of Memory) killer

Regular memory monitoring allows administrators to detect abnormal consumption before it affects system stability.


Understanding How Linux Uses Memory

Linux manages memory differently from some other operating systems. It aggressively uses available RAM for caching in order to improve disk performance.

This means that a system showing high memory usage does not necessarily indicate a problem.

Memory in Linux is generally divided into:

โ€ข Used memory โ€“ RAM used by applications

โ€ข Buffers/cache โ€“ RAM used for disk caching

โ€ข Free memory โ€“ unused RAM

Cached memory can be quickly reclaimed by the kernel when applications require more RAM.


Checking Memory Usage with free

The free command provides a quick overview of system memory usage.

Run:

free -h

Example output:

              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.1G        1.3G        256M        4.3G        5.1G
Swap:          2.0G        0.0G        2.0G

Key columns explained:

โ€ข total โ€“ total installed RAM

โ€ข used โ€“ memory currently used by processes

โ€ข free โ€“ completely unused memory

โ€ข buff/cache โ€“ memory used for disk caching

โ€ข available โ€“ estimated memory available for new applications

The available column is often the most useful indicator of whether a system has sufficient memory.


Monitoring Memory Activity with vmstat

The vmstat command provides more detailed information about system resource usage, including memory, CPU activity, and swap operations.

Run:

vmstat 2

This command updates statistics every two seconds.

Example output columns include:

โ€ข swpd โ€“ swap memory used

โ€ข free โ€“ idle memory

โ€ข buff โ€“ buffer memory

โ€ข cache โ€“ page cache

โ€ข si / so โ€“ swap in / swap out activity

If swap activity (si or so) increases significantly, the server may be experiencing memory pressure.


Using htop for Interactive Monitoring

The htop utility provides an interactive system monitoring interface that makes it easier to visualize memory usage.

Install on Debian/Ubuntu:

apt install htop

Install on AlmaLinux/CentOS:

yum install htop

Run:

htop

htop displays:

โ€ข memory usage bars

โ€ข swap usage

โ€ข CPU usage

โ€ข running processes

Administrators often sort processes by memory consumption to identify programs using excessive RAM.


Identifying Memory-Hungry Processes

When memory usage becomes high, administrators typically identify which processes consume the most RAM.

A common command used for this purpose is:

ps aux --sort=-%mem | head

This lists processes sorted by memory usage, allowing administrators to quickly identify heavy consumers.


Common Causes of High Memory Usage

Several factors may cause excessive RAM consumption.

Memory Leaks

Applications with memory leaks gradually consume more RAM over time.

Large Database Queries

Database workloads may temporarily require large memory allocations.

Caching Systems

Web applications often use caching layers that store data in RAM.

Background Services

Certain services may allocate memory continuously as workloads grow.


When Memory Usage Indicates Infrastructure Limits

If a server frequently exhausts available RAM or begins swapping heavily, it may require additional resources.

Possible solutions include:

โ€ข upgrading to a larger VPS plan

โ€ข deploying scalable cloud servers

โ€ข migrating to dedicated servers or streaming dedicated servers infrastructure for memory-intensive workloads

Monitoring memory behavior helps administrators determine when infrastructure upgrades are necessary.

Related Linux Server Guides


Final Thoughts

Memory monitoring is a fundamental skill for anyone managing Linux servers. Tools such as freevmstat, and htopprovide quick insight into RAM consumption and system performance.

By regularly monitoring memory usage and identifying processes consuming excessive RAM, administrators can maintain stable server environments and prevent performance degradation.

Understanding how Linux manages memory is an essential step toward mastering Linux server administration.

Share:

Facebook
Twitter
Pinterest
LinkedIn