Is the memory map static?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
mrjbom
Member
Member
Posts: 301
Joined: Sun Jul 21, 2019 7:34 am

Is the memory map static?

Post by mrjbom »

Hi.
I use the memory map obtained from GRUB.
I write the free memory areas to my table. I'm wondering if these addresses and the sizes of these areas can change as the computer works. Do I need to update my previously obtained memory area data?

I think not, but it's better to know for sure.
nexos
Member
Member
Posts: 1078
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Is the memory map static?

Post by nexos »

No, because that would be very hard to do right and to know when to re-obtain the map. As far as my knowledge goes, no.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
User avatar
mrjbom
Member
Member
Posts: 301
Joined: Sun Jul 21, 2019 7:34 am

Re: Is the memory map static?

Post by mrjbom »

nexos wrote:No, because that would be very hard to do right and to know when to re-obtain the map. As far as my knowledge goes, no.
What should I do in this case? How do I track its changes? When should I update my data?
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Is the memory map static?

Post by iansjack »

Not sure what you mean. Free memory only changes as you allocate pages; it's the reponsibility of the OS to keep track of which pages it has allocated (and therefore which are still free).
User avatar
mrjbom
Member
Member
Posts: 301
Joined: Sun Jul 21, 2019 7:34 am

Re: Is the memory map static?

Post by mrjbom »

iansjack wrote:Not sure what you mean. Free memory only changes as you allocate pages; it's the reponsibility of the OS to keep track of which pages it has allocated (and therefore which are still free).
I mean, can the memory map to change myself.
Can the data about RAM partitions received from grub change by itself? Or do they not change?
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Is the memory map static?

Post by iansjack »

Why would they change?
User avatar
eekee
Member
Member
Posts: 872
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: Is the memory map static?

Post by eekee »

There is such a thing as hot-pluggable RAM, but I think very few of us here have to worry about that particular craziness. Ditto hot-pluggable PCI. We don't have supercomputers.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
User avatar
mrjbom
Member
Member
Posts: 301
Joined: Sun Jul 21, 2019 7:34 am

Re: Is the memory map static?

Post by mrjbom »

Okay, thanks, I thought so. I just wanted to clarify.
Thanks.
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Is the memory map static?

Post by Octocontrabass »

Hot-pluggable RAM and CPUs are very popular in enterprise virtual machines, where there's a pretty high demand for being able to scale resources up or down while the OS and applications are running.

PCI hotplug is working its way into consumer electronics in the form of Thunderbolt and SD Express.
User avatar
eekee
Member
Member
Posts: 872
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: Is the memory map static?

Post by eekee »

Ah, thanks Octocontrabass. Well, I'm sure beginner OS devs are not expected to support hot-pluggable RAM. :) Interesting that Thunderbolt is so closely related to PCIe; it might be easy to support. I'm not so sure about the other parts of it, though.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

Re: Is the memory map static?

Post by ITchimp »

I am looking for the definition fille (.h) for struct mboot or struct mboot_header...do you know where to get it?
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Is the memory map static?

Post by Octocontrabass »

They can also be found in the Multiboot and Multiboot2 specifications.

The Multiboot specifications don't use the names "mboot" or "mboot_header" so that probably came from someone else's implementation of the header. (You can write your own header based on the spec instead of using the one in the spec.)
User avatar
bellezzasolo
Member
Member
Posts: 110
Joined: Sun Feb 20, 2011 2:01 pm

Re: Is the memory map static?

Post by bellezzasolo »

Not in GRUB, but it's worth noting that something like this sort of is possible in UEFI.
It doesn't happen automagically, though. Calls to Boot Services can result in changes to the memory map.

When you call GetMemoryMap, UEFI gives you a mapKey.
When you call ExitBootServices, you need to pass that same mapKey, and an error will be returned if it has changed in the interim!
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Is the memory map static?

Post by bzt »

bellezzasolo wrote:Not in GRUB, but it's worth noting that something like this sort of is possible in UEFI.
It doesn't happen automagically, though. Calls to Boot Services can result in changes to the memory map.

When you call GetMemoryMap, UEFI gives you a mapKey.
When you call ExitBootServices, you need to pass that same mapKey, and an error will be returned if it has changed in the interim!
EFI applications and drivers can allocate and free memory which changes the map. Calling ExitBootServices guarantees that all further memory allocation calls will result in an error code. Therefore RunTime Services must operate on static memory (allocated at initialization stage), and BootTime Services are not accessible at all after ExitBootServices call.

For BIOS, this can't happen as BIOS doesn't have memory allocation functions, so BIOS code can't allocate memory to change the map. E820 will remain static (this is what GRUB returns for you).

Cheers,
bzt
Post Reply