Last updated: 31 May 2021

The free utility shows the amount of free and used memory in a system. The output is similar to the memory information displayed by top.

Understanding memory usage

Memory data is often misinterpreted. The main source of confusion is related to buffers and caching. Keeping data in memory speeds things up, and the Linux kernel therefore uses as much memory as possible for caching. However, this memory can be released at any time. For instance, if a processes asks for a big chunk of memory then the kernel can simply give it some of the cached memory. So, memory used for caching is both used and available. I have described this in more detail in my article about memory data in free and top.

Let’s look at an example. The below output shows that the system has 797M of free memory. However, some of that memory is used for caching. The actual amount of available memory is therefore higher (1.1G):

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.8G        503M        797M         39M        537M        1.1G
Swap:          3.9G        899M        3.0G

The same is not true for swap memory. A swap partition (or file) never uses caching – data either is or isn’t written to the file system. So, in the case of swap the free column does reflect how much memory is free.

To summarise, free shows the following information:

  • total is the total amount of physical memory. In other words, it show how much RAM and swap the system has.
  • used is the amount of memory in use. The value doesn’t include buffered/cached memory.
  • free is the amount of unused memory. This figure is usually quite low, as unused memory is really wasted memory.
  • shared memory is the sum of memory used by tmpfs file systems. It is a very nerdy stat. You safely ignore it.
  • buff/cache is mostly used for caching. As mentioned, this memory can be made available at any time.
  • available is the total amount of memory that is actually available.

Options

By default, free displays amounts in kibibytes. You can use the -m or –g option to use mebibytes or gibibytes instead.

Another useful option is -h (--human). As the name suggests, this option makes the stats “human readable”. Columns will use mebibytes or gibibytes, depending on which unit is the easiest to interpret by humans.

And finally, the -t option adds a row with the grand totals:

$ free -ht
total used free shared buff/cache available
Mem: 1.8G 494M 767M 41M 576M 1.1G
Swap: 3.9G 897M 3.0G
Total: 5.7G 1.4G 3.8G
/pre>