CS401/CS746
(Linux) Kernel Programming
Spring 2016
Exercise #5
The aim of this exercise is to get familiar with the virtual memory based memory management, the page table layout and the process address space kernel state. The kernel state variables are: task_struct and mm_struct
Some references
- Understanding the Linux Virtual Memory Manager, Mel Gorman (book)
- memory-faq
- sched.h
- mm_types.h
- page table management
- process address space
- memory areas
- Browse the ../include directory and locate the definition of the two structures task_struct and mm_struct
- Understand the various roles and purpose for important variables in
the mm_struct
Look up vm_area_struct and its members, udnerstand how vm_areas are chained, how per vm_area protection and permission bits/flags are set.
Understand how the 12-bits available in each pte are used as flag bits
Understand the following kernel macros, variables, #defines and functions:
pte_t, pmd_t, pgd_t,
PGDIR_SHIFT, PAGE_OFFSET, PAGE_SHIFT, PMD_SHIFT
pte_page(), pte_dirty(), pte_write(), pte_free ...
Lookup and understand the structure struct page - Write a module which takes as input a process pid and,
- Extracts the corresponding task_struct for the pid.
- Print information from the task_struct to confirm that the pid is of the correct process.
- Print the process hierarchy for process with given pid. Meaning print a sequence of parent processes based on the given process and their information.
- Write a module which takes as input a process pid and,
- Prints the virtual memory areas for that process. Print output similar to that in /proc/$PID/maps or similar to that of the pmap $PID command.
- Display above (some of the above) information for all processes in the system and demonstrate correctness.
Submit a step-by-step ordered process in which the above is achieved.
A in-class demo is required.