COS 318 : Operating system
Fall 2002, Princeton University

Project 5: Virtual Memory

Important Dates:

Due: 11:59 PM, Tuesday, December 3

This project will require you to implement a simple virtual memory mechanism in your operating system. The processes will now each execute in a separate virtual address space. These address space will be protected from each other, so one process may not access or modify data in another address space. Additionally the kernel will also be protected from the processes in a similar manner. In this project the kernel and the kernel threads run in kernel mode (privilege level 0) and the processes are executed in user mode (privilege level 3).

Your task in this project is to implement a simple, demand-paged virtual memory system with a floppy diskette. In order to accomplish this, you will need to the following :

You should use the code available in the class webpage as a starting point for your project. We have provided you with two main components to help you with the virtual memory implementation:

There are now 33 files. Don't be daunted by the large number of files since you are already familiar with many of them, and the only file that needs to be changed is memory.c.

Since our entire project will be using the floppy drive, please do not read/modify the hard disk.


Detailed Requirements and Hints

Before starting this project, you should read carefully Chapters 2-4 of the Intel Architecture Software Developer's Manual, Volume 3: System Programming Guide to understand the address translation mechanism so that you can understand how to set up the page tables. As discussed in class, x86 architectures use a two-level table structure with a directory page that has 1024 entries pointing to the actual page tables. You need to understand this structure very well.

In this project, you can make several assumptions and constraints to simplify your design and implementation.

The floppy diskette is much smaller than the physical memory on your PC, you can assume that the physical memory for all user processes is smaller than the size of the reserved virtual memory paging space on a floppy diskette. This assumption will allow you to trigger demand paging.

You can simplify the mapping between a virtual address space and the backing store space on the floppy diskette to avoid implementing a diskette allocator. You can use the area allocated on the diskette for the image file as the backing store for each process. You can assume that processes do not use a heap for dynamic memory allocation.

You need to figure out how to initially map your physical memory page frames to run the kernel threads and how to load the code and data of a process into its address space. When the address space for the process is initialized, all the code and data pages for the process are marked as invalid. This will triggers the page_fault_handler() to run on the first access to any of these pages. At this time you can allocate a physical page frame and read in the page from the diskette.

Finally, you can assume that your virtual memory deals with only the data and code pages. All pages of the stack segments are "pinned," they will never be evicted by your page replacement mechanism. This means that you need to perform pinning when you initialize a process's address space. Also, you can assume that physical pages that are allocated to store the page-tables are pinned in memory and do not get paged.

Extra Credits

There are up to two possible extra credits you can receive in this project by doing one of the following extensions to the project:

Implement the FIFO with second chance replacement policy described in the class.

Implement asynchronous operations. This means that after issuing a floppy diskette read or write operation, the faulting process will be suspended instead of busy waiting and let another process to run to overlap your I/O with computation.

Useful Resources


Submitting Programming Assignments

Submit your final solution electronically using the following command:

/u/cs318/bin/318submit 5 README otherfiles ...

The submit command copies your files to the directory /u/cs318/submit/user/number and lists all the files that you have submitted for assignment number. user is your user account name. If you execute submit after the project deadline, your files are placed in directory number_late. You can run submit more than once, and you can submit partial lists of files.


CS318 Staff