Introduction / Why This Matters
Understanding how your Linux system uses RAM (random-access memory) is a critically important skill for diagnosing slowdowns, planning hardware upgrades, or optimizing a server. Unlike Windows, Linux actively uses free RAM for disk caching, which can be misleading. This guide will show you how to correctly interpret memory data using standard utilities to distinguish normal operation from actual RAM shortage.
After completing this, you'll confidently read the output of free, top, and htop, understand what "free" memory means and where cache fits in, and quickly identify memory-hungry processes.
Requirements / Preparation
- Access to a terminal (Ctrl+Alt+T or an SSH connection).
- Basic familiarity with the command line.
- Permissions to run utilities (all commands are available to a regular user, except package installation, which requires
sudo). - To use
htop, installation may be required (instructions are in step 3).
Step-by-Step Instructions
Step 1: Use the free Command for a General Summary
The free command is the fastest way to get an overview of RAM and swap usage.
free -h
Example output:
total used free shared buff/cache available
Mem: 7.7G 1.2G 4.1G 156M 2.4G 6.0G
Swap: 2.0G 0B 2.0G
How to read it:
- total — the total amount of installed RAM.
- used — memory occupied by processes (but not all of it, because in Linux
used=total-free-buff/cache). - free — completely unused RAM (this number is usually small in Linux, and that's normal).
- buff/cache — memory used by the kernel for disk cache and buffers. It can be automatically freed for applications.
- available — the most important metric. An estimate of memory available for starting new applications without using swap. Use this as your primary guide.
💡 Tip: If
availableapproaches zero and the system actively uses swap, that's a sign of insufficient physical RAM.
Step 2: Monitor Processes in Real Time with top
top shows a dynamic list of processes, sorted by CPU usage by default. However, you can configure it to analyze memory.
top
Inside top:
- Press
F6(or>to sort by the next field). - Select the field
%MEM(percentage of total RAM) orRES(physical memory in KiB) and press Enter. - Now processes are sorted by memory consumption. The most "gluttonous" will be at the top.
- To exit, press
q.
Key columns in top:
- VIRT — virtual memory (includes code, data, shared libraries, mapped files, and swap).
- RES — resident memory (physical RAM occupied by the process, excluding swap).
- %MEM — percentage of
RESrelative to total RAM.
Step 3: Install and Use htop for a User-Friendly Interface
htop is an improved, interactive, and colorized alternative to top. It's more visually intuitive.
# Installation (if not present)
# For Debian/Ubuntu:
sudo apt update && sudo apt install htop
# For CentOS/RHEL/Fedora:
sudo dnf install htop # or sudo yum install htop
# Launch
htop
In htop:
- At the top of the screen — colored bars with labels: Mem (RAM) and Swp (Swap). The green part is used, blue is buffers/cache.
- Default sorting is by CPU. Press
F6, select%MEMorRESto sort by memory. F5— toggle between tree view (shows child processes) and list view.F10— exit.
htop also displays convenient real-time graphs for CPU and RAM usage.
Step 4: Use vmstat for Statistics
vmstat (virtual memory statistics) provides a summary of memory, processes, swap, and I/O.
vmstat -s
Example output:
8192000 total memory
4194304 used memory
1064960 active memory
2109440 inactive memory
3997696 free memory
524288 buffer memory
2109440 swap cache
0 total swap
0 used swap
0 free swap
123456 non-nice user cpu ticks
...
This format compactly shows absolute values (in kilobytes). Useful for quick assessment in scripts.
Step 5: Check Detailed Information in /proc/meminfo
For the most detailed information (which the utilities above use), check the kernel's virtual file:
cat /proc/meminfo
Key fields:
MemTotal— total RAM.MemFree— completely free RAM.MemAvailable— estimate of available RAM (similar tofree).Buffers— memory for block device buffers.Cached— memory for page cache (file cache).SwapTotal/SwapFree— swap.
This file is the source of truth for all the commands listed above.
Verification
You have successfully checked RAM usage if:
- The
free -hcommand displayed a table with understandable values, and you can explain the difference betweenfreeandavailable. - In
htoportop, you sorted processes by%MEMorRESand saw a list with memory consumption. - You understand that a high
buff/cachevalue is good, while a lowavailablevalue is bad.
Success criterion: You can answer the question "How much memory is actually available for new applications?" by looking at the available field in free or the indicator in htop.
Potential Issues
htop: command not found— the utility is not installed. Install it via your distribution's package manager (see Step 3).freeshows a very lowavailablevalue, but the system is running fast — you might have just launched a heavy application, and the cache hasn't had time to free up yet. Wait a few seconds and check again. Ifavailableis consistently low and swap is active — consider upgrading your RAM.- No permissions to install packages — installing
htoprequiressudoprivileges. Contact your administrator or use onlyfree,top,vmstat, which are almost always available. /proc/meminfois unavailable — this can only happen in very stripped-down container or embedded environments. In a normal system, this file always exists. In a container, usefreeorcat /sys/fs/cgroup/memory.current(depends on the cgroup version).