There are several ways to monitor memory usage in a Linux system. Some may or may not be available depending on
- What version you are running
- How the kernel is configured
- What user-space tools are included in the root file-system
Since Linux typically is a virtual memory system, some statistics may be misleading and/or inaccurate. It is important to dig and understand what each statstic means.
With all that said, I typically monitor memory usage by running vmstat to get an idea of the total memory usage:
# vmstat -s
127168 total memory
44072 used memory
33296 active memory
2164 inactive memory
83096 free memory
0 buffer memory
20468 swap cache
0 total swap
0 used swap
0 free swap
582750 non-nice user cpu ticks
0 nice user cpu ticks
160883 system cpu ticks
7448748 idle cpu ticks
0 IO-wait cpu ticks
16066 IRQ cpu ticks
18249 softirq cpu ticks
0 stolen cpu ticks
0 pages paged in
0 pages paged out
0 pages swapped in
0 pages swapped out
15079537 interrupts
28629740 CPU context switches
1344249586 boot time
25532 forks
"free" Will also give you a bird's eye view of the memory usage. If I see anything unexpected, I will look on suspect processes by examining files in procfs. Good files to look at are
/proc/PID/maps - This lists all the memory currently mapped by the process
/proc/PID/smaps - Provides more details about how much memory is resident/shared/dirty/etc... This file can be verbose, but a Python script could be written to generate more meaningful data