Assignment 3 Virtual Memory - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Assignment 3 Virtual Memory

Description:

... without the concern of physical memory size in her computer. ... Before we can answer these questions we must review our hardware. The main components: ... – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 14
Provided by: azar9
Category:

less

Transcript and Presenter's Notes

Title: Assignment 3 Virtual Memory


1
Assignment 3 Virtual Memory
  • In your third assignment you will implement a
    virtual memory simulator.
  • VMs goal is to give the user the ability to
    write programs without the concern of physical
    memory size in her computer.
  • The simulator will enable simulation of paging
    hardware and page-replacement software and
    testing of various page replacement strategies.

2
The main questions
  • Which page replacement algorithm to use?
  • how to maintain the page tables?
  • Before we can answer these questions we must
    review our hardware.

3
The main components
  • Swapper - very simple swapper device,
    simulating a paging disk. It reads/writes pages
    from/to a specific page address.
  • Fast memory - the physical memory and some
    info.It has the ability to read/write a byte or
    a page from/to a specific address. For the same
    price, it includes also a table with the
    following info on each page ID ,Dirty bit,
    Reference bit
  • MMU the hardware translator from logical to
    physical addresses. Has limited amount of space
    to store information. When a page is not in
    physical memory, the MMU will trap to the page
    replacement manager.

4
And two more
  • Page Replacement Manager - acts as the OS in
    time of a trap from the MMU. When called to duty,
    it chooses a page from physical memory and
    replaces it with the requested page.
  • VM The object that the user has to interface.
    All other components are transparent to the user.
    It provides read/write from/to any address in the
    virtual address space, and requests from the
    system some statistical data (e.g. hit ratio).

5
Back to our questions
  • Which page replacement algorithm to use?
  • Answer you will have to design a LRU
    approximation algorithm with the given hardware
    in the fast memory.
  • For comparison, also a FIFO algorithm.

6
  • How to maintain the page table?
  • Answer Use a 2-level page table. The first
    level is stored in the MMU cache memory. The 2nd
    level tables are page sized each and are located
    in the physical memory.Important 2nd level
    tables may be swapped in and out of memory.

7
A Typical configuration.
Physical Memory
Kernel space
Swap device
User space
Kernel space
User space
User Page no 1
First Level Table in MMU.
8
What happens if
  • The user wishes to write to user page no 6.
  • The user wishes to write to user page no 5, while
    the next candidate to be swapped out is user page
    no 6.
  • The user wishes to write to user page no 3, while
    the next candidate to be swapped out is user page
    no 7.

9
The scenario
  • User wishes to Read/Write a character from/to
    address v_adr in the virtual memory that belongs
    to a virtual page number pg.
  • The virtual memory queries the MMU for the
    physical address of v_adr .
  • The MMU first checks (in the first level table)
    if the second level page (that contains the entry
    for pg) is in physical memory. If it is, go to 6.
  • Notify the Page Replacement manager that a page
    fault occurred provide the required information.
  • The Page Replacement Manager chooses a page p
    from the second level pages section in the
    physical memory and replaces the requested page
    with p. Then it updates both entries in the first
    level table. Go to 3.

10
  • Look for the physical address of pg in the
    appropriate second level page table entry. If it
    is in physical memory, then return correct
    physical address of v_adr and go to 9.
  • The MMU notifies the Page Replacement Manager
    that a page fault occurred.
  • The Page Replacement Manager chooses page sp from
    the user pages section of the physical memory and
    replaces the requested page with sp. Then it
    updates both entries in the appropriate second
    level pages (But the second level page containing
    the entry of sp might not be in physical memory.
    In that case we have another page fault that has
    to be taken care of). Go to 6
  • The VM receives from the MMU the physical address
    of v_adr and reads/writes from/to that physical
    address.

11
VMInterface
  • virtual bool initialize(char fileName) 0
  • virtual bool write(int address,char data) 0
  • virtual const char read(int address) const 0
  • There is more..

12
For evaluating your assignment
  • virtual void pf_history() 0 for each page
    fault, displays on screen a record serial
    number, type(kernel/user), Page In, Page out
  • virtual double hit_ratio() 0
  • virtual void showMemoryTable()
  • virtual void showPhysicalAddress(int adr)0
  • virtual void showFirstLevelPageTable()0
  • virtual void showSecondLevelPageTable(int i)0
  • Important these methods are for evaluation only
    and will not change the simulators configuration.

13
Assignment 3 part 2
  • Write a short program in C that on execution
    will do the following
  •  
  • Do
  • 1. Display Menu
  • 1. Increase Working set.
  • 2. Decrease working set
  • 3. Exit.
  • 2. Read input
  • 3. Execute code that will cause Increase/
    Decrease Working set size.
  • While (input! Exit)
Write a Comment
User Comments (0)
About PowerShow.com