0

I'm monitoring my RAM on a CentOS 6 server and when I free -h I see 15G available which is OK but when I free -b I see 1641154969 bytes which equals 1,641154969G.


free -h
             total       used       free     shared    buffers     cached
Mem:           15G       3.0G        12G       1.7M        39M       671M
-/+ buffers/cache:       2.3G        12G 
Swap:         7.7G         0B       7.7G 

free -b
             total       used       free     shared    buffers     cached
Mem:    1641154969 3238035456 1317351424    1781760   41451520  704331776
-/+ buffers/cache: 2492252160 1391929753 
Swap:   8279552000          0 8279552000 
4

Old versions of free, such as that used in CentOS 6, only display ten digits at most for each value. The “1641154969” displayed is missing its last digit. This was fixed by version 3.3.10; free now displays up to eleven digits, which is enough for up to one exbibyte of memory. (I haven’t checked, but the changes in version 3.3.0, if not earlier, might have addressed this too.)

The discrepancy between 16 billion bytes and the displayed “15G” is explained by the fact that scaling here is done in powers of two; 16411549690 divided by 1024×1024×1024 is 15.284, which is displayed as 15. Current versions of free add i to the unit to make it clear they’re using binary prefixes.

0

This question is conflating two separate classes of byte units, namely decimal Gigabytes and binary Gibibytes:

   Prefixes for multiples of
   bits (bit) or bytes (B)
   Decimal              Binary
   Value        SI      Value       IEC
   1000   10^3  k kilo  1024   2^10 Ki kibi
   1000^2 10^6  M mega  1024^2 2^20 Mi mebi
   1000^3 10^9  G giga  1024^3 2^30 Gi gibi

The free -h command prints gibibytes, whereas free -b prints bytes. Doing the math, (first suffixing a 0 to the byte count to compensate for the free bug noted in Stephen Kitt's answer):

echo $(( 16411549690 / (10**9) ))  # gigabytes
echo $(( 16411549690 / (2**30) ))  # gibibytes

Outputs:

16
15

Hard drive vendors used to exploit this common confusion, and one vendor even wound up on the losing end of a class action lawsuit. See Orin Safier v. Western Digital Corporation, in which annoyed purchasers were in 2006 awarded $30 worth of backup software, not actual money, each for their troubles.

  • Being awarded $30 in backup software seems even more annoying than the initial grievance. – agc Jul 10 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.