In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to check memory usage in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Unlike Windows, Linux often doesn't have a graphical interface to use, especially in a server environment.
As a Linux administrator, it is important to know how to get information about currently available and used resources, such as memory, CPU, disks, and so on. If an application takes up so many resources on your system that your system cannot reach its optimal state, you need to find it and fix it.
If you want to find the top 10 memory-consuming processes, you need to read this article: how to find the most memory-consuming processes in Linux.
In Linux, commands can do anything, so use them. In this tutorial, we will show you eight useful commands to view memory usage on Linux systems, including RAM and swap partitions.
Creating a swap partition is very important in a Linux system, and if you want to know how to create it, you can read this article: create a swap partition on a Linux system.
The following commands can help you view Linux memory usage in different ways.
Free command
/ proc/meminfo file
Vmstat command
Ps_mem command
Smem command
Top command
Htop command
Glances command
1) how to use the free command to view Linux memory usage
The free command is the main command widely used by Linux administrators. But it provides less information than the / proc/meminfo file.
The free command shows the number of used and unused physical memory and swap partition memory, as well as the buffers and caches used by the kernel.
This information is obtained from the / proc/meminfo file.
# free-m total used free shared buff/cache availableMem: 15867 9199 1702 3315 4965 3039Swap: 17454 666 16788
Total: total amount of memory
Used: the amount of memory used by the currently running process (used = total-free-buff/cache)
Free: amount of unused memory (free = total-used-buff/cache)
Shared: the amount of memory shared between two or more processes
Buffers: the amount of memory reserved in memory for the kernel to record process queue requests
Cache: the page buffer size that stores recently used files in RAM
Buff/cache: total amount of memory used by buffers and caches
Available: amount of available memory that can be used to launch new applications (excluding swap partitions)
2) how to use the / proc/meminfo file to view Linux memory usage
The / proc/meminfo file is a virtual file that contains real-time information about multiple memory uses. It shows that the memory state unit uses kB, most of which are difficult to understand. However, it also contains useful information about memory usage.
# cat / proc/meminfo MemTotal: 16248572 kBMemFree: 1764576 kBMemAvailable: 3136604 kBBuffers: 234132 kBCached: 4731288 kBSwapCached: 28516 kBActive: 9004412 kBInactive: 3552416 kBActive (anon): 8094128 kBInactive (anon): 2896064 kBActive (file): 910284 kBInactive (file): 656352 kBUnevictable: 80 kBMlocked: 80 kBSwapTotal: 17873388 kBSwapFree: 17191328 kBDirty: 252 kBWriteback: 0 kBAnonPages: 7566736 kBMapped: 3692368 kBShmem: 3398784 kBSlab: 278976 kBSReclaimable: 125480 kBSUnreclaim: 153496 kBKernelStack: 23936 kBPageTables: 73880 kBNFS_Unstable: 0 kBBounce: 0 kBWritebackTmp: 0 kBCommitLimit: 25997672 kBCommitted_AS: 24816804 kBVmallocTotal: 34359738367 KBVmallocUsed: 0 kBVmallocChunk: 0 kBPercpu: 3392 kBHardwareCorrupted: 0 kBAnonHugePages: 0 kBShmemHugePages: 0 kBShmemPmdMapped: 0 kBHugePages_Total: 0HugePages_Free: 0HugePages_Rsvd: 0HugePages_Surp: 0Hugepagesize: 2048 kBHugetlb: 0 kBDirectMap4k: 1059088 kBDirectMap2M: 14493696 kBDirectMap1G: 2097152 kB3) how to use the vmstat command to view Linux memory usage
The vmstat command is another useful tool for reporting virtual memory statistics.
The information reported by vmstat includes: process, memory, page mapping, block Imax O, traps, disk, and CPU property information. Vmstat does not require special permissions, and it can help diagnose system bottlenecks.
# vmstat procs-memory--swap---io-----system---cpu- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 682060 1769324 234188 4853500 0 3 25 91 31 16 34 13 52 00
If you want to know the meaning of each item in detail, read the description below.
Procs: process
R: number of processes that can be run (running or waiting to run)
B: number of processes in uninterruptible sleep
Memory: memory
Swpd: amount of virtual memory used
Free: amount of free memory
Buff: the amount used as buffer memory
Cache: the amount used as cache memory
Inact: amount of inactive memory (using the-an option)
Active: amount of active memory (using the-an option)
Swap: swap partition
Si: the amount of memory swapped from disk per second
So: the amount of memory swapped to disk per second
IO: input and output
Bi: blocks received from a block device (blocks per second)
Bo: blocks sent to a block device (blocks per second)
System: system
In: number of interrupts per second, including the clock.
Cs: the number of context changes per second.
CPU: the following are the percentage of total CPU time
Us: percentage of time spent on non-kernel code (including user time, scheduling time)
Sy: percentage of time spent on kernel code (system time)
Id: the percentage of time spent idle. Before Linux 2.5.41, including the Imax O wait time
Wa: the percentage of time spent waiting for iCompo. Before Linux 2.5.41, included in idle time
St: the percentage of time stolen by a virtual machine. Before Linux 2.6.11, this part was called unknown
Run the following command to view the details.
# vmstat-s 16248580 K total memory 2210256 K used memory 2311820 K active memory 2153352 K inactive memory 11368812 K free memory 107584 K buffer memory 2561928 K swap cache 17873388 K total swap 0 K used swap 17873388 K free swap 44309 non-nice user cpu ticks 164nice user cpu ticks 14332 system cpu ticks 382418 idle cpu ticks 1248 IO-wait cpu ticks 1407 IRQ cpu ticks 2147 softirq cpu ticks 0 stolen cpu ticks 1022437 pages paged in 260296 pages paged out 0 pages swapped in 0 pages swapped out 1424838 interrupts 4979524 CPU context switches 1577163147 boot time 3318 forks4) how to use the ps_mem command to view Linux memory usage
Ps_mem is a simple Python script used to view current memory usage. This tool can determine how much memory each program uses (not each process).
The tool calculates the memory used by each program in the following way: total usage = private memory of the program process + memory shared by the program process.
There are shortcomings in computing shared memory, and the tool can automatically select the most accurate method for the running kernel.
# ps_mem Private + Shared = RAM used Program180.0 KiB + 30.0 KiB = 210.0 KiB xf86-video-intel-backlight-helper (2) 192.0 KiB + 66.0 KiB = 258.0 KiB cat (2) 312.0 KiB + 38.5 KiB = 350.5 KiB lvmetad380.0 KiB + 25.5 KiB = 405.5 KiB crond392.0 KiB + 32.5 KiB = 424.5 KiB rtkit-daemon852.0 KiB + 117.0 KiB = 969.0 KiB Gnome-session-ctl (2) 928.0 KiB + 56.5 KiB = 984.5 KiB gvfs-mtp-volume-monitor 1.0 MiB + 42.5 KiB = 1.0 MiB dconf-service 1.0 MiB + 106.5 KiB = 1.1 MiB gvfs-goa-volume-monitor 1.0 MiB + 180.5 KiB = 1.2 MiB gvfsd.. 5.3 MiB + 3.0 MiB = 8.3 MiB evolution-addressbook-factory 8.5 MiB + 1.2 MiB = 9.7 MiB gnome-session-binary (4) 7.5 MiB + 3.1 MiB = 10.5 MiB polkitd 7.4 MiB + 3.3 MiB = 10.7 MiB pulseaudio (2) 7.0 MiB + 7.0 MiB = 14.0 MiB msm_notifier 12.7 MiB + 2.3 MiB = 15.0 MiB Evolution-source-registry 13.3 MiB + 2.5 MiB = 15.8 MiB gnome-terminal-server 15.8 MiB + 1.0 MiB = 16.8 MiB tracker-miner-fs 18.7 MiB + 1.8 MiB = 20.5 MiB python3.7 16.6 MiB + 4.0 MiB = 20.5 MiB evolution-calendar-factory 22.3 MiB + 753.0 KiB = 23.0 MiB gsd-keyboard (2) 22.4 MiB + 832.0 KiB = 23 .2 MiB gsd-wacom (2) 20.8 MiB + 2.5 MiB = 23.3 MiB blueman-tray 22.0 MiB + 1.8 MiB = 23.8 MiB blueman-applet 23.1 MiB + 934.0 KiB = 24.0 MiB gsd-xsettings (2) 23.7 MiB + 1.2 MiB = 24.9 MiB gsd-media-keys (2) 23.4 MiB + 1.6 MiB = 25.0 MiB gsd-color (2) 23.9 MiB + 1.2 MiB = 25.1 MiB gsd-power (2) 16.5 MiB + 8.9 MiB = 25.4 MiB evolution-alarm-notify 27.2 MiB + 2.0 MiB = 29.2 MiB systemd-journald 28.7 MiB + 2.8 MiB = 31.5 MiB c 29.6 MiB + 2.2 MiB = 31.8 MiB chrome-gnome-sh (2) 43.9 MiB + 6.8 MiB = 50.7 MiB WebExtensions 46.7 MiB + MiB = 53.5 MiB goa-daemon 86.5 MiB + 55.2 MiB = 141.7 MiB Xorg (2) 191.4 MiB + 24.1 MiB = 215.4 MiB notepadqq-bin306.7 MiB + 29.0 MiB = 335.7 MiB gnome-shell (2) 601.6 MiB + 77.7 MiB = 679.2 MiB firefox 1.0 GiB + 109.7 MiB = 1.1 GiB chrome (15) 2.3 GiB + 123.1 MiB = 2 .5 GiB Web Content (8)-5.6 GiB==5) how to use the smem command to view Linux memory usage
Smem is a tool that can provide a variety of memory usage reports for Linux systems. Unlike existing tools, smem can report scale set size Proportional Set Size (PSS), unique set size Unique Set Size (USS), and resident set size Resident Set Size (RSS).
Proportional set size (PSS): the usage of libraries and applications in virtual memory systems.
Unique set size (USS): it reports non-shared memory.
Resident set size (RSS): physical memory usage (usually shared by multiple processes), which is usually higher than memory usage.
# smem-tk PID User Command Swap USS PSS RSS3383 daygeek cat 0 92.0K 123.0K 1.7M3384 daygeek cat 0 100.0K 129.0K 1.7M1177 daygeek / usr/lib/gnome-session-ctl 0436.0K 476.0K 4.6M1171 daygeek / usr/bin/dbus-daemon-- conf 0524.0K 629.0K 3.8M1238 daygeek / usr/lib/xdg-permission-sto 0592.0K 681.0K 5.9M1350 daygeek / usr/lib/gsd-screensaver-pr 0652.0K 701.0K 5.8M1135 daygeek / usr/lib/gdm-x-session-- ru 0648.0K 723.0K 6.0M..1391 daygeek / usr/lib/evolution-data-ser 0 16.5M 25.2m 63.3M1416 daygeek caffeine-ng 0 28.7M 31.4M 66.2M4855 daygeek / opt/google/chrome/chrome-038.3M 46.3M 120.6M2174 daygeek / usr/lib/firefox/firefox-c 044.0M 50.7m 120.3M1254 daygeek / usr/lib/goa-daemon 0 46.7M 53.3M 80.4M3416 daygeek / opt/google/chrome/chrome-044.7M 54.2M 103.3M4782 daygeek / opt/google/chrome/chrome-057.2M 65.8M 142.3M1137 daygeek / usr/lib/Xorg vt2-displayf 077.2M 129.6M 192.3M3376 daygeek / opt/google/chrome/ Chrome 0 117.8M 131.0M 210.9M4448 daygeek / usr/lib/firefox/firefox-c 0 124.4M 133.8M 224.1M3558 daygeek / opt/google/chrome/chrome-0157.3M 165.7M 242.2M2310 daygeek / usr/lib/firefox/firefox-c 0 159.6M 169.4M 259.6M4331 daygeek / usr/lib/firefox/firefox-c 0176 .8M 186.2m 276.8M4034 daygeek / opt/google/chrome/chrome-0179.3M 187.9M 264.6M3911 daygeek / opt/google/chrome/chrome-0183.1M 191.8M 269.4M3861 daygeek / opt/google/chrome/chrome-0199.8M 208.2M 285.2M2746 daygeek / usr/bin/../lib/notepadqq/n 0193.5M 217. 5m 261.5M1194 daygeek / usr/bin/gnome-shell 0203.7M 219.0M 285.1M2945 daygeek / usr/lib/firefox/firefox-c 0294.5M 308.0M 410.2M2786 daygeek / usr/lib/firefox/firefox-c 0341.2M 354.3M 459.1M4193 daygeek / usr/lib/firefox/firefox-c 0417.4M 427.6m 519.3M2651 daygeek / usr/lib/firefox/firefox-c 0 417.0M 430.1M 535.6M2114 daygeek / usr/lib/firefox/firefox-c 0430.6M 473.9M 610.9M2039 daygeek / usr/lib/firefox/firefox-0601.3M 677.5M 840.6M- -90 1 0 4.8G 5.2g 8.0G6) how to use the top command to view Linux memory usage
The top command is the most commonly used command used by administrators of a Linux system to view the resource usage of a process.
This command shows the total memory of the system, the current memory usage, the amount of free memory, and the total memory used by the buffer. In addition, the command shows the total amount of swap space memory, the current swap space memory usage, the amount of free swap space memory, and the total memory used by the cache.
# top-b | head-10 top-11:04:39 up 40 min, 1 user, load average: 1.59,1.42, 1.28Tasks: 288 total, 2 running, 286 sleeping, 0 stopped, 0 zombie%Cpu (s): 13.3 us, 1.5 sy, 0.0 ni, 84.4 id, 0.0 wa, 0.3 hi, 0.5 si, 0.0 stKiB Mem: 16248572 total, 7755928 free, 4657736 used, 3834908 buff/cacheKiB Swap: 17873388 total 17873388 free, 0 used. 9179772 avail Mem PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 2114 daygeek 20 3182736 616624 328228 R 83.3 3.8 7 daygeek 09.72 Web Content 2039 daygeek 20 4437952 849616 261364 S 13.3 5.2 7 daygeek 58.54 firefox 1194 daygeek 20 4046856 2988 165460 S 4.2 1.81 57.68 gnome-shell 4034 daygeek 20 808556 273244 88676 S 4.21. 71: 44.72 chrome 2945 daygeek 20 3309832 416572 150112 S 3.3 2.6 4:04.60 Web Content 1137 daygeek 20 564316 197292 183380 S 2.5 1.2 2:55.76 Xorg 2651 daygeek 20 3098420 547260 275700 S 1.7 3.4 2:15.96 Web Content 2786 daygeek 20 2957112 463912 240744 S 1.7 2.9 3:22.29 Web Content 1 root 20 182756 10208 7760 S 0.8 0.1 irq/141-iw+ 04.51 systemd 442 root-51 S 0.8 0 daygeek 05.02 irq/141-iw+ 1426 daygeek 20 373660 48948 29820 S 0.8 0.3 0 daygeek 03.55 python3 2174 daygeek 20 2466680 122196 78604 S 0.8 0 irq/141-iw+ 17.75 WebExtensi+7) how to use the htop command to view Linux memory usage
The htop command is an interactive Linux/Unix system process viewer. It is a text mode application, and using it requires ncurses libraries developed by Hisham.
This command is designed to be used instead of the top command. This command is similar to the top command, but it allows you to scroll vertically or horizontally so that you can see all the processes in the system.
The htop command has different colors, which is an added advantage when you are tracking system performance.
In addition, you are free to perform process-related tasks, such as killing a process or changing its priority without requiring its process number (PID).
8) how to use the glances command to view Linux memory usage
Glances is a cross-platform system monitoring tool written by Python.
You can view all the information in one place, such as: CPU usage, memory usage, running processes, network interface, disk ID O, RAID, sensors, file system information, Docker, system information, run time, and so on.
Thank you for reading! This is the end of this article on "how to check memory usage in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.