Virtual Memory Basic Concept - Introduction to Operating System - Lecture Notes, Study notes of Operating Systems

Virtual Memory Basic Concept, Demand Paging, Page Fault, Performance of Demand Paging, Virtual Memory Support, Protected Mode, Address translation in protected mode . Above mentioned are key points of this lecture handout. Virtual University handout for introduction to operating system are in detail and explanatory.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

ahsen
ahsen ๐Ÿ‡ต๐Ÿ‡ฐ

4.6

(88)

84 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
184
Operating Systems Lecture No. 37
Operating Systems
Lecture No. 37
Reading Material
๎šƒ Chapters 9 and 10 of the textbook
๎šƒ Lecture 37 on Virtual TV
Summary
๎šƒ Intel 80386 Virtual Memory Support
๎šƒ Virtual Memory Basic Concept
๎šƒ Demand Paging
๎šƒ Page Fault
๎šƒ Performance of Demand Paging
Intel 80386 Virtual Memory Support
We discussed logical to physical address translation in the real mode operation of the Intel
80386 processor in the last lecture. Here we discuss address translation in the protected
mode.
Protected Mode
๎šƒ 248 bytes virtual address space
๎šƒ 232 bytes linear address space
๎šƒ Max segment size = 4 GB
๎šƒ Max segments / process = 16K
๎šƒ Six CPU registers allow access to six segments at a time
๎šƒ Selector is used to index a segment descriptor table to obtain an 8-byte segment
descriptor entry. Base address and offset are added to get a 32-bit linear address,
which is partitioned into p1, p2, and d for supporting 2-level paging.
The following figure shows the hardware support needed for this translation.
Intel 80386 address translation in protected mode
pf3
pf4
pf5
pf8

Partial preview of the text

Download Virtual Memory Basic Concept - Introduction to Operating System - Lecture Notes and more Study notes Operating Systems in PDF only on Docsity!

Operating Systems Lecture No. 37

Operating Systems

Lecture No. 37

Reading Material

ยƒ Chapters 9 and 10 of the textbook ยƒ Lecture 37 on Virtual TV

Summary

ยƒ Intel 80386 Virtual Memory Support ยƒ Virtual Memory Basic Concept ยƒ Demand Paging ยƒ Page Fault ยƒ Performance of Demand Paging

Intel 80386 Virtual Memory Support

We discussed logical to physical address translation in the real mode operation of the Intel 80386 processor in the last lecture. Here we discuss address translation in the protected mode.

Protected Mode ยƒ 248 bytes virtual address space ยƒ 232 bytes linear address space ยƒ Max segment size = 4 GB ยƒ Max segments / process = 16K ยƒ Six CPU registers allow access to six segments at a time ยƒ Selector is used to index a segment descriptor table to obtain an 8-byte segment descriptor entry. Base address and offset are added to get a 32-bit linear address, which is partitioned into p1, p2, and d for supporting 2-level paging.

The following figure shows the hardware support needed for this translation.

Intel 80386 address translation in protected mode

Virtual Memory Basic Concept

An examination of real programs shows that in many cases the existence of the entire program in memory is not necessary: ยƒ Programs often have code to handle unusual error conditions. Since these errors seldom occur in practice, this code is almost never executed. ยƒ Arrays, lists and tables are often allocated more memory than they actually need. An array may be declared 100 by 100 elements even though it is seldom larger than 10 by 10 elements. ยƒ Certain options of a program may be used rarely. Even in cases where the entire program is needed, it may not be all needed at the same time. The ability to execute a program that is only partially in memory confers many benefits. ยƒ A program would 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. ยƒ Because each user program could take less physical memory, more programs could be run at the same time, with a corresponding increase in CPU utilization and throughput with no increase in response time or turnaround time. ยƒ Less I/O would be needed to load or swap each user program into memory, so each user program would run faster. Thus running a program that is not entirely in memory would benefit both the system and the user. Virtual Memory is the separation of user logical memory from physical memory. This separation allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available. Virtual memory makes the task of programming easier because the programmer need not worry about the amount of physical memory, or about what code can be placed in overlays; she can concentrate instead on the problem to be programmed. In addition to separating logical memory from physical memory, virtual memory also allows files and memory to be shared by several different processes through page sharing. The sharing of pages further allows performance improvements during process creation. Virtual memory is commonly implemented as demand paging. It can also be implemented in a segmentation system. One benefit of virtual memory is efficient process creation. Yet another is the concept of memory mapped files. We will discuss these topics in subsequent lectures.

Mapping of logical memory onto physical memory under paging

Protection under paging

Page Fault 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 trap. 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 (in an attempt to minimize disk transfer overhead and memory requirements) rather than an invalid address error as a result of an attempt to use an illegal memory address. The procedure for handling a page fault is straightforward:

  1. We check an internal table (usually kept with the process control block) for this process to determine whether the reference was valid or invalid memory access.
  2. If the reference was invalid we terminate the process. If it was valid, but we have not yet brought in that page, we now page it in.
  3. We find a free frame (by taking one from the free-frame list, for example)
  4. We schedule a disk operation to read the desired page into the newly allocated frame.
  5. When the disk read is complete, we modify the internal table kept with the process and the page table to indicate that the page is now in memory.
  6. We restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory.

