I'm writing a kernel module that works with page table entries, in order to implement a new page replacement policy. I want to get a list of page table entries owned by a specific process. So far I have retrieved a linked list of vma
structures which basically carry information about pages owned by a process. There is a function called walk_page_vma
which takes the pointer to the vma
and gives back the page tables, it has been defined in mm/pagewalk.c
also declared in linux/mm.h
. Therefore, I have included linux/mm.h
in my code.
process_pid = -1;
struct task_struct* task_list;
size_t process_counter = 0;
for_each_process(task_list) {
if (strcmp(task_list->comm, process_name) == 0){
process_pid = task_list->pid;
pr_info("found %s pid = %d \n", process_name, process_pid);
struct vm_area_struct *mmap = task_list->mm->mmap;
while(mmap != NULL){
struct mm_walk walk;
int res = walk_page_vma(mmap, &walk);
if (res == 0) {
printk("walked successfully\n");
} else {
printk("failed to walk!\n");
}
mmap = mmap->vm_next;
}
// break;
}
// pr_info("== %s [%d]\n", task_list->comm, task_list->pid);
++process_counter;
}
if (process_pid){
// pr_info("found %s pid = %d \n", process_name, process_pid);
} else {
pr_info("couldn't find %s pid. exiting! \n", process_name);
}
// printk(KERN_INFO "== Number of process: %zu\n", process_counter);
At building time, it throws a warning saying
WARNING: "walk_page_vma" [/home/myusername/Projects/ProjectModule/my_module.ko] undefined!
and is unable to load it when calling insmode
.