Presentation is loading. Please wait.

Presentation is loading. Please wait.

O.S Lecture 13 Virtual Memory.

Similar presentations


Presentation on theme: "O.S Lecture 13 Virtual Memory."— Presentation transcript:

1 O.S Lecture 13 Virtual Memory

2 Introduction Virtual memory is used by all current operating systems. It simply means that the memory address a program requests is virtualized – not necessarily related to a physical memory address.   The program may request the content of memory address 1000; the computer looks at where the current map for address 1000 is pointing, and returns the contents of that address. (Virtual address 1000 may be mapped to physical address 20.)

3  Of course, if the memory is virtualized, that means that there is no need to actually have physical memory on the server for every address the programs think they can address – so the programs can believe the server to have more memory than it physically does.   Virtual memory addresses do not need to be mapped to anything until they are allocated by a program.  And a virtual memory address is not mapped to a physical block of memory for storage, but to a block on a hard drive.

4 So if the operating system has 2G of physical memory, has a program loaded that is using 1.5G of memory, and the user attempts to start another program that will also use 1.5G of data in memory – what happens?   To simplify things a bit, the memory pages that the first program is using will be copied from physical memory to disk, thus freeing enough memory for the second program to run.

5 If the first program then has to run again, the second program’s data will be written to the disk backed portion of virtual memory, and the first program’s data read in from disk, and it will run again. Of course, accessing a hard drive to retrieve the contents of a virtual memory block will be much slower than accessing physical memory, so the operating system tries to avoid using disk backed virtual memory.

6 Virtual memory is a technique that allows the execution of processes that are not completely in memory. Advantages programs can be larger than physical memory. main memory can be viewed by the user as an extremely large, uniform array of storage.

7 allows processes to share files easily and to implement shared memory
provides an efficient mechanism for process creation. Virtual memory is not easy to implement, however, and may substantially decrease performance if it is used carelessly.

8 The ability to execute a program that is only partially in memory has many benefits:
A program will no longer be constrained by the amount of physical memory that is available. Users would be able to write programs for an extremely large virtual address space, simplifying the programming task.

9 Virtual Memory That is Larger Than Physical Memory

10 The address space of a process refers to the logical (or virtual) view of how a process is stored in memory. Typically, this view is that a process begins at a certain logical address-say, address 0-and exists in contiguous memory,

11 Consider how an executable program might be loaded from disk into memory.
One option is to load the entire program in physical memory at program execution time. However, a problem with this approach is that we may not initially need the entire program in memory. Suppose a program starts with a list of available options from which the user is to select.

12 Loading the entire program into memory results in loading the executable code for all options, regardless of whether an option is ultimately selected by the user or not. An alternative strategy is to load pages only as they are needed. This technique is known as demand paging and is commonly used in virtual memory systems. With demand-paged virtual memory, pages are only loaded when they are demanded during program execution; pages that are never accessed are thus never loaded into physical memory.

13 With demand paging, a pager is used to swap into memory the individual pages of a process which needs to be executed. When a process is to be swapped in, the pager guesses which pages will be used before the process is swapped out again.

14 Instead of swapping in a whole process, the pager brings only those pages into memory.
Thus, it avoids reading into memory pages that will not be used anyway, decreasing the swap time and the amount of physical memory needed.

15 Your Task Explain the hardware support required to support demand paging

16 But what happens if the process tries to access a page that was not brought into memory?
Access to a page marked invalid causes a page fault. The paging hardware, in translating the address through the page table, will notice that the invalid bit is set, causing a trap to the operating system. This trap is the result of the operating system's failure to bring the desired page into memory.

17 Thrashing If a process does not have “enough” pages, the page-fault rate is very high Page fault to get page Replace existing frame But quickly need replaced frame back This leads to: Low CPU utilization Operating system thinking that it needs to increase the degree of multiprogramming Another process added to the system Thrashing = a process is busy swapping pages in and out

18 Find out… How can page thrashing be avoided?


Download ppt "O.S Lecture 13 Virtual Memory."

Similar presentations


Ads by Google