How to Check Memory Usage in Linux
How to Check Memory Usage in Linux

Checking memory usage in Linux is often one of the first steps when a system becomes slow, applications start consuming more resources than expected, or you simply need to see how much RAM is still available. Linux provides several command-line tools for checking total memory, available RAM, swap activity, and memory usage by individual processes.

However, memory statistics can be misleading if you read only the used or free values. Linux actively uses otherwise idle RAM for caching, so a system with very little free memory is not necessarily running out of RAM.

This guide shows how to check memory usage in Linux, interpret the numbers correctly, identify processes consuming the most memory, and recognize signs of actual memory pressure.



Check Memory Usage with the free Command


The free command is one of the quickest ways to check memory usage in Linux. It displays the total amount of physical RAM and swap space, how much memory is currently in use, and how much remains available to applications.

Run:

free -h

The -h option displays memory values in a human-readable format, using units such as MiB and GiB instead of raw byte counts.

A typical output looks like this:

	total	used	free	shared	buff/cache	available
Mem:	7.7Gi	4.9Gi	320Mi	210Mi	2.5Gi		2.2Gi
Swap:	2.0Gi	256Mi	1.7Gi


Understanding the free Command Output


The Mem row summarizes physical memory, while the Swap row shows configured swap space and how much of it is currently being used.

The main columns are:

   total — the total amount of usable physical memory.
   used — memory that is currently unavailable for starting new applications,
   calculated as total memory minus available memory.
   free — completely unused physical memory.
   shared — memory primarily used by tmpfs and shared memory.
   buff/cache — memory used for buffers, page cache, and reclaimable kernel data.
   available — an estimate of how much memory can be made available to new applications without swapping.

When assessing how much memory the system can still provide to applications, pay particular attention to available. The difference between free and available is explained in the next section.


Useful free Command Options


For most checks, free -h is sufficient. If you need to watch memory usage change over time, add an update interval:

free -h -s 2

This refreshes the output every two seconds, making it useful for watching memory while starting an application, running a workload, or reproducing a performance issue.

Press Ctrl+C to stop the continuous output.



Free vs. Available Memory in Linux: What the Numbers Really Mean


Suppose free -h shows that a server with 8 GiB of RAM has only about 300 MiB of free memory:

total:		8 GiB
used:		5.8 GiB
free:		300 MiB
available:	2.0 GiB

At first glance, 300 MiB of free RAM may look like the server is close to running out of memory. But the free value represents memory that is completely unused. It does not include memory that Linux is currently using for caches and other reclaimable purposes.

Linux deliberately uses otherwise idle RAM to cache frequently accessed data. This can improve performance because retrieving data from memory is faster than reading it again from storage. When applications require more memory, the kernel can reclaim eligible cached and reclaimable memory as needed.

This is why the available value is usually more useful when assessing how much memory the system can still provide to applications. It estimates how much memory can be made available without swapping, taking reclaimable memory into account rather than treating all cached memory as immediately free.

In the example above, the server has only 300 MiB completely unused, but approximately 2 GiB is still available for applications. The low free value alone therefore does not indicate a RAM shortage.

The opposite is also important: a high used value is not automatically a problem. To determine whether the system is actually under memory pressure, you need to consider available memory together with swap activity, process memory consumption, and other indicators rather than relying on a single number.



Check Memory Usage in Real Time with top


While free provides a quick snapshot of system memory, the top command lets you monitor memory usage and running processes in real time. It is available by default on most Linux distributions.

Run:

top

Near the top of the output, top displays a summary of physical memory and swap usage. Below it is a continuously updated list of running processes.

For memory troubleshooting, two columns are particularly useful:

RES — the amount of a process's memory currently resident in physical RAM. It can include shared memory, so it should not be treated as the process's exact exclusive RAM consumption.
%MEM — the process's resident memory as a percentage of the system's total physical memory.
This makes top useful when memory consumption changes over time or when you want to see whether a particular process starts consuming more RAM under load.


