4

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?

Petr
  • 1,711
  • It depends on the kernel version. All distributions will move towards the output you see on Gentoo as the kernel is updated. See the answer in the duplicate (which was written by a Debian Developer). – terdon Apr 07 '16 at 13:38
  • free comes in procps not coreutils (at least on redhat/centos/fedora); from your output, it seems debian runs by default as free -o (disables the display of a "buffer adjusted" line), check if you have any aliases defined. – guido Apr 07 '16 at 13:41
  • @terdon I am not sure the question you linked is a duplicate.This one is just about the additional "buffer adjusted" line, has been available on redhat for a long time (certainly before 3.x kernels) – guido Apr 07 '16 at 13:42
  • @terdon I don't think the question is a duplicate – I answered yours as looking for the available memory, whereas I understand this one as being concerned with the variations in output between procps 3.3.9 and 3.3.10, in particular the -/+ buffers/cache line which was removed in 3.3.10. Running 3.3.9 on a new kernel will produce the old-style output. – Stephen Kitt Apr 07 '16 at 13:42
  • @StephenKitt I assumed the removal of the buffers/cache line was because the addition of the "available" field renders it useless. OK, I'll reopen it then. – terdon Apr 07 '16 at 13:44
  • @guido fair enough, see above. But no, it's not the -o option, look at the "available" field. I have the same output on Arch and no -o option available. – terdon Apr 07 '16 at 13:44
  • @terdon your assumption is correct, but that wasn't explained in the other answer (and isn't especially obvious IMO). – Stephen Kitt Apr 07 '16 at 14:05

1 Answers1

6

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

Stephen Kitt
  • 434,908
  • Well the available column might be interesting, but to me it was more interesting to see how much memory is actually being used - buffers/caches. Which is pretty much total_memory - available memory. This was shown by older versions and was really very nice to see... This new version just does it the other way. – Petr Apr 07 '16 at 21:58
  • Hmm, although it looks that that is actually what used refers to in this version, unlike older version where used was all used memory including the buffers etc. So maybe I was wrong. It's really confusing change :/ especially for someone who was used to old format for many years... – Petr Apr 07 '16 at 22:00
  • The formats were changed because the way memory is handled or portioned out has changed. In the old days taking the used field and adjusting for buffers and cache was good enough to get a "true" value for used and working out what really was free.

    Those days are gone and just using that simple method will give you the wrong result. That's why the format changed.

    – Craig Small May 14 '16 at 23:41