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][1]
* [vmstat – A Standard Nifty Tool to Report Virtual Memory Statistics][2]
#### 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 -t
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.
To print the human readable output, add`h`option with`free`command, which will print more detailed output compare with other options likem & g.
```
# free -h
total used free shared buff/cache available
Mem: 2.0G 1.6G 138M 20M 188M 161M
Swap: 2.0G 1.8G 249M
```
#### 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. (This option is available on version 3.3.12).
Note :See the above output,`Buffers/Cached`comes together.
```
# free -wh
total used free shared buffers cache available
Mem: 2.0G 1.6G 137M 20M 8.1M 183M 163M
Swap: 2.0G 1.8G 249M
```
#### 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.