Free command provides us valuable information of available RAM in Linux/Unix machine. Linux free command gives information about total used and available space of physical memory and swap memory with buffers which is used by kernel in Linux/Unix system.
Many new Linux users and admins confused of Linux free command output. In this article I will explain its output and show you actual free memory on the system.
Free Command Examples
Memory Details In Linux Machine
Follow the below command to check the memory details in Linux/Unix system:
# free total used free shared buffers cached Mem: 12187608 5452200 6735408 0 94860 1109312 -/+ buffers/cache: 4248028 7939580 Swap: 2097144 1106964 990180
Line 1 : Shows the memory details such as total available memory, used memory, shared memory, memory used for buffer, memory used for caching.
Line 2 : Shows total buffers/cache used and free.
Line 3 : Shows total swap memory available, used swap and free swap memory.
For better understanding let us dig more into these lines.
Mem: 12187608 5452200 6735408 0 94860 1109312
12187608 : Display physical/memory available for your system. Output is in KBs.
5452200 : Display memory used by system. Include buffers and cached data size as well.
6735408 : Display total free memory and available for new process to execute.
0 : Display shared memory.
94860 : Display total memory buffered by different application on the system.
1109312 : Display total memory used for caching of data for future uses.
-/+ buffers/cache: 4248028 7939580
4248028 : This is actual size of used RAM which we get from RAM used -(buffers + cache).
Used RAM = +5452200
Used Buffers = -94860
Used Cache = -1109312
Actual Total Used Memory is 5452200 -(94860+1109312) = 4248028
So, why free Linux system is displaying 5452200 as used memory, because Linux counts cached memory, buffered memory to this used memory. In future any application want to use these buffer/cache then Linux will make it free.
7939580 : Display actual total memory available, got this number by subtracting actual memory used from total memory available on the system.
Total RAM = +12187608
Actual used RAM = -4248028
Total actual available RAM = 7939580
Swap: 2097144 1106964 990180
Above line display the swap details such as total swap size, used and free swap. Swap is virtual memory exist on HDD to increase virtual memory size.
What Is The Difference Between Buffers And Cache?
Buffers is used to store data for a particular application for temporarily and this data is not used by any other application. Similar work like bandwidth if try to send burst of data through network, and network card is unable to send this data and capable to send less data it will keep these hugs amounts of data in buffer so that it can send data constantly in lesser speeds. Similarly cache is a memory location to store frequently used data for faster access. Another difference between a buffer and cache is that cache can be used multiple times and buffer is used single time, both are used to temporary data storage for processing.