LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-20-2018, 12:41 PM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
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.

Last edited by vincix; 08-20-2018 at 12:46 PM.
 
Old 08-20-2018, 01:15 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
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.
 
Old 08-20-2018, 01:26 PM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member response

Hi,

Maybe you can look at this to help you understand; https://simple.wikipedia.org/wiki/Mebibyte

Hope this helps.
Have fun & enjoy!
 
1 members found this post helpful.
Old 08-20-2018, 02:41 PM   #4
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
@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.

Thanks in advance.

[later edit:]
http://extraconversion.com/data-stor...-to-bytes.html
Please look at the screenshot. It follows that the value of free -m --si doesn't make any sense! The value should be 3153, not 3079!
Attached Thumbnails
Click image for larger version

Name:	bytes megabytes.png
Views:	14
Size:	99.6 KB
ID:	28429  

Last edited by vincix; 08-20-2018 at 02:51 PM.
 
Old 08-20-2018, 04:31 PM   #5
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
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...
 
Old 08-20-2018, 05:52 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by vincix View Post
@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⟩
 
Old 08-21-2018, 06:30 AM   #7
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to sum bytes, kilobytes, megabytes and gigabytes using awk command roopakl Linux - Newbie 8 11-30-2012 12:02 PM
[SOLVED] Unable to attach a C file of 32.8 kilobytes Aquarius_Girl LQ Suggestions & Feedback 28 05-06-2010 02:17 AM
meaning of dd if=/dev/zero of=abc bs=1024 count=1000 atikna2001 Programming 2 03-11-2009 12:48 PM
Upload AND download limit to 100 kilobytes / sec +Yan Linux - Networking 2 03-01-2007 04:57 AM
Kilobytes vs block dvong3 Linux - Newbie 5 07-17-2003 04:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration