Andreas Vöst
2 months
Stefan Langenmaier
1 year
Claus-Theodor Riegg
1 year
Claus-Theodor Riegg
4 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
8 years

Linux Memory Metrics

Posted . Visible to the public. Repeats.

There are different kind of memory measurement metrics in Linux. These are the differences:

Code Name Description
vsz virtual memory size Total amount of memory a process may hypothetically access. Includes swapped memory, memory from external libraries and allocated memory that’s not used.
rss resident set size Total amount of non-swapped used physical memory. Includes memory from external shared libraries.
pss proportional share size Total amount of non-swapped physical memory with shared memory proportionally accounted.
uss unique set size Total amount of the non-swapped physical memory which is not shared with an another task.
  • First choice for metrics is pss
  • Second choice (due to the lack of Ubuntu support for pss) is rss

Commands

ps and smem Show archive.org snapshot can be used to display the metrics. The default ps version in Ubuntu does not support all of them. smem can be used to access all metrics on older Ubuntu versions. However the syntax is a bit clunky. You can use -P as filter but not for the PID.

Code ps command smem command Ubuntu ps support
vsz ps -p "${pid}" -o vsz smem -c "pid vss" | grep "${pid}" | awk '{ print $2}' Yes
rss ps -p "${pid}" -o rss smem -c "pid rss" | grep "${pid}" | awk '{ print $2}' Yes
pss ps -p "${pid}" -o pss smem -c "pid pss" | grep "${pid}" | awk '{ print $2}' Ubuntu 24.04+
uss ps -p "${pid}" -o uss smem -c "pid uss" | grep "${pid}" | awk '{ print $2}' Ubuntu 24.04+
Andreas Vöst
Last edit
Ruben Aleman
License
Source code in this card is licensed under the MIT License.