Thank you Rik, u saved me from getting one more white hair.....:-). On Sat, Jun 14, 2008 at 11:30 AM, Rik van Riel <riel@xxxxxxxxxxx> wrote: > On Sat, 14 Jun 2008 10:51:19 +0800 > "Peter Teoh" <htmldeveloper@xxxxxxxxx> wrote: > >> first, it should attempt to allocate space from physical mem...and it >> uses max_pfn as the mark to guide it. > > No. > >> On the other hand, because i cannot find the link between max_pfn and >> __get_free_pages() - so question is how does __get_free_pages() know >> where the max pfn it can used for memory allocation? > > You read correctly, __get_free_pages() has absolutely nothing to > do with max_pfn. > >> next, it should then update the pagetable entries - right?\ > > No, __get_free_pages() never manipulates page tables. > >> essentially...it should be marking the pagetable entries for the block >> of memory as "notfree" - right? what is the function used? thanks. > > This info is not kept in page tables, but in the array > struct page mem_map[]. > > Take a look at the functions that __get_free_pages() calls: > > alloc_pages() > -> alloc_pages_node() > -> __alloc_pages() > -> __alloc_pages_internal() > -> get_page_from_freelist() > -> buffered_rmqueue() > -> rmqueue_bulk() > -> __rmqueue() > -> __rmqueue_smallest() > > As you can see, each zone has a number of free lists, for each > allocation order: > > /* Find a page of the appropriate size in the preferred list */ > for (current_order = order; current_order < MAX_ORDER; ++current_order) { > area = &(zone->free_area[current_order]); > if (list_empty(&area->free_list[migratetype])) > continue; > > page = list_entry(area->free_list[migratetype].next, > struct page, lru); Yes....as I read the code now I get better understanding. Thanks for the lead. But now I have to shift the entire question to another area again. Original intent was understanding how the pagetable got updated. So, as u implied, it is not done at mem allocation time, but when the zone-based free list is constructed - for each order - right? I have traced a few functions that are involved when constructing the area->free_list (quoted from your extract above): free_area_init() free_area_init_node() free_area_init_core() init_currently_empty_zones(), memmap_init() zone_init_free_lists() And the one specifically involved in pagetable update is memmap_init(): void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, unsigned long start_pfn, enum memmap_context context) { struct page *page; unsigned long end_pfn = start_pfn + size; unsigned long pfn; struct zone *z; z = &NODE_DATA(nid)->node_zones[zone]; for (pfn = start_pfn; pfn < end_pfn; pfn++) { But this node_zones-->is not the pagetable? How is it linked to the pagetable? thanks. -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