Issue
As we know, struct page
in Linux, associated with a physical 4KB page and mapped to a pfn. This forms the backbone to memory allocation in Linux.
The struct page
is described in include\linux\mm_types.h
contains variety of information about the page. I want to know, when are struct page
allocated during boot and who initialize these struct page
structures and where (in linux)?
I was able to get some idea of where the pages are stored from this answer -https://stackoverflow.com/a/63893944/13286624 but I'm unable to find how these structures are allocated and initialized.
Solution
Maybe try mm_init
, called by start_kernel()
in /init/main.c/
and the corresponding mem_init
in /arch/x86/mm/init_64.c
:
void __init mem_init(void)
1286 {
1287 pci_iommu_alloc();
1288
1289 /* clear_bss() already clear the empty_zero_page */
1290
1291 /* this will put all memory onto the freelists */
1292 memblock_free_all();
1293 after_bootmem = 1;
1294 x86_init.hyper.init_after_bootmem();
1295
1296 /*
1297 * Must be done after boot memory is put on freelist, because here we
1298 * might set fields in deferred struct pages that have not yet been
1299 * initialized, and memblock_free_all() initializes all the reserved
1300 * deferred pages for us.
1301 */
1302 register_page_bootmem_info();
Answered By - ajb