TWiki> CS385fall14 Web>Homeworks>Homework4 (revision 1)EditAttach

Homework 4: mmap() - eager and lazy

In this homework, we learn a little bit about memory management by adding a widely used Unix feature to xv6: mmap(). While mmap can be (and is) used to allocate large chunks of memory, the more interesting use of mmap() is that of mapping a file into memory. This means, you call mmap once, with a file descriptor as argument, and the file immediately appears in memory.

There are at least two main ways to do this. The first is eager: when mmap is called, have the kernel read the file as instructed, put it somewhere convenient in memory, and return a pointer to the location. The second is lazy: take note of the user's request, and return without doing anything further. When the user tries to access the memory, deal with the resulting page-fault, reading in only those pages that the user tries to read, when the user tries to read them.

Getting started

As in the past, git fetch the latest changes, then checkout the origin/hw4 branch which contains some minimal template code, and some more extensive testing code. To test your solution, rebuild and start xv6, then run hw4_tests from inside qemu, on the xv6 command line.


The system call sys_mmap() has already been created for you, only it doesn't do much.

Eager solution

Lazy solution

Bonus points: anonymous mmap() allocations

Here, allow the user to allocate huge amounts of memory, but only actually allocate each page of memory on access. To get your extra credit, also provide a test program, and demonstrate and explain in person to Jakob or a TA.

Edit | Attach | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2014-09-09 - 03:49:06 - Main.jakob
Copyright 2016 The Board of Trustees
of the University of
Helping Women Faculty Advance
Funded by NSF