[SOLVED] megabytes in free is not kilobytes/1000 but kilobytes/1024
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
megabytes in free is not kilobytes/1000 but kilobytes/1024
on Centos (ubuntu/debian's version has a different syntax when distinguishing between kilo and kibi and so on):
Code:
free -b
total used free shared buff/cache available
Mem: 3153575936 2029826048 309317632 19070976 814432256 886857728
And the number of kilobytes is the number I'm expecting:
Code:
free -k --si
total used free shared buff/cache available
Mem: 3153575 2039660 299229 19070 814686 876961
It's simply divided by 1000.
But when I run:
Code:
free -m --si
I get:
Code:
total used free shared buff/cache available
Mem: 3079 1991 291 18 795 856
Which is actually the result of 3153575/1024, instead of 3153575/1000. And I don't understand why, if I'm using the same power of 1000.
On the other hand, the kibi/mebi notation (so the 1024 power) is consistent:
Code:
free -k
total used free shared buff/cache available
Mem: 3079664 1980132 303200 18624 796332 868120
free -m
total used free shared buff/cache available
Mem: 3007 1945 284 18 777 836
So 3153575936/1024 = 3079664 - that's consistent.
And 3079664/1024 equals 3007, which is also expected.
So what don't I understand exactly? I'm not sure what's going on.
Interesting. Although the man page doesn't say so, the --si option appears to only work in conjunction with the -k option
I note that it doesn't even work with no byte option specified, even tho -kilo is the default.
By definition, computer kilobytes == 1024 (2^10) and megabytes is 1000 kilobytes or 1024000, so I suppose it doesn't make sense to apply the 1000 byte divisor to megabytes, as that would misrepresent the size.
@scasey
I don't think that's correct. Bear in mind that I'm not talking about the fact that we often call a kilobyte what is actually a kibibytes and on (mega, giga, etc.)
1 kilobyte = 1000 bytes.
1 kibibyte = 1024 bytes. (2^10)
1 megabyte = 1 milion bytes, i.e. 10^6 bytes.
1 mebibyte = 1024^2 = 1048576 bytes
Quote:
Interesting. Although the man page doesn't say so, the --si option appears to only work in conjunction with the -k option
I don't agree with this sentence either, because it would follow that free -m --si and free -m are the same, which isn't true. free -m --si ends up outputting what would seem a values that shouldn't exist. If 1 megabyte is 1 milion bytes, then the correct value in megabytes should be (in my case) 3153575936 divded by 10^6! Not by 1000 and then by 1024! It doesn't make any sense... If you could address this problem directly, I'd greatly appreciate it, instead of pointing me to links that I've read and reread so many times. That's why I'm writing here, so that someone explains exactly what is going on.
Another example in fdisk -l which doesn't seem to be following the same mathematical rules as free does:
Code:
fdisk -l:
Disk /dev/mapper/centos-swap: 2164 MB, 2164260864 bytes, 4227072 sectors
So fdisk says that 1MB equals 10^6 bytes, not 10^3 * 1024 bytes. Which is to be expected. Free says otherwise. This is insanely stupid, in my opinion... Let alone the fact that on Centos they call 'megabytes' what are actually 'mebibytes' and on Ubuntu the same free tool explicitly says mebibytes (-m) and --mega actually refers to the international system, but as you've seen, it doesn't actually, as it multiplies the bytes with 10^3 * 1024...
@scasey
If you could address this problem directly, I'd greatly appreciate it, instead of pointing me to links that I've read and reread so many times. That's why I'm writing here, so that someone explains exactly what is going on.
I didn't point you to any links. I merely observed what free was doing on my desktop, which is a CentOS 7.5 installation.
I stand corrected on the behavior of free -m -si. I guess I got lost running examples.
I don't see it as a "problem" It is what it is. So I'm not going to be much help in "resolving" it.
If you think its a bug, report it. Version and reporting address from my desktop. Reporting address is at the bottom of the man page.
Code:
free -V
free from procps-ng 3.3.10
REPORTING BUGS
Please send bug reports to ⟨procps@freelists.org⟩
Sorry I got so worked up, but, as I didn't really understand what was going on and I myself was struggling to understand it, I found it annoying that I ended up with links to some basic information instead of an actual answer. Yes, I wasn't referring to you in particular, it was a general "you", but the general was that I wasn't being understood. Anyway, thanks for confirming. That's really helpful. At least I know I'm not crazy, given how easy it is (for me) to get tricked by 1024/1000 powers
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.