nachos project assignment 3 memory management

26
Nachos Project Assignment 3 Memory Management TA: Chien-Wen, Huang. Advisor: Farn, Wang. 2015/12/16

Upload: trinhphuc

Post on 04-Jan-2017

261 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Nachos Project Assignment 3 Memory Management

Nachos Project Assignment 3

Memory ManagementTA: Chien-Wen, Huang.

Advisor: Farn, Wang.2015/12/16

Page 2: Nachos Project Assignment 3 Memory Management

Outline• Memory Management• Report• Grading Policy & Late Policy.• Reference.

Page 3: Nachos Project Assignment 3 Memory Management

Memory ManagementAbout the virtual memory manager, swap, page fault handler…

Page 4: Nachos Project Assignment 3 Memory Management

The Goal of Project 3.• Have you run these test cases in the test folder?• /test/matmult.c• /test/sort.c

• Both the test cases require lots of memory.• Larger than the physical memory!

• Goal: Run this two programs concurrently, and get the correct result.• Remember to specify the scheduling algorithm you used in the report.• No way to pass this project by simply modify the memory size in “machine”.

Page 5: Nachos Project Assignment 3 Memory Management

Some Hints.• File system – swap space.• Maintain three tables to record the information.• PageTable• FrameTable• SwapTable

• Think how to “load” the page correctly.• Deal with the PageFaultException.• Design your own “Virtual Memory Manager".

Page 6: Nachos Project Assignment 3 Memory Management

Swap Space - Create Disk. • swap = new SynchDisk in your kernel.• Use the disk as the swap space.• Access the virtual memory in the disk by…• kernel->swap->WriteSector• kernel->swap->ReadSector

• See “synchdisk.cc” and other files in /filesys for details!• Read the header in those files first.

Page 7: Nachos Project Assignment 3 Memory Management

Maintain Three Tables.• PageTable• One page table per process.• Decide your virtual page number.

• FrameTable• Record every physical page’s information.• Each frame represent one physical page.

• SwapTable• Record every sector’s information in swap.• The number of entries in SwapTable is the same as the swap sectors.• Each entry represent one frame in the disk.

Page 8: Nachos Project Assignment 3 Memory Management

Maintain Three Tables.

PageTable1234

FrameTable1234

SwapTable1234

Physical memory

Page 9: Nachos Project Assignment 3 Memory Management

