Master Linux Memory Monitoring: 6 Essential Commands and How to Use Them
This guide explains why monitoring system memory is crucial for Linux administrators and walks through six practical commands—free, vmstat, /proc/meminfo, top, htop, and per‑process status—detailing their syntax, useful options, example outputs, and how to interpret key metrics for troubleshooting.
0. Introduction
System memory is a critical hardware component; regularly checking memory usage helps detect abnormal consumption and keep services stable. Linux administrators need reliable ways to inspect memory status.
1. free command
Syntax
free [options]Common options
-b : display in bytes
-k : display in kilobytes
-m : display in megabytes
-g : display in gigabytes
-o : hide the buffers/cache column
-s <interval> : continuously monitor every <interval> seconds
-t : show total column
-V : show version
Examples
free -t # show totals
free -h -s 10 # update every 10 seconds with human‑readable units
free -h -c 10 # output 10 times (v3.2.8 needs -s)
free -V # versionThe output columns include Mem, Swap, total, used, free, shared, buff/cache, available, and the legacy -/+ buffers/cache line. Differences between kernel versions 3.2.8 and 3.3.10 are noted, especially how the "used" and "available" fields are calculated.
2. vmstat command
Syntax
vmstat -s [options]Example
# vmstat 2 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 3498472 315836 3819540 0 0 0 1 2 0 0 0 100 0Key fields:
r – number of runnable processes (CPU queue length)
b – processes blocked on I/O
swpd – virtual memory used (KB)
free – idle memory (KB)
buff – memory used for block device buffers
cache – page cache memory
si/so – swap in/out per second
bi/bo – block I/O reads/writes per second
in – interrupts per second
cs – context switches per second
us, sy, id, wa – CPU usage percentages (user, system, idle, I/O wait)
Typical trouble‑shooting notes: high r (>4) with low id (<40) signals CPU overload; non‑zero pi / po indicates memory pressure; high disk values point to I/O bottlenecks.
3. /proc/meminfo
How to view
cat /proc/meminfoSample output and key fields
Important entries include MemTotal, MemFree, MemAvailable, Buffers, Cached, SwapTotal, SwapFree, Active, Inactive, AnonPages, Shmem, Slab, and many others that give a detailed view of physical and virtual memory usage.
Values are reported in kB (kilobytes), not KB. You can also scroll the file with less /proc/meminfo .
Kernel source that generates the file
static int meminfo_proc_show(struct seq_file *m, void *v) {
struct sysinfo i;
unsigned long committed;
long cached;
long available;
unsigned long pages[NR_LRU_LISTS];
int lru;
si_meminfo(&i);
si_swapinfo(&i);
committed = percpu_counter_read_positive(&vm_committed_as);
cached = global_node_page_state(NR_FILE_PAGES) -
total_swapcache_pages() - i.bufferram;
if (cached < 0)
cached = 0;
for (lru = LRU_BASE; lru < NR_LRU_LISTS; lru++)
pages[lru] = global_node_page_state(NR_LRU_BASE + lru);
available = si_mem_available();
show_val_kb(m, "MemTotal: ", i.totalram);
/* ... many more show_val_kb calls for each metric ... */
return 0;
}4. top command
Syntax
top [-] [d delay] [q] [c] [S] [s] [i] [n] [b]Important options
d : change refresh delay
q : no delay; runs with highest priority if root
c : toggle full command line
S : cumulative mode
s : safe mode
i : hide idle/zombie processes
n : number of updates before exit
b : batch mode (useful for redirecting output)
Typical output sections
Load average line (from uptime)
Tasks line (process counts)
CPU line (us, sy, id, wa, etc.)
Memory line (total, free, used, buff/cache)
Swap line (total, free, used, avail)
Per‑process table (PID, USER, PR, NI, VIRT, RES, SHR, S, %CPU, %MEM, TIME+, COMMAND)
Examples show how to display processes, show full command lines, run in batch mode, limit update count, change delay, filter by PID, and quit after a set number of iterations.
5. htop command
htop is an interactive, color‑enhanced alternative to top that supports vertical and horizontal scrolling, allowing you to see all processes and their full command lines. It also provides shortcuts for killing, renicing, and filtering processes.
Typical key bindings:
F1/h/? : help
F2 : setup
F3 / : search
F4 \ : filter
F5 : tree view
F6 < >: change sort column
F7 [ : decrease nice
F8 ] : increase nice
F9 k : kill selected process
F10 q : quit
u : show processes of a specific user
U : unmark all processesIn htop the memory line shows total, used, buffers/cache, and swap separately, making it easy to spot memory pressure.
6. Inspecting a specific process’s memory
Read /proc/<pid>/status to obtain detailed information about a single process, such as Name, State, VmSize, VmRSS, Threads, and various capability flags.
cat /proc/4398/statusConclusion
Knowing how to use free, vmstat, /proc/meminfo, top, htop, and per‑process status equips Linux operators with the ability to diagnose memory‑related performance problems, detect CPU or I/O bottlenecks, and take corrective actions such as adjusting application behavior, adding RAM, or tuning kernel parameters.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
