Linux – free command output: gentoo (redhat?) vs debian

command linelinuxmemoryUtilities

I noticed there is a difference between outputs of free command:

On debian:

$ free -h
             total       used       free     shared    buffers     cached
Mem:          4.0G       3.4G       629M         0B        96K       1.3G
-/+ buffers/cache:       2.1G       2.0G
Swap:         4.0G       1.1G       2.9G

On gentoo:

$ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        3.7G        9.6G        485M        2.2G         11G
Swap:          8.8G        2.6G        6.2G

Redhat (at least 7.x) seems to have same output as gentoo. Why is that? Is it possible to display debian style output on gentoo / redhat systems as well? Are both distros using different gnu coreutils?

Best Answer

free is provided by procps-ng; Debian 8 has version 3.3.9, which uses the old style with a separate line for buffers/cache, while Gentoo and presumably RHEL 7.x have version 3.3.10 or later which uses the new style. You can see the reasoning behind the change in the corresponding commit message.

If you really want the old-style output you can run an older version of procps, but you'll find that distributions will migrate to the newer style by default. The newer style also gives the amount of available memory which is a really useful piece of information (see How can I get the amount of available memory portably across distributions? for details).

Somewhat confusingly, version 3.3.9 refers to the format without the buffers/cache line as "old format", and you can see it in that version with free -o. So all told:

  • versions 3.3.9 and earlier show by default

                 total       used       free     shared    buffers     cached
    Mem:           31G        30G       539M       1.1G       2.2G        15G
    -/+ buffers/cache:        13G        18G
    Swap:          31G       180M        31G
    
  • versions 3.3.9 and earlier, with -o, show

                 total       used       free     shared    buffers     cached
    Mem:           31G        30G       549M       1.1G       2.2G        15G
    Swap:          31G       180M        31G
    
  • versions 3.3.10 and later only show

                  total        used        free      shared  buff/cache   available
    Mem:            31G        7.8G        525M        1.1G         23G         22G
    Swap:           31G        180M         31G
    
  • versions 3.3.10 and later also have a wide output mode, -w, which shows

                  total        used        free      shared     buffers       cache   available
    Mem:            31G        7.8G        531M        1.1G        2.2G         20G         22G
    Swap:           31G        180M         31G
    

(This is all on the same system; note how the accounting is more accurate with the later versions.)

Related Question