views:

202

answers:

2

In the Linux kernel, given the task_struct's mm I can access the process's list of vm_area_structs. Given these vm_area_structs, how do I get the struct pages which actually correspond to this vma?

I tried looking for functions in mm/memory.c and the like, but I was at a loss.

Edit: the idea is to find which pages in the vma are currently in memory and which are not. But I don't want someone telling me how to do this bit, as that's a small part of a homework assignment that I need to figure out on my own. But I can't seem to figure out how to find the pages that correspond to this vma. If I can find the pages, I figure I can check to see if they have a valid pfn or not.

+1  A: 

From your comment to another answer (edit: the other answer seems to have been deleted), it seems you want to read from user space. The function to get the user space pages would be get_user_pages(), but that is most probably not what you want; you probably want copy_from_user/copy_to_user.

CesarB
I believe get_user_pages() generates a page fault whenever it finds a page not present in physical memory. But I think follow_page() might do the trick. Let me check.
FreeMemory
It is supposed to, after all you should not have to worry whether the page is present or not. What exactly do you want to do?
CesarB
Yeah that's what i've got wrong too before. the vm area is there, but the page isn't there always :)
Johannes Schaub - litb
I just want to know which pages in the vma are present and which are not. In that case, could I loop from vm_start to vm_end in the vma, incrementing by PAGE_SIZE and do a follow_page on each address? If follow_page is NULL, the page is not present, else it is?
FreeMemory
A: 

I don't have the direct answer off-hand, but it won't take you long to navigate the structures by using lxr.linux.no

Given you already have the struct you want to start from, take a look from http://lxr.linux.no/linux+v2.6.29/+code=vm_area_struct. You can look for definitions, see where a single struct is used, etc... If you already know the final struct name you are looking for, you can go in reverse and navigate up until you reach the mm.

Note that if your net connection is not so good, you may want to install a local copy of the indexed source by getting the lxr packages of your distro and generating the index locally. It used to take 2 hours on a 400mhz / 128mb machine, nowadays it should go much much much faster.

winden