brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: smem shows the fair share of shared memory that each process uses

Memory
~/tips/tip-memory-smem-pss

sudo apt install smem

Get per process and per user memory numbers that add up sensibly.

Add up the RSS column in ps and you can end up with more memory than the machine has. Shared libraries are counted again for every process that uses them.

smem reports a fairer figure, the PSS:

sudo apt install smem
smem -tk

PSS, the proportional set size, is the memory a process has to itself plus its share of what it splits with others. USS is only the private part. -t adds a totals line and -k prints units.

Group the result by user to see which account is the heavy one:

sudo smem -utk

Or limit the list to processes that match a pattern, handy for a program that starts many workers:

sudo smem -tk -P php-fpm

The total of the PSS column for those workers is a good estimate of what the whole group costs, which is the number I want when I decide how many workers a small server can hold.

Without sudo you only get full figures for your own processes. USS tells you roughly what you would get back by stopping one process, while PSS is better for totals, so pick the column that matches your question. The tool reads /proc for every process and can take a few seconds on a busy machine. It is also a snapshot, so a leak only shows when you run it several times.

Further reading: smem man page

More Memory tips lsmem --summary for f in /proc/[0-9]*/status; do sudo pmap -x 1234 sudo systemctl edit indexer.service leaks -atExit — ./myprogram --some-option All Memory tips (12) All topics

Link