Sort Processes by Memory Usage in top


By default, top may not place the largest memory consumers at the top of the process list. While top is running, press:

Shift+M

The process list will be sorted by memory usage, making it easier to identify processes with high resident memory consumption.

Use q to exit top.



Use htop for an Interactive Memory View


htop provides an interactive view of system resources and running processes. It presents memory and swap usage visually and makes it easier to browse, sort, and inspect processes than with the standard top interface.

Start it with:

htop

The memory and swap meters at the top provide a quick overview of current resource usage. In the process list, you can sort by memory consumption to identify processes using the most RAM.

Unlike top, htop is not installed by default on every Linux distribution. On Ubuntu and Debian, you can install it with:

sudo apt update
sudo apt install htop

On RHEL-based distributions, use the appropriate package manager for your distribution. If you are running CentOS, see our guide on how to install htop on CentOS.



Find Which Processes Are Using the Most Memory


If overall memory usage is high, the next step is to identify which processes are consuming the most RAM. You can do this without opening an interactive tool by using ps:

ps aux --sort=-%mem | head

The --sort=-%mem option sorts processes from highest to lowest memory usage, while head limits the output to the first ten lines.

A typical result may look like this:

USER       PID  %CPU  %MEM     VSZ    RSS TTY      STAT START   TIME COMMAND
mysql     1842   2.1  12.8 1824500 1043200 ?      Ssl  10:14   4:31 mysqld
www-data  2716   0.7   5.4  642800  438200 ?      S    10:26   1:12 php-fpm

For a quick memory check, the most useful fields are:

PID — the process ID.
%MEM — the percentage of total physical memory represented by the process's resident memory.
RSS — the resident set size, or the amount of the process's memory currently held in physical RAM.
COMMAND — the command or process name.

RSS is useful for identifying likely heavy memory consumers, but it should not be treated as the exact amount of RAM exclusively owned by a process. Memory pages can be shared between processes, so simply adding their RSS values may overestimate actual physical memory usage.

To inspect a specific process by PID, use:

ps -p 1842 -o pid,comm,%mem,rss

Replace 1842 with the PID you want to inspect.



Check Detailed Memory Information with /proc/meminfo


For a more detailed view of system memory, Linux exposes memory statistics through /proc/meminfo. Many memory-monitoring tools, including free, use information from this virtual file.

To view it, run:

cat /proc/meminfo

The output contains considerably more detail than free, with most memory values displayed in kB. For a general memory check, the most relevant fields include:

MemTotal — total usable physical RAM.
MemFree — physical memory that is completely unused.
MemAvailable — memory available for starting new applications without swapping.
Buffers — memory used for filesystem block-related buffers.
Cached — memory used for the page cache as well as tmpfs and shared memory.
SwapTotal — total configured swap space
SwapFree — unused swap space.

If you only need these values, filter the output instead of reading the entire file:

grep -E 'MemTotal|MemFree|MemAvailable|Buffers|Cached|SwapTotal|SwapFree' /proc/meminfo

/proc/meminfo is particularly useful when you need more detail than the summarized output of free or want to inspect specific memory counters directly.



Check Swap Activity and Memory Pressure with vmstat


Seeing used swap space does not necessarily mean that a Linux system is currently short on memory. Pages may remain in swap even after memory pressure has decreased. To see whether the system is actively moving memory between RAM and swap, use vmstat.

Run:

vmstat -y 2

The 2 tells vmstat to update the statistics every two seconds. The -y option skips the initial report, which otherwise contains values based on statistics collected since the system was started.

For memory and swap activity, focus on these columns:

   free — currently unused memory.
   buff — memory used as buffers.
   cache — memory used as cache.
   si — memory swapped in from disk per second.
   so — memory swapped out to disk per second.