Steps needed for servicing a page fault

Since we save the state (registers, condition code, instruction counter) of the interrupted process when the page fault occurs, we can restart the process in exactly the same place and state except that the desired page is now in memory and is accessible. In this way we are able to execute a process even though portions of it are not yet in memory. When the process tries to access locations that are not in memory, the hardware traps the operating system (page fault). The operating system reads the desired into memory and restarts the process as though the page had always been in memory. In the extreme case, we could start executing a process with no pages in memory. When the operating system sets the instruction pointer to the first instruction of the process, which is on a non memory resident page, the process immediately faults for the page. After this page is brought into memory, the process continues to execute faulting as necessary until every page that it needs is in memory. At that point, it can execute with no more faults. This scheme is called pure demand paging: never bring a page into memory until it is required. The hardware needed to support demand paging is the same as the hardware for paging and swapping: ยƒ Page table: This table has the ability to mark an entry invalid through a valid- invalid bit or special value of protection bits. ยƒ Secondary memory: This memory holds those pages that are not present in main memory. The secondary memory is usually a high speed disk. It is known as the swap device, and the section of disk used for this purpose is called the swap space. In addition to this hardware, additional architectural constraints must be imposed. A crucial one is the need to be able to restart any instruction after a page fault. In most cases this is easy to meet, a page fault occurs while we are fetching an operand, we must fetch and decode the instruction again, and then fetch the operand. A similar problem occurs in machines that use special addressing modes, including auto increment and auto decrement modes. These addressing modes use a register as a pointer and automatically increment or decrement the register. Auto decrement automatically decrements the register before using its contents as the operand address; auto increment increments the register after using its contents. Thus the instruction

MOV (R2) +, -(R3)

Copies the contents of the location pointed to by register2 into that pointed to by register3. Now consider what will happen if we get a fault when trying to store into the location pointed to by register3. To restart the instruction we must reset the two registers to the values they had before we started the execution of the instruction.

  1. Interrupt from the disk (I/O completed)
  2. Save the registers and process state for the other user (if step 6 is executed)
  3. Determine that the interrupt was from the disk
  4. Correct the page table and other tables to show that the desired page is now in memory
  5. Wait for the CPU to be allocated to this process again
  6. Restore the user registers, process state and new page table Not all these steps are necessary in every case. For example we are assuming that in step 6, the CPU is allocated to another process while the I/O occurs. This arrangement allows multiprogramming to maintain CPU utilization, but requires additional time to resume the page fault service routine when the I/O transfer is complete. In any case we are faced with three major components of the page fault service time:
  7. Service the page fault interrupt
  8. Read in the page
  9. Restart the process The first and third tasks may be reduced, with careful coding, to several hundred instructions. These tasks may take from 1 to 100 microseconds each. The page switch time, on the other hand, will probably be close to 24 milliseconds. A typical hard disk has an average latency of 8 milliseconds, a seek of 15 milliseconds, and a transfer time of 1 millisecond. Thus, the total paging time would be close to 25 milliseconds, including hardware and software time. Remember that we are looking at only the device service time. If a queue of processes is waiting for the device we have to add device queuing time as we wait for the paging device to be free to service our request, increasing even more the time to swap. If we take an average page fault service time of 25 milliseconds and a memory access time of 100 nanoseconds, then the effective access time in nanoseconds is

Effective access time = (1-p) * (100) + p (25 milliseconds) = (1-p) * 100 + p * 25,000, = 100 + 24,999,900 * p We see then that the effective access time is directly proportional to the page fault rate. If one access out of 1,000 causes a page fault, the effective access time is 25 microseconds. The computer would be slowed down by a factor of 250 because of demand paging! If we want less than 10 percent degradation, we need:

110 > 100 + 25,000,000 * p 10 > 25,000,000 * p p < 0. That is, to keep the slowdown due to paging to a reasonable level, we can allow only less than one memory access out of 2,500,000 to page fault. It is important to keep the slowdown due to paging to a reasonable level, we can allow only less than one memory access out of 2,500,000 to page fault. It is important to keep the page fault rate low in a demand-paging system. Otherwise the effective access time increases, slowing process execution dramatically. One additional aspect of demand paging is the handling and overall use of swap space. Disk I/O to swap space is generally faster than that to the file system. It is faster because swap space is allocated in much larger blocks, and file lookups and indirect allocation methods are not used. It is therefore possible for the system to gain better paging throughput by copying an entire file image into the swap space at process startup,

and then performing demand paging from the swap space. Another option is to demand pages from the from the file system initially, but to write the pages to swap space as they are replaced. This approach will ensure that only needed pages are ever read from the file system, but all subsequent paging is done from swap space. Some systems attempt to limit the amount of swap space when binary files are used. Demand pages for such files are brought directly from the file system. However, when page replacement is called for, these pages can simply be overwritten and read in from the file system again if ever needed. Using this approach, the file system itself serves as the backing store. However swap space must still be used for pages not associated with a file; these pages include the stack and heap for a process. This technique is used in several systems including Solaris.