A system that lacks enough physical memory (RAM) will run significantly slower, as processes are moved between the RAM and swap. If a Linux system begins running slow, one of the first troubleshooting tasks is to free up physical memory.
There are multiple tools available to monitor the memory usage on a Linux system, including top, which we have discussed. Smem is another tool, used for monitoring memory usage. In addition to displaying the memory use of processes on the command line, smem can also display a color coded pie and/or bar chart. With smem, you can easily visualize memory use on your Linux system.
On Debian and Ubuntu systems, smem can be installed from the repositories with the command
sudo apt-get install smem
Check Memory Usage
Running smem as an unprivileged user will show the memory used by all processes launched with the current user ID, ordered by PSS from least to most.
By default, there are seven columns, the process ID, the username, the command used to launch the process, the amount of swap space allocated to the process, and USS, PSS and RSS.
RSS (Resident set size) is the total memory held in RAM for a process. This includes the memory allocated to shared libraries used by the process, although shared libraries can be used by multiple processes, while being loaded only once in memory. RSS is therefore not an accurate representation of the memory used by a given process.
PSS (Proportional set size), on the other hand, shares the memory allocated to a shared library among the processes using it. Hence, if three processes use a shared library that has sixty pages, the library will contribute twenty pages to the PSS of each of the processes. The total PSS is usually about equal to the total RAM of the system. However, when a process that shares a library is killed, the PSS reported for the process is not equal to the total memory freed.
USS (Unique set size) refers to the total unique memory for a process. This does not include memory from shared libraries. When a process is killed, the USS refers to the actual memory that would be freed. As a result, the USS is the value to watch if you suspect a process has a memory leak.
Running smem as root shows all processes for all users on the system.
Visualize Memory Use
A visualized report is almost certainly easier to read than text-based results. Using smem, you can view the memory usage as either a pie chart or a bar chart.
To view a bar chart for PSS, USS and RSS of the current user’s processes run the following command:
smem --bar name -c "pss uss rss"
Recall that the PSS is a closer reflection of the total memory available on the system. To view a pie chart of this, use the following command:
smem --pie name
To view a pie chart of RSS labeled by name:
smem --pie name -s rss
Using smem, you can easily view the memory used by applications and processes on your system, with a helpful color-coded pie chart or bar chart. As is commonly said, a picture is worth a thousand words. It seems the smem developers agree.
Our latest tutorials delivered straight to your inbox