OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 4:14 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 66 posts ]  Go to page Previous  1, 2, 3, 4, 5
Author Message
 Post subject: Re: GRUB Returning Less Memory
PostPosted: Mon Aug 14, 2017 2:21 am 
Offline
Member
Member

Joined: Sun Mar 01, 2015 7:58 am
Posts: 51
Octacone wrote:
TheLittleWho wrote:
Then you must be doing something wrong. I managed to count 127 MB (0x7F9DC00 bytes) of free RAM from the image you provided.

0x7F9DC00 means 127 MiBs and few KiBs, but I have 128 MiBs...


Top
 Profile  
 
 Post subject: Re: GRUB Returning Less Memory
PostPosted: Mon Aug 14, 2017 4:17 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
TheLittleWho wrote:
Octacone wrote:
TheLittleWho wrote:
Then you must be doing something wrong. I managed to count 127 MB (0x7F9DC00 bytes) of free RAM from the image you provided.

0x7F9DC00 means 127 MiBs and few KiBs, but I have 128 MiBs...


Octacone wrote:
Basically what I've done is summed up all the lengths (note they are 64 bit wide) that are marked as free. Only count those free ones or else you'll register more RAM than physically available.


Read that again, slowly. I also mentioned something about ACPI reclaimable space. That should give you those extra few kilobytes, but first make sure to reclaim that space and use the data from it accordingly.
Also when printing out those values, printing them in bytes is the most accurate way, everything else is kind of not precise (4 GB instead of 4.2). See the decimal point? Floating point printing is handy for that type of stuff.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: GRUB Returning Less Memory
PostPosted: Mon Aug 14, 2017 4:54 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
TheLittleWho wrote:
Octacone wrote:
TheLittleWho wrote:
Then you must be doing something wrong. I managed to count 127 MB (0x7F9DC00 bytes) of free RAM from the image you provided.

0x7F9DC00 means 127 MiBs and few KiBs, but I have 128 MiBs...


In general there's two different numbers, the amount of RAM installed and the amount available for your OS. If you want to know how much RAM is installed then you might want to take a look at SMBios. If you want to know the address and availability of memory then you use the memory map provided to you.

For instance if you have an integrated GPU then it might take a piece of the RAM and that piece won't be available for your OS as such. The firmware (BIOS/UEFI) might/will also take some memory for itself, some of the ACPI memory is reclaimable after you're done with it, some might not be. So simply put, the memory you should ever use for allocation is the memory in the mmap. The SMBios stuff for installed memory is likely more useful for "accounting" purposes, for instance large organizations like to be able to automatically detect what hardware they have.


Top
 Profile  
 
 Post subject: Re: GRUB Returning Less Memory
PostPosted: Mon Aug 14, 2017 4:58 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
Octacone wrote:
64 GB = 64 * 1024 MB = 64 * 1024 * 1024 KB = 64 * 1024 * 1024 * 1024 Bytes = 68719476736 Bytes conatined in 64 GB of RAM.
We don't want to store 68719476736 different addresses, we want to store blocks of memory (4 KB chunks).
4 KB = 4096 Bytes --> 68719476736 / 4096 = 16777216 Bytes/Addresses to store.
Now since we are using a bitmap there are 32 bits inside a single uint32_t, so we need to divide 16777216 by 32 = 524288 addresses to store in total.
524288 addresses = 524288 different variables = each one of them being 4 bytes so 524288 * 4 = 2097152 bytes in total to store them = exactly 2 MB.
Wow! I was missing the last line... =D> Good catch.

Well, I wouldn't say you missed the last line, instead I'd drop the use of uint32_t in the math (though not necessarily in code). You need the 16 mega _bits_, and since each byte is 8 bits that means 16/8 = 2 MiB. By using uint32_t you end up with a number that is 1/4 of what it should be, then you multiply it with 4 to get the correct result, just redundant to essentially divide and multiply by the same number in a sense..

But anyway, as said, my main point was that for a full 64-bit PAS you'd waste a lot of memory, unless you record the base address, so you don't need a full bitmap for the entire 64-bit PAS, given that no hardware even supports the full 64-bit PAS, AFAIK.


Top
 Profile  
 
 Post subject: Re: GRUB Returning Less Memory
PostPosted: Mon Aug 14, 2017 5:39 am 
Offline
Member
Member

Joined: Sun Mar 01, 2015 7:58 am
Posts: 51
Thank you! I will read about SMBios, but that structure is on bios legacy and uefi or?


Top
 Profile  
 
 Post subject: Re: GRUB Returning Less Memory
PostPosted: Mon Aug 14, 2017 6:36 am 
Offline
Member
Member

Joined: Thu Aug 13, 2015 4:57 pm
Posts: 384
TheLittleWho wrote:
Thank you! I will read about SMBios, but that structure is on bios legacy and uefi or?

http://wiki.osdev.org/System_Management_BIOS

I haven't actually used SMBIOS myself (except on Linux/BSD type systems, but that's not my code), but I think it should be available on UEFI as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 66 posts ]  Go to page Previous  1, 2, 3, 4, 5

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 117 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group