In a shared memory environment, which is a technique used by most operating systems, there is a challenge of counting the memory several times. This ends up giving users and system administrators inaccurate information on how physical memory is used.
To solve this problem smem comes in very handy. Smem reports Unique Set Size (USS) which is the memory that is not shared with any other process and Proportional Set Size (PSS) which is the USS and a process’ fair share of the shared memory.
The standard measure of memory is known as Resident Set Size(RSS), which has a tendency of overestimating the memory used as you shall see later in this article.
Note, however, that the memory that has been moved to swap space is not reported by smem.
Installing Smem
If you have Fedora 19 upwards, smem is in the repositories and therefore you can use yum to install it as follows:
$ sudo yum install smem
For Ubuntu users, you can install smem as follows:
$ sudo apt-get install smem
Alternatively you can compile from source which can be found at selenic smem download page.
Command Line Options
After successfully installing smem, you can now run it with, various options. You can report memory usage by mapping, user or sytemwide. By default, smem will show each running process and the memory used. Here you start to note the way RSS reports memory used relative to USS and PSS.
$ smem
Smem can be used to show the memory used as per library. This can generate a long list depending on your system.
$ smem -m
At times is useful to see how a specific application is using memory for example Firefox. The -p option helps you to see memory usage in form of percentages which is more convenient.
$ smem -m -p | grep firefox
$ smem -u -p
You can also view the system wide memory with the -w option and adding -p to give percentage values.
$ smem -w -p
Generating Graphical Output
It is also possible with smem to generate graphical chart to show memory usage. To do this you need to have python installed on your machine.
Next install the matplotlib library which is used to generate the charts.
Next install the matplotlib library which is used to generate the charts.
Fedora users can install it by running the command:
$ sudo yum install python-matplotlib
While Ubuntu users can get it by running:
$ sudo apt-get install python-matplotlib
Once you have the library installed, you can now go ahead and get a visual representation of memory usage either in form of a bar graph or a pie chart.
Pie Chart
You can now view memory usage(USS, PSS and RSS) in form of a pie by using smem as follows:
$ smem –pie name -s uss
This will generate a pie chart which shows memory usage by USS. To get the PSS and RSS, simply replace uss in the command with the respective acronym.
From the three pie charts, you can see that RSS reports that I have 41.74% of unused memory while PSS 53.02% of unused memory. You can now see that using RSS can send a system administrator into panic mode while still there is ample memory in the system.
Bar Graph
Another cool feature of smem is generating the output in form of a bar graph. With this you are able to view the memory usage as reported by USS, PSS and RSS.
This is done as follows.
This is done as follows.
$ smem –bar pid -c “pss uss rss”
The above command will give the output with process ID numbers. If you want to view the process’ name you can replace ‘pid’ with ‘name’ without the quotes.
As before in the pie chart, RSS always gives an exaggerated view of memory used as you can see in the bar graph.
Conclusion
Smem is a great tool to use determine actual memory being used by your system.
No comments:
Post a Comment