In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use the free command to check memory usage under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use the free command to check memory usage under Linux.
Display system memory
Running the free command without any options displays the total memory of the system, including free, used, swap, buffers, cached, and swap.
# free total used free shared buffers cachedMem: 32869744 25434276 7435468 0 412032 23361716 Mozilla + buffers/cache: 1660528 31209216Swap: 4095992 04095992
The output has three lines:
The first line: indicates all memory, used memory, free memory, shared memory (mainly used by tmpfs (the Shmem entry in / proc/meninfo), memory used for buffering, and cache content size.
All: all installed memory (MemTotal entry in / proc/meminfo) used: used memory (all compute-space + buffer + cache) free: unused memory (MemFree entry in / proc/meminfo) sharing: memory mainly used by tmpfs (Shmem entry in / proc/meminfo) buffering: memory used by kernel cache (Buffers entry in / proc/meminfo) cache: used by page cache and slab Memory (Cached and SSReclaimable entries in / proc/meminfo)
Second line: buffers / caches indicating used and idle
The third line indicates total swap memory (SwapTotal entry in / proc/meminfo), free memory (SwapFree entry in / proc/meminfo), and used swap memory.
Display system memory in MB
By default, the free command outputs system memory in KB-Kilobytes units, which can be a little confusing for most administrators (when the system memory is large, many of us need to convert the output to MB units in order to understand the memory size). To avoid this confusion, we add the-m option to the free command to get the output in MB-Megabytes immediately.
# free-m total used free shared buffers cachedMem: 32099 24838 7261 0402 22814 + buffers/cache: 1621 30477Swap: 3999 0 3999
How do I check how much free memory is left from the above output? It is mainly based on used (used) and idle (free) columns. You may be thinking, you have very low free memory, because it is only 10%, why?
All actual available memory = (all memory-used memory in line 2)
All memory = 32099 actual used memory = 1621 (= all memory-buffer-cache)
All actual available memory = 30477
If your Linux version is up to date, there is an option to view the actual free memory called available, and for the older version, see the free column that shows the-/ + buffers/cache line.
How do I check how much memory is actually used from the above output? Based on the used (used) and idle (free) columns. You may think that you have used more than 95% of the memory.
All actual used memory = first column used-(first column buffer + first column cache)
Used memory = 24838 used buffer = 402 used cache = 22814
All actual used memory = 1621
Display memory in GB
By default, the free command displays output in KB-kilobytes units, which can be a bit confusing for most administrators, so we use the options above to get output in MB-Megabytes units. However, the above options can also be confusing when the server has a large amount of memory (more than 100 GB or 200 GB). So, at this point, we can add the-g option to the free command to get the output in GB-Gigabytes immediately.
# free-g total used free shared buffers cachedMem: 31 24 7 00 22 Muhammad + buffers/cache: 1 29Swap: 3 03 shows all memory lines
By default, the output of the free command is only three lines (memory, buffering / caching, and swapping). To uniformly display on a single line (all (memory + swap), used (memory + (used-buffer / cache) + swap) and idle (memory + (used-buffer / cache) + swap), add the-t option after the 'free' command.
# free-t total used free shared buffers cachedMem: 32869744 25434276 7435468 0 412032 23361716 buffers/cache: 1660528 31209216Swap: 4095992 0 4095992Total: 36965736 27094804 42740676 run the free command delayed for better statistics
By default, the free command displays statistical output only once, which is not enough for further troubleshooting, so memory activity can be counted periodically by adding a delay (which means updating again in a few seconds). If you want to run the free command with a delay of two seconds, you can use the following command (if you want more delay, you can change the value as you wish).
The following command will be run every 2 seconds until you exit:
# free-s 2 total used free shared buffers cachedMem: 32849392 25935844 6913548 182424 24632796 buffers/cache + buffers/cache: 1120624 31728768Swap: 20970492 total used free shared buffers cachedMem: 32849392 25935288 6914104 188 182424 24632796 31729324Swap + buffers/cache: 1120624 : 20970492 0 20970492 total used free shared buffers cachedMem: 32849392 25934968 6914424 188 182424 24632796 buffers/cache + buffers/cache: 1119748 31729644Swap: 20970492 020970492 run the free command according to delay and specific times
In addition, you can run the free command by delay and a specific number of times, and then exit automatically once a certain number of times is reached.
The following command will run the free command every 2 seconds and automatically exit after counting 5 times.
# free-s 2-c 5 total used free shared buffers cachedMem: 32849392 25931052 6918340 182424 24632796 buffers/cache + buffers/cache: 1115832 31733560Swap: 20970492 total used free shared buffers cachedMem: 32849392 25931192 6918200 188 182424 24632796 buffers/cache: 1115972 31733420Swap: 20970492 0 20970492 total used free shared buffers cachedMem: 32849392 25931348 6918044188 182424 24632796 buffers/cache + buffers/cache: 1116128 31733264Swap: 20970492 total used free shared buffers cachedMem: 32849392 25931316 6918076 188 182424 24632796max Buffers/cache: 1116096 31733296Swap: 20970492 0 20970492 total used free shared buffers cachedMem: 32849392 25931308 6918084 188 182424 24632796 Muhammad + buffers/cache: 1116088 31733304Swap: 20970492 020970492 cancel buffer and cache memory output
By default, buffer / cache memory is output at the same time. To unbuffer and cache the output from memory, you can add the-w option after the free command. (this option is available on version 3.3.12)
Note that the output with buffered / cached above is compared.
# free-wh total used free shared buffers cache availableMem: 2.0G 1.6G 137m 20m 8.1m 183m 163MSwap: 2.0g 1.8g 249m shows the lowest and highest memory statistics
By default, the free command does not display the lowest and highest memory statistics. To display the lowest and highest memory statistics, add the-l option after the free command.
# free-l total used free shared buffers cachedMem: 32849392 25931336 6918056 188 182424 24632808Low: 32849392 25931336 6918056High: 0.000 Muhammad + buffers/cache: 1116104 31733288Swap: 20970492 020970492
Read more about the free command
If you want to know more about the options available for the free command, just check its man manual.
# free-helpor# man free at this point, I believe you have a better understanding of "how to use the free command to check memory usage under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.