We all knows, most of the Servers (Including world Top Super Computers are running in linux) are running in Linux platform on IT infrastructure because Linux is more flexible compare with other operating systems. Other operating systems required reboot for small small changes & patch updates but Linux systems doesn’t required reboot except critical patch updates.

One of the big challenge for Linux administrator to maintain the system up and running without any downtime. To managing memory utilization on Linux is another challenging task for administrator, free is one of the standard & widely used command, to analyze Memory Statistics (Free & Used Memory) in Linux. Today we are going to cover free command with useful options.

Suggested Articles : smem Linux Memory Reporting/Statistics Tool vmstat A Standard Nifty Tool to Report Virtual Memory Statistics

What’s Free Command

free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo.

Display System Memory

Run the free command without any option to display system memory, including total amount of free , used , buffers , caches & swap .

# free total used free shared buffers cached
Mem: 32869744 25434276 7435468 0 412032 23361716
-/+ buffers/cache: 1660528 31209216
Swap: 4095992 0 4095992

The output has three columns.

Column-1 : Indicates Total memory, used memory, free memory, shared memory (mostly used by tmpfs (Shmem in /proc/meminfo)), memory used for buffers, cached contents memory size. Total : Total installed memory (MemTotal in /proc/meminfo) Used : Used memory (calculated as total free + buffers + cache) Free : Unused memory (MemFree in /proc/meminfo) Shared : Memory used (mostly) by tmpfs (Shmem in /proc/meminfo) Buffers : Memory used by kernel buffers (Buffers in /proc/meminfo) Cached : Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo) Column-2 : Indicates buffers/cache used & free. Column-3 : Indicates Total swap memory (SwapTotal in /proc/meminfo), free (SwapFree in /proc/meminfo)) & used swap memory. Display Memory in MB

By default free command output display memory in KB - Kilobytes which is bit confusion to most of the administrator (Many of us convert the output to MB, to understand the size, when the system has more memory). To avoid the confusion, add -m option with free command to get instant output with MB - Megabytes .

# free -m total used free shared buffers cached
Mem: 32099 24838 7261 0 402 22814
-/+ buffers/cache: 1621 30477
Swap: 3999 0 3999

How to check, how much free ram I really haveFrom the above output based on used & free column, you may think, you have very low free memory, when it’s really just 10% , How ?

Total Actual Available RAM = (Total RAM column2 used)

Total RAM = 32099

Actual used RAM = -1621

Total actual available RAM = 30477

If you have latest distribution, you have a option to see the actual free memory called available , for older distribution, look at the free column in the row that says -/+ buffers/cache .

How to check, how much RAM actually usedFrom the above output based on used & free column, you may think, you have utilized morethan 95% memory.

Total Actual used RAM = column1 used (column1 buffers + column1 cached)

Used RAM = 24838

Used Buffers = 402

Used Cache = 22814

Total Actual used RAM = 1621

Display Memory in GB

By default free command output display memory in KB - Kilobytes which is bit confusion to most of the administrator, so we can use the above option to get the output in MB - Megabytes but when the server has huge memory (morethan 100 GB or 200 GB), the above option also get confuse, so in this situation, we can add -g option with free command to get instant output with GB - Gigabytes .

# free -g total used free shared buffers cached
Mem: 31 24 7 0 0 22
-/+ buffers/cache: 1 29
Swap: 3 0 3 Display Total Memory Line

By default free command output comes with three columns (Memory, Buffers/Cache & Swap). To display consolidated total in separate line (Total (Mem+Swap), Used (Mem+(Used Buffers/Cache)+Swap) & Free (Mem+(Used Buffers/Cache)+Swap), add -t option with free command.

# free total used free shared buffers cached
Mem: 32869744 25434276 7435468 0 412032 23361716
-/+ buffers/cache: 1660528 31209216
Swap: 4095992 0 4095992
Total: 36965736 27094804 42740676 Run free with delay for better statistic

By default free command display single statistics output which is not enough to troubleshoot further so, add delay (delay is the delay between updates in seconds) which capture the activity periodically. If you want to run free with 2 second delay, just use the below command (If you want more delay you can change as per your wish).

The following command will run every 2 seconds until you exit.

# free -s 2 total used free shared buffers cached
Mem: 32849392 25935844 6913548 188 182424 24632796
-/+ buffers/cache: 1120624 31728768
Swap: 20970492 0 20970492 total used free shared buffers cached
Mem: 32849392 25935288 6914104 188 182424 24632796
-/+ buffers/cache: 1120068 31729324
Swap: 20970492 0 20970492 total used free shared buffers cached
Mem: 32849392 25934968 6914424 188 182424 24632796
-/+ buffers/cache: 1119748 31729644
Swap: 20970492 0 20970492 Run free with delay & counts

Alternatively you can run free command with delay and specific counts, once it reach the given counts then exit automatically.

The following command will run every 2 seconds with 5 counts then exit automatically.

# free -s 2 -c 5 total used free shared buffers cached
Mem: 32849392 25931052 6918340 188 182424 24632796
-/+ buffers/cache: 1115832 31733560
Swap: 20970492 0 20970492 total used free shared buffers cached
Mem: 32849392 25931192 6918200 188 182424 24632796
-/+ buffers/cache: 1115972 31733420
Swap: 20970492 0 20970492 total used free shared buffers cached
Mem: 32849392 25931348 6918044 188 182424 24632796
-/+ buffers/cache: 1116128 31733264
Swap: 20970492 0 20970492 total used free shared buffers cached
Mem: 32849392 25931316 6918076 188 182424 24632796
-/+ buffers/cache: 1116096 31733296
Swap: 20970492 0 20970492 total used free shared buffers cached
Mem: 32849392 25931308 6918084 188 182424 24632796
-/+ buffers/cache: 1116088 31733304
Swap: 20970492 0 20970492 Split Buffers & Cached memory output

By default Buffers/Cached memory output comes together. To split Buffers & Cached memory output, add -w option with free command.

# free -w Show Low and High Memory Statistics

By default free command output comes without Low and High Memory Statistics. To display Show Low and High Memory Statistics, add -l option with free command.

# free -l total used free shared buffers cached
Mem: 32849392 25931336 6918056 188 182424 24632808
Low: 32849392 25931336 6918056
High: 0 0 0
-/+ buffers/cache: 1116104 31733288
Swap: 20970492 0 20970492 Read more about free

If you want to know more option which is available for free, simply navigate to man page.

# free --help
or
# man free

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: Linux
分页:12
转载请注明
本文标题:free A Standard Command to Check Memory Usage Statistics (Free & Used) ...
本站链接:http://www.codesec.net/view/531096.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(34)