When booting the Linux kernel, it is possible to load an initramfs archive and a DTB file in RAM and specify those physical addresses to the kernel. For example, using U-Boot, you could do:
bootz 0x80008000 0x82000000 0x81000000
which means: boot kernel image located at memory address 0x80008000, and specify to kernel the initramfs archive is at 0x82000000 and the DTB file is at 0x81000000. In this example, it's an ARM system, but my question applies to all systems.
When those three files are loaded into RAM, the RAM might look like this:
[...kkkkk..........iii.............dd............................... ... ..]
where k
means kernel, i
initramfs, d
DTB and .
unused space.
The initramfs archive is extracted into a ramfs, which needs to allocate memory pages to exist. The DTB file is used to populate an internal tree, which also allocates pages for its data structure.
How does the kernel avoid overwriting the initramfs and DTB files in memory while allocating pages? Are the physical pages taken by those files mapped and marked as used before eventually being freed when the original data is not needed anymore?