Occasional swap activity does not automatically indicate a problem. However, sustained si or so activity together with low available memory and degraded performance can be a sign that the system is under memory pressure.

This distinction is important: swap space being occupied is not the same as active swapping. A system can have data in swap while still having sufficient available RAM and showing little or no current swap activity.

If you need to reset swap after addressing the underlying memory issue, see how to clear swap memory in Linux.



How to Identify Memory Pressure in Linux


Memory pressure is better identified by combining several indicators rather than relying on a single memory value.

Signs that the system may actually be struggling for memory include:

   available memory remaining consistently low rather than dropping only briefly;
   sustained swap-in or swap-out activity;
   high process memory consumption accompanied by low available memory;
   noticeable slowdowns while memory availability is low;
   processes being terminated by the Out-of-Memory (OOM) Killer.

For example, high used memory with sufficient available memory and little swap activity can be perfectly normal.

If monitoring shows that your workload consistently requires more memory than the current server can provide, a Linux VPS plan with more RAM may be a suitable option. However, first determine whether the shortage is caused by insufficient resources or abnormal memory consumption by an application. However, first determine whether the shortage is caused by insufficient resources or abnormal memory consumption by an application.


Check Memory Pressure with PSI


On systems with PSI support enabled, Linux exposes Pressure Stall Information (PSI), which measures how much time tasks spend stalled because resources such as memory are unavailable.

To view memory pressure data, run:

cat /proc/pressure/memory

If /proc/pressure/memory does not exist, PSI may not be available or enabled on that kernel.

A typical output has two lines:

some avg10=0.00 avg60=0.00 avg300=0.00 total=123456
full avg10=0.00 avg60=0.00 avg300=0.00 total=7890

The some line indicates periods when at least some tasks were stalled because of memory pressure. The full line represents more severe periods when all non-idle tasks were simultaneously stalled on memory.

The avg10, avg60, and avg300 values show the percentage of time affected over the previous 10, 60, and 300 seconds. Higher or sustained PSI values indicate that tasks are spending more time stalled because of memory contention. Their significance depends on the workload, so interpret them together with available memory, swap activity, and observed performance problems


Check for OOM Killer Events


Severe memory pressure can eventually cause the kernel's OOM Killer to terminate a process so the system can recover memory.

To check the kernel log for related events, run:

dmesg | grep -i -E 'out of memory|oom|killed process'

If access to kernel messages through dmesg is restricted, systems using systemd can also be checked with:

journalctl -k | grep -i -E 'out of memory|oom|killed process'

Finding an OOM event is strong evidence that the affected workload encountered a severe memory shortage or memory-limit condition at that time. However, the absence of OOM events does not mean that memory pressure is absent; performance can degrade well before the kernel needs to terminate a process.

If your checks confirm persistent memory pressure, the next step is to investigate and resolve its cause. See our guide to Linux VPS running out of memory for troubleshooting swap usage, OOM Killer events, and persistent RAM shortages.



A Practical Linux Memory Check Workflow


When checking memory usage on a Linux system, use the tools above in a logical order rather than relying on a single metric:

1. Run free -h and check the available value instead of judging memory usage by free or used alone.
2. If available memory is low, use top, htop, or ps to identify the processes consuming the most RAM.
3. Use vmstat -y 2 to determine whether the system is actively swapping.
4. Check /proc/pressure/memory if you need to confirm whether memory pressure is causing tasks to stall.
5. If applications have been terminated unexpectedly, check the kernel logs for OOM Killer events.

Together, these checks help distinguish normal Linux memory utilization from an actual memory shortage before you begin troubleshooting the underlying cause.



Conclusion


Understanding Linux memory usage requires more than checking a single number. The useful distinction is between memory that Linux is actively putting to work and resource pressure that begins to affect applications or system performance.

Once memory statistics are interpreted in context, they become a practical diagnostic tool rather than just a collection of RAM values.

FAQ

You ask, and we answer! Here are the most frequently asked questions!