Update docs.
[pintos-anon] / doc / vm.texi
index 84b07524d98791fb86cf6b44f3864e6a7969e413..5226e63358fdb8c3b26736ee570e9fc60f543c87 100644 (file)
@@ -12,16 +12,22 @@ You will be using the @file{vm} directory for this project.  There is
 no new code to get acquainted with for this assignment.  The @file{vm}
 directory contains only the @file{Makefile}s.  The only change from
 @file{userprog} is that this new @file{Makefile} turns on the setting
-@option{-DVM}, which you will need for this assignment.  All code you
-write will either be newly generated files (e.g.@: if you choose to
-implement your paging code in their own source files), or will be
-modifications to pre-existing code (e.g.@: you will change the
-behavior of @file{addrspace.c} significantly).
+@option{-DVM}.  All code you write will either be newly generated
+files (e.g.@: if you choose to implement your paging code in their own
+source files), or will be modifications to pre-existing code (e.g.@:
+you will change the behavior of @file{process.c} significantly).
 
 You will be building this assignment on the last one.  It will benefit
 you to get your project 2 in good working order before this assignment
 so those bugs don't keep haunting you.
 
+All the test programs from the previous project should also work with
+this project.  You should also write programs to test the new features
+introduced in this project.
+
+Your submission should define @code{THREAD_JOIN_IMPLEMENTED} in
+@file{constants.h} (@pxref{Conditional Compilation}).
+
 @menu
 * VM Design::                   
 * Page Faults::                 
@@ -34,7 +40,7 @@ so those bugs don't keep haunting you.
 * Virtual Memory FAQ::          
 @end menu
 
-@node VM Design, Page Faults, Project 3--Virtual Memory, Project 3--Virtual Memory
+@node VM Design
 @section A Word about Design
 
 It is important for you to note that in addition to getting virtual
@@ -52,7 +58,7 @@ In keeping with this, you will find that we are going to say as little
 as possible about how to do things.  Instead we will focus on what end
 functionality we require your OS to support.
 
-@node Page Faults, Disk as Backing Store, VM Design, Project 3--Virtual Memory
+@node Page Faults
 @section Page Faults
 
 For the last assignment, whenever a context switch occurred, the new
@@ -137,14 +143,29 @@ address.
                            /                      /
 @end example
 
+Header @file{threads/mmu.h} has useful functions for various
+operations on virtual addresses.  You should look over the header
+yourself, but its most important functions include these:
+
+@table @code
+@item pd_no(@var{va})
+Returns the page directory index in virtual address @var{va}.
+
+@item pt_no(@var{va})
+Returns the page table index in virtual address @var{va}.
 
-FIXME need to explain virtual and physical memory layout - probably
-back in userprog project
+@item pg_ofs(@var{va})
+Returns the page offset in virtual address @var{va}.
 
-FIXME need to mention that there are many possible implementations and
-that the above is just an outline
+@item pg_round_down(@var{va})
+Returns @var{va} rounded down to the nearest page boundary, that is,
+@var{va} but with its page offset set to 0.
 
-@node Disk as Backing Store, Memory Mapped Files, Page Faults, Project 3--Virtual Memory
+@item pg_round_up(@var{va})
+Returns @var{va} rounded up to the nearest page boundary.
+@end table
+
+@node Disk as Backing Store
 @section Disk as Backing Store
 
 In VM systems, since memory is less plentiful than disk, you will
@@ -170,7 +191,7 @@ page can be brought in.  Many virtual memory systems avoid this extra
 overhead by writing modified pages to disk in advance, so that later
 page faults can be completed more quickly.
 
-@node Memory Mapped Files, Stack, Disk as Backing Store, Project 3--Virtual Memory
+@node Memory Mapped Files
 @section Memory Mapped Files
 
 The traditional way to access the file system is via @code{read} and
@@ -196,7 +217,7 @@ file (plus one each for code, data, and stack).  You will implement
 memory mapped files for problem 3 of this assignment, but you should
 design your solutions to problems 1 and 2 to account for this.
 
-@node Stack, Problem 3-1 Page Table Management, Memory Mapped Files, Project 3--Virtual Memory
+@node Stack
 @section Stack
 
 In project 2, the stack was a single page at the top of the user
@@ -207,7 +228,7 @@ system should allocate additional pages for the stack as necessary,
 unless those pages are unavailable because they are in use by another
 segment, in which case some sort of fault should occur.
 
-@node Problem 3-1 Page Table Management, Problem 3-2 Paging To and From Disk, Stack, Project 3--Virtual Memory
+@node Problem 3-1 Page Table Management
 @section Problem 3-1: Page Table Management
 
 Implement page directory and page table management to support virtual
@@ -268,7 +289,7 @@ Follow the PDE to the page table.  Point the PTE for the faulting
 virtual address to the physical page found in step 2.
 @end enumerate
 
-You'll need to modify the ELF loader in @file{userprog/addrspace.c} to
+You'll need to modify the ELF loader in @file{userprog/process.c} to
 do page table management according to your new design.  As supplied,
 it reads all the process's pages from disk and initializes the page
 tables for them at the same time.  For testing purposes, you'll
@@ -276,7 +297,11 @@ probably want to leave the code that reads the pages from disk, but
 use your new page table management code to construct the page tables
 only as page faults occur for them.
 
-@node Problem 3-2 Paging To and From Disk, Problem 3-3 Memory Mapped Files, Problem 3-1 Page Table Management, Project 3--Virtual Memory
+There are many possible ways to implement virtual memory.  The above
+is simply an outline of our suggested implementation.  You may choose
+any implementation you like, as long as it accomplishes the goal.
+
+@node Problem 3-2 Paging To and From Disk
 @section Problem 3-2: Paging To and From Disk
 
 Implement paging to and from disk.
@@ -327,7 +352,7 @@ file itself as backing store for read-only segments, since these
 segments won't change.
 
 There are a few special cases.  Look at the loop in
-@code{load_segment()} in @file{userprog/addrspace.c}.  Each time
+@code{load_segment()} in @file{userprog/process.c}.  Each time
 around the loop, @code{read_bytes} represents the number of bytes to
 read from the executable file and @code{zero_bytes} represents the number
 of bytes to initialize to zero following the bytes read.  The two
@@ -355,7 +380,11 @@ be ``lazy''; even real OSes such as Linux do not load partial pages
 lazily.
 @end itemize
 
-FIXME mention that you can test with these special cases eliminated
+Incidentally, if you have trouble handling the third case above, you
+can eliminate it temporarily by linking the test programs with a
+special ``linker script.''  Read @file{tests/userprog/Makefile} for
+details.  We will not test your submission with this special linker
+script, so the code you turn in must properly handle all cases.
 
 You may optionally implement sharing: when multiple processes are
 created that use the same executable file, share read-only pages among
@@ -364,7 +393,7 @@ segments for each process.  If you carefully designed your data
 structures in part 1, sharing of read-only pages should not make this
 part significantly harder.
 
-@node Problem 3-3 Memory Mapped Files, Virtual Memory FAQ, Problem 3-2 Paging To and From Disk, Project 3--Virtual Memory
+@node Problem 3-3 Memory Mapped Files
 @section Problem 3-3: Memory Mapped Files
 
 Implement memory mapped files.
@@ -402,7 +431,7 @@ the changes to the @code{mmap} segment will eventually be written to
 the file.  (In fact, you may choose to implement executable mappings
 as a special case of file mappings.)
 
-@node Virtual Memory FAQ,  , Problem 3-3 Memory Mapped Files, Project 3--Virtual Memory
+@node Virtual Memory FAQ
 @section FAQ
 
 @enumerate 1