Maintain Three Tables - PageTable• For each entry in PageTable• TranslationEntry {

unsigned int virtualPage; //virtual memory pageunsigned int physicalPage; //if in physical memorybool valid; //if in physical memorybool use; //been used(read or write)bool dirty; //been modified };

Page 10: Nachos Project Assignment 3 Memory Management

Maintain Three Tables - FrameTable• For each entry in FrameTable• FrameInfoEntry {

Bool valid; //if being usedBool lock;AddrSpace *addrSpace; //which process is using this pageUnsigned int vpn; //which virtual page of the process is stored in this page};

Page 11: Nachos Project Assignment 3 Memory Management

Maintain Three Tables - SwapTable• For each entry in SwapTable• FrameInfoEntry {

Bool valid; //if being usedBool lock;AddrSpace *addrSpace; //which process is using this pageUnsigned int vpn; //which virtual page of the process is stored in this page};// same as the FrameTable

Page 12: Nachos Project Assignment 3 Memory Management

Back to Nachos - Addrspace::Load• Note: Load 1 page a time.• First ask for 1 page, if the FrameTable is full, select 1 frame and put it

into SwapTable.• Design your own page replacement method to get the frame.• Specify the method in your report.

• Mapping virtual address to physical address.• Invoke “executable->ReadAt(&(kernel->machine-

>mainMemory[physical address]), sizeToLoadNow, inFileAddr)”

Page 13: Nachos Project Assignment 3 Memory Management

Address Mapping• Map the Virtual Address to Physical Address.• Like the way you used in project 1.• Physical Address =

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

Page 14: Nachos Project Assignment 3 Memory Management

One Possible Way to Implement:Create a new class “Memory Manager”• Class MemoryManager {

Int TransAddr(AddrSpace *space, int virtAddr); //return phyAddr (translated from virtAddr)

Bool AcquirePage(AddrSpace *space, int vpn); //ask a page (frame) for vpn

Bool ReleasePage(AddrSpace *space, int vpn); //free a page

Void PageFaultHandler();//will be called when manager want to swap a page from SwapTable to

FrameTable and the FrameTable is full.};

Page 15: Nachos Project Assignment 3 Memory Management

Page-Fault Handler?• Put the pages in SwapTable into FrameTable.• When all physical memory frames are occupied, design a page

replacement method to get a frame.• Remember to specify it in your report!

• You can do this work in your own way.

Page 16: Nachos Project Assignment 3 Memory Management

Some files that might be useful.• For the disk usage details, see: • /filesys/synchdisk.h• /filesys/synchdisk.cc• Other files in /filesys (Optional).

• For the swap space initialization:• /userprog/userkernel.h• /userprog/userkernel.cc

• For the table maintaining, see:• /machine/machine.h and /machine/machine.cc• /machine/translate.h and /machine/translate.cc

Page 17: Nachos Project Assignment 3 Memory Management

Some files that might be useful.• For the table maintaining, see:• /machine/machine.h and /machine/machine.cc• /machine/translate.h and /machine/translate.cc

• For the loading of pages.• userprog/addrspace.h• userprog/addrspace.cc

• Always see the header and comments first.• Based on your implementation, there might be different files that

your need to see and modify.

Page 18: Nachos Project Assignment 3 Memory Management

Report & PolicyReport contents, grading policy, late policy and the summary.

Page 19: Nachos Project Assignment 3 Memory Management

19

Report• Report• Motivation and the problem analysis.• What’s your plan to deal with the problem(high-level).• How you really implement to solve the problem in Nachos.• You can including some (not all) important code segments and comments.• Experiment result and some discussion.• Extra effort or observation.

• Please saved as [Student ID]_NachOS_report.pdf• E.g. r04942044_NachOS_report.pdf• NOT [r04942044]_NachOS_report.pdf

Page 20: Nachos Project Assignment 3 Memory Management

Extra effort as Bonus• The replacement method you design.• Extra observation or modification on nachos.• Please write it down on your report if you did.

Page 21: Nachos Project Assignment 3 Memory Management

21

Hand in source code & report• Source Code• tar zcvf [Student ID]_Nachos3.tar.gz ./nachos-4.0• E.g. r04942044_Nachos3.tar.gz• NOT .gz or .rar.• Please include ALL the nachos code.

• Mail your source code and report to [email protected]• One pdf file as report and one tar.gz file as source code.

• Deadline: Jan.20.2016, 23:59:59.

Page 22: Nachos Project Assignment 3 Memory Management

Grading PolicyWith presentation• Nachos source code: (30%)• Report: (30%)• Correct format: (20%)• Presentation: (20%)• Bonus

Page 23: Nachos Project Assignment 3 Memory Management

Grading PolicyWithout presentation• Nachos source code: (40%)• Report: (40%)• Correct format: (20%)• Bonus

Page 24: Nachos Project Assignment 3 Memory Management

Late Policy• 10% penalty per day.• Late penalty only holds for a week• After 7 days, you will get 70% penalty, but no more penalty after that.• That is, after n(n>=7) days, you will still get 70% penalty.• Don’t give up!

• No plagiarism.

Page 25: Nachos Project Assignment 3 Memory Management

Summary• Implement the memory manager (mainly the virtual memory).• Write the report.• Send to TA in the correct format before the deadline.• Jan.20.2016, 23:59:59

• Prepare the presentation if you should.

Page 26: Nachos Project Assignment 3 Memory Management

Reference• Nachos Beginner’s Guide:• https://www.ida.liu.se/~TDDI12/material/begguide/

• Nachos Virtual Memory Slides:• http://www.ittc.ku.edu/~dmitchell/EECS678/labs/old-labs/lab12/NachosVM.

pdf

• Search Engine as your friends.