CS 537
Programming Assignment IV: Maintain the Reverse Page Mapping

Due:

April 21 at the start of class for people who are implementing the project as a user program; April 23 at midnight for people who are implementing the project through modifying the Linux kernel;

Contents


Description

This project is both an excercise in maintaining reverse-mapping information in the virtual memory system, and an excercise in modifying, compiling and booting the Linux kernel.

Typically, there are three uses of physical memory in the kernel: used to hold a virtual page of some process, used by the kernel to hold kernel's own data structures, and used by the kernel to cache file data, file i-nodes and file-related information (the cache is called file buffer cache).

In the Linux kernel, there is a structure called "mem_map" which is an array of "struct page". Each entry in "mem_map" corresponds to a physical page. However, Linux did not maintain information on the use of a physical page, that is, whether it is used by kernelto hold kernel data structure, or used by file buffer cache to hold file data, or used by the virtual memory system to hold a virtual page. In other words, there is no field in "struct page" that contains this information.

The assignment asks you to modify the "struct page" data structure to include two more fields: int pid, and unsigned long virtaddr. The two fields have the following semantics: if pid == -1, it means that the page is used by kernel, and virtaddr should be 0; if pid == -2, it means that the page is used by file buffer cache, and virtaddr should be 0; if pid == 0, it means that the page is free (not used for any purpose); if pid>0, then pid and virtaddr describe the virtual page that is mapped to this physical page.

The assignment asks you to find all places where the physical pages are allocated/freed and modify the code, so that the appropriate values of the two fields are set when the page is allocated, and cleared when the page is freed. Furthermore, the assignment asks to implement a routine called "dump_mem_map", which prints out the usage of the all physical pages. The print-out should print clearly whether the page is used by kernel, by file buffer cache, or by virtual memory, and in the third case, the (pid, virtaddr) of the virtual page that is mapped to the physical page.

Implementation

You can either implement the assignment as a user-program, or as a kernel modification.

Linux source code, version 2.1.54, can be found in ~cs537-2/public/project4/linux/.

Driver routines for the user-program implementation can be found in ~cs537-2/public/project4/user-program-driver/.

About Linux

There are many good online sources and books about Linux. See the emails I sent out on the subject.

Suggestions

I would not recommend you doing the kernel implementation unless you have a fair amount of programming experience, for example, have written programs that are at least 2000 lines long.

Handin

If you decide to do the user-program implementation, simply handin your code and README file and test runs.

If you decide to do the kernel implementation, handin the file "diff"s between your code and the original Linux source (preferable Linux 2.1.54 or later), and a README file. I will compile and test your code on the "crash and burn" lab.

Grading

If you decide to implement this project as a user program, the grade on this project will count for 5\% in your final grade, and the grade on Project 5 will count for 19\% in your final grade.

If you decide to implement this project through modifying the kernel, the grade on this project will count for 12\% in your final grade, and the grade on Project 5 will count for 12\% in your final grade.

Other Stuff

On Thursday, Apr 16th, I'll hold a discussion and demo session on building Linux kernel during the discussion session.


cao@cs.wisc.edu