Free

From DikapediaV2
Revision as of 00:16, 27 August 2024 by Ardika Sulistija (talk | contribs) (Created page with "<b>free</b> - Display amount of free and used memory in the system, as well as the buffer used by the kernel, and the used physical and swap memory. It 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 <b>/proc/meminfo</b>. * <b>total</b> - Total installed memory (MemTotal and SwapTotal in /proc/meminfo) * <b>used</b> - Used memory (calculat...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

free - Display amount of free and used memory in the system, as well as the buffer used by the kernel, and the used physical and swap memory.


It 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.

  • total - Total installed memory (MemTotal and SwapTotal in /proc/meminfo)
  • used - Used memory (calculated as total - free - buffers - cache)
  • free - Unused memory (MemFree and SwapFree in /proc/meminfo)
  • shared - Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, available on kernels 2.6.32, displayed as zero if not available)
  • buffers - Memory used by kernel buffers (Buffers in /proc/meminfo. "Buffers" represent how much portion of RAM is dedicated to cache disk blocks.
  • cache - Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo). "Cached" is similar like "Buffers", only this time it caches pages from file reading.
  • buff/cache - Sum of buffers and cache
  • available - Estimation of how much memory is available for starting new applications, without swapping.
    • Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)


How to use free



Some common ‘free’ command options:
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times


Examples:

$ free
              total        used        free      shared  buff/cache   available
Mem:         984180      494120      240972         716      249088      349920
Swap:             0           0           0 

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           961M        482M        235M        716K        243M        341M
Swap:            0B          0B          0B

$ free -m
              total        used        free      shared  buff/cache   available
Mem:            961         483         234           0         243         340
Swap:             0           0           0 

$ free -k
              total        used        free      shared  buff/cache   available
Mem:         984180      493416      241592         716      249172      350624
Swap:             0           0           0 


# Display a line containing the total memory in MB
$ free -t -h
              total        used        free      shared  buff/cache   available
Mem:           961M        479M        237M        716K        243M        344M
Swap:            0B          0B          0B
Total:         961M        479M        237M


/proc/meminfo



/proc/meminfo stores statistics about memory usage on the Linux system. The same file is used by free and other utilities to report the amount of free and used memory (physical and swap) on the system, as well as the shared memory and buffers used by the kernel.

$ less /proc/meminfo
$ more /proc/meminfo
$ egrep --color 'Mem|Cache|Swap' /proc/meminfo
$ cat /proc/meminfo
MemTotal:         984180 kB
MemFree:          248040 kB
MemAvailable:     357272 kB
Buffers:               0 kB
Cached:           214256 kB
SwapCached:            0 kB
Active:           485564 kB
Inactive:         128240 kB
Active(anon):     394264 kB
Inactive(anon):      376 kB
Active(file):      91300 kB
Inactive(file):   127864 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
.
.
.
.
[Long output]
$ egrep --color 'Mem|Cache|Swap' /proc/meminfo
MemTotal:         984180 kB
MemFree:          248396 kB
MemAvailable:     357836 kB
Cached:           214464 kB
SwapCached:            0 kB
SwapTotal:             0 kB
SwapFree:              0 kB





References: