shivank
shivank

Reputation: 77

Where are struct page* initialized in Linux?

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.

Upvotes: 2

Views: 771

Answers (2)

ajb
ajb

Reputation: 26

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();

Upvotes: 1

wxz
wxz

Reputation: 2546

You should take a look at the include/linux/gfp.h file. It has a bunch of alloc_page type functions. From there, using cscope or your favorite IDE, you can see every function that calls these functions and that will give you a sense of how the functions are used.

Upvotes: 1

Related Questions