In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use smem to check the memory footprint in Linux, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.
Whether as a system administrator or as a simple user of the desktop version of Linux, you will notice that a process is consuming all the memory of your system.
First of all, understand how Linux manages memory; I've been told many times that if I run the free command, I just can't read the output properly. In short, if it's the Linux kernel, don't worry; the kernel is consuming memory and caching files.
Rest assured, Linux kernel developers are better able than you and me to find a good algorithm to cache files and free up that area of memory when a process needs it, so don't let me put a task running a command like this into a scheduled task (cron):
Echo 3 > / proc/sys/vm/drop_caches
Of course, after that, you will have more free memory on the system, but the system will have to reread all files from disk, so this is usually a bad move in terms of performance:
But now we might as well look at a small program that can help us find out which processes / users are consuming a lot of our system's memory.
Smem is a tool that provides numerous reports on memory consumption on Linux systems. Unlike existing tools, smem can report physical memory actually used (PSS), which is a more meaningful metric for measuring the amount of memory consumed by libraries and applications in a virtual memory system.
Because most of the physical memory is usually shared among multiple applications, this standard memory consumption metric, called physical memory actually used (RSS), greatly overestimates memory consumption. The PSS parameter instead measures the "fair distribution" of each application in each shared memory area, giving a realistic metric.
Smem has many functional features:
System Overview list
By process, mapping, and user list
Filter by user, map, or user
Configurable columns from multiple data sources
Configurable output units and percentage
Configurable title and sum
Read active data from / proc
Read data snapshots from directory mirrors or compressed packaged files
Lightweight capture tool for embedded system
Built-in chart generation function
Installation
If you use Debian, Ubuntu, or Mint, you can use the following command to install smem directly from the official software library:
$sudo apt-get install smem
Arch Linux users can install packages from the Arch user Software Library (AUR, https://www.archlinux.org/packages/community/i686/smem/).
Red Hat / Fedora / CentOS / SuSE users can use precompiled binaries downloaded directly from the official website. For convenience, you can copy and paste these commands, which will put the command smen into your / usr/local/bin folder:
Cd / tmp/ wget http://www.selenic.com/smem/download/smem-1.3.tar.gz tar xvf smem-1.3.tar.gz sudo cp / tmp/smem-1.3/smem / usr/local/bin/ sudo chmod + x / usr/local/bin/smem
Basic usage
Smem reports physical memory usage and takes into account shared memory pages. Non-shared memory is reported as physical memory (USS) occupied by the process alone. Shared memory is evenly distributed among multiple processes that share the memory. Unshared memory (USS) and the shared memory ratio of processes are reported as physical memory actually used (PSS). USS and PSS contain only physical memory usage. They do not contain memory that has been replaced to disk.
The basic usage shows the running process and the amount of memory used; to see this, run the command smem with no options, which produces output similar to the following:
# smem PID User Command Swap USS PSS RSS.... 4223 linuxaria / usr/lib/chromium-browser/c 0 9144 11696 29132 14280 root python. / smem 0 11580 11839 13680 2180 linuxaria / usr/bin/python / usr/share/ 0 12956 14691 24392 2144 linuxaria python / usr/lib/linuxmint/m 020252 22337 35648 2121 linuxaria Thunar-daemon 013316 23122 44404 2123 Linuxaria xfdesktop 0 24004 24924 36032 13095 linuxaria / usr/lib/chromium-browser/c 0 27536 30996 53328 2577 linuxaria / usr/bin/python / usr/lib/ub 0 34192 35112 41300 2127 linuxaria / home/riccio/copy/x86_64/Co 0 40268 41081 52248 10720 linuxaria / usr/lib/chromium-browser/c 0 38684 42107 63928 10561 linuxaria / usr/lib/chromium-browser/c 0 43956 48137 71644 10579 linuxaria/ usr/lib/chromium-browser/c 0 46276 50290 73484 5605 linuxaria transmission-gtk / tmp/ [kick 0 48616 51508 65148 8938 linuxaria/ usr/lib/firefox/plugin-con 0 48960 55428 71132 2186 linuxaria/ home/linuxaria/.dropbox-dist/ 0 55524 56061 64820 1722 root / usr/bin / X: 0-audit 0-aut 0 52360 73110 96008 10623 linuxaria / usr/lib/chromium-browser/c 0 114224 121888 149236 4171 linuxaria chromium-browser-disable- 0 131044 140415 165780 7050 linuxaria / usr/lib/thunderbird/thunde 0253428 256803 273152 2644 linuxaria / usr/lib/firefox/firefox 0528420 537423 558992
So in this example (my desktop), the process that consumes more memory is Firefox, and the second most memory consuming process is Thunderbird.
-u is a useful option that shows the total amount of memory consumed by each user:
# smem-uUser Count Swap USS PSS RSS daemon 1 0196 197 368 rtkit 1 0300 312 1396 nobody 1 0428 442 1600 mdm 20 600 695 1808 avahi 20 568 806 2420 syslog 1 0 1032 1043 1884 messagebus 10 1124 1207 2048 root 40 0 96568 123002 203372 linuxaria 83 0 1539864 1640378 2222556
You can add-p to the command to display the percentage value:
# smem-u-pUser Count Swap USS PSS RSS daemon 1 0.000% 0.002 rtkit 1 0.000% 0.002 nobody 1 0.001 0.01% 0.01% 0.02 mdm 2 0.000. 01% 0.01% 0.02% avahi 2 0.00% 0.01% 0.01% 0.03% syslog 1 0.00% 0.01% 0.01% 0.02% messagebus 1 0.00% 0.01% 0.01% 0.03% root 40 0.00% 1.18% 1.47% 2.41% linuxaria 83 0.009% 19.29% 20.48% 27.58%
Or, if you prefer to see the memory usage of the entire system, you can use the-w option:
# smem-w-pArea Used Cache Noncache firmware/hardware 0.00% 0.00% 0.00% kernel image 0.00% 0.00% 0.00% kernel dynamic memory 64.55% 62.42% 2.13% userspace memory 22.12% 3. 00% 19.12% free memory 13.33% 13.33% 0.005%
Speaking of-w, I recommend using the alternative-R REALMEM, which refers to the amount of physical memory. This allows smem to find the amount of memory consumed by firmware / hardware in the output of the entire system (- w). If provided, it can also be used as the total amount of memory used as a percentage.
# smem-R 8G-w-pArea Used Cache Noncache firmware/hardware 2.83% 0.003% 2.83% kernel image 0.00% 0.00% 0.00% kernel dynamic memory 63.02% 60.95% 2.07% userspace memory 21.60% 2.91% 18.68% free memory 12.56% 12.56% 0.005%
Display linux memory graphically with smen
With the help of smem (and the matplotlib library), bar and pie charts can be generated with a few more options.
Displays a bar chart with the columns "pss" and "uss":
# smem-bar pid-c "pss uss"
Create a pie chart that shows the processes that start with "k" on the running system:
# smem-P'^ k'- pie=name
The above is all the contents of the article "how to use smem to check memory footprint in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.