15
Nachos Project Assignment 3 Virtual Memory TA: 吳吳吳

Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Embed Size (px)

Citation preview

Page 1: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Nachos Project Assignment 3

Virtual MemoryTA:吳哲榮

Page 2: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Assignment

Test case /test/matmult.c /test/sort.c

Both test programs are greater than whole memory.

Goal – run this two programs concurrently, and get the correct result.

Under RR scheduling.

Page 3: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

File system – swap space Add some table to help you record all

the information. PageTable FrameTable SwapTable

Catch PageFaultException Construct your Virtual Memory

Manager

Page 4: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

swap = new SynchDisk All headers you need to see are in

/filesys/ Use this disk to be the swap space

Page 5: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

PageTable one pagetable per process

FrameTable Record every physical page information

SwapTable Record every sector’s information in

swap.

Page 6: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

PageTable decide your virtual page number

TranslationEntry{unsigned int virtualPage;unsigned int physicalPage; bool valid; //whether in physical memorybool readOnly; bool use; //whether been referenced

or modifiedbool dirty; //whether been modified}

Page 7: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

FrameTable Each frame represent one physical page

FrameInfoEntry{

bool valid;bool lock;unsigned int vpn; //which virtual page is

in this frameAddrSpace *addrSpace; //which process is

using this frame};

Page 8: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

SwapTable The number of entries in swapTable is the same as swap

sectors. Each entry represent one frame in the disk.

FrameInfoEntry{

bool valid; //whether entry been used

bool lock;unsigned int vpn; //which virtual page is in

this entryAddrSpace *addrSpace;//which process is using

this entry};

Access virtual memory in the disk by kernel->swap->WriteSector and kernel->swap->ReadSector.

Page 9: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

Virtual Address Map to Physical Address

Physical Address = pageTable[(virtual address / PageSize)].physicalPage * PageSize + (virtual address % PageSize)

Page 10: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hints

Modify Addrspace::Load(char *fileName) load one page once

1.acquire one page When all physical memory frames are occupied,

please design a page replacement method to get a frame.

2.Map virtual address to physical address Invoke ‘executable->ReadAt(&(kernel-

>machine->mainMemory[physical address]), sizeToLoadNow, inFileAddr)’

Page 11: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Virtual Memory Manager

Public: int TranslateAddr(AddrSpace *space, int

virtAddr);// translate virtual address to physical address

bool AcquirePage(AddrSpace *space, unsigned int vpn);// get a frame

void ReleasePage(AddrSpace *space, unsigned int vpn);// release a page

void PageFaultHandler(void);// manage page fault

Page 12: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

PageFaultHandler

PageFaultHandler Put the pages in swaptable into

frametable. When all physical memory frames are

occupied, please design a page replacement method to get a frame.

Page 13: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Assignment Requirements

Assignment Report (1/20 on the class)

How you modified Nachos to make it support virtual memory – important code segments

Test cases and demonstration to show the correctness of your design

Everything you consider important

Page 14: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Hand in your reports.

Please compress following with zip. source code Final report power-point filetar zcvf b99901000.tar.gz

E-mail your code and presentation files(report) to TA ([email protected]).

Deadline: 2011/1/20 23:59

Page 15: Nachos Project Assignment 3 Virtual Memory TA: 吳哲榮

Grading Policy

Correct Result 30% Report 70%