Linux Process Memory - from the address space to what the tools report
This Learning is about the memory of a user process in Linux. The first article explains how the kernel lays out and describes a process's virtual memory and how that memory can be read from outside; the second shows what the usual tools report and why their numbers differ.
/proc/<PID>/maps, /proc/<PID>/mem and the meaning of VSS, RSS, PSS and USS have not changed.Both articles end with a section Current practice, which says what has changed since and what to do instead today.
The levels
Each level ends with a small check. There is no time limit: when you can do what the check asks, go on to the next level.
| Level | You practice | You have passed the level when |
|---|---|---|
| 1 · Understand | Physical and virtual memory, paging, the address space and its regions | You can draw the memory regions of a process and say what each one holds |
| 2 · Read | The memory descriptor, /proc/<PID>/maps, reading a region from /proc/<PID>/mem | You can find the heap and the stack of a running process in its maps file |
| 3 · Measure | ps, pmap, smem and ps_mem.py on the same process | You can say what VSS, RSS, PSS and USS each count, and which one answers "how much would I get back if this process ended" |
Levels 1 and 2 are the first article: sections 1 and 2 for level 1, sections 3 to 6 for level 2. Level 3 is the second article.
The articles
Both articles also exist in Slovak, the language they were written in; the (SK) link is at the top of each.
| # | Article | What it is |
|---|---|---|
| 1 | The virtual memory of a user process in Linux | Levels 1 and 2: the address space, the memory regions, the kernel's memory descriptor, and tools that read and dump process memory |
| 2 | Diagnosing process memory use in Linux | Level 3: the four memory figures, the tools that report them, and a worked measurement of Midnight Commander |
What you will be able to do
- Explain why the virtual size of a process says little about the memory it uses.
- Read the memory map of a process and recognise its regions.
- Choose the right figure for the question you are asking.
- Measure how the memory of a process changes while it works.
Set up once
A Linux machine where you are root. The second article downloads smem and ps_mem.py; both are single scripts.
Final check
Pick a process on your machine and report its memory with two tools. Explain why the two numbers differ.