Linux mem_map array initialization
Posted: Thu Aug 02, 2018 1:52 pm
I'm trying to figure out how Linux stores his physical page structs. Currently I am initializing an array where MAX_NR_PAGES equals the size of RAM divided by the size of a physical page frame (1GiB / 4KiB), which is a little over 250.000 in size. This is a rather lame and costly approach, so I am trying to find out how Linux manages his mem_map array.
In this file, Linux declares its pointer to the page structs array: There are some references to this variable, but I cannot seem to find out how all over 250.000 page structs are lined up there. It is a pretty cost saving approach regarding memory, since the single pointer does not use as much space as my array, but I don't know where all the other page structs for the whole physical RAM are stored.
In my approach, I am initializing a buddy allocator which assigns information to a struct page (physical address, order, ...). So to assign those informations to each of the structs, I would need to iterate over my whole 250.000 sized array. Where in Linux does this happen, or if not, how exactly does Linux initialize all page structs, especially at a point where allocation is not set up yet? (Since allocation would only work when page structs are available?)
Hope, you could enlighten me in this pretty crucial matter.
Code: Select all
struct page mem_map[MAX_NR_PAGES]
In this file, Linux declares its pointer to the page structs array:
Code: Select all
struct page *mem_map;
EXPORT_SYMBOL(mem_map);
In my approach, I am initializing a buddy allocator which assigns information to a struct page (physical address, order, ...). So to assign those informations to each of the structs, I would need to iterate over my whole 250.000 sized array. Where in Linux does this happen, or if not, how exactly does Linux initialize all page structs, especially at a point where allocation is not set up yet? (Since allocation would only work when page structs are available?)
Hope, you could enlighten me in this pretty crucial matter.