Sie sind auf Seite 1von 6

Virtual Memory Definition: An imaginary area supported by some operating system which is actually located at secondary storage.

-Virtual memory combines computers RAM with temporary space on hard disk. When RAM runs low, virtual memory moves data from RAM to space called paging file. -The purpose of virtual memory is to enlarge the address space, the set of address a program can utilize. -Virtual memory can contain twice as many addresses as main memory. -All programs running in a computer will not fit in memory at once, so there goes the use of virtual memory. -Only some portions of a program will be loaded in main memory, the others will stay in secondary storage. -Even though only a portion of each program is stored in memory, it gives the users the appearance that their programs are being completely loaded in main memory during their entire processing time.

-Virtual memory allows multiple programs to load in memory at the same time. Each application addresses memory starting at zero, but virtual memory takes control of the memory addressing and lets each application function as if it had unlimited memory. -Before virtual memory, sharing meant that copies of files were stored in each users account. This allowed them to load their own copy and work on it at any time. This kind of sharing created a great deal of unnecessary system cost the I/O overhead in loading the copies and the extra secondary storage needed. -With virtual memory, those cost are substantially reduced because shared programs and subroutine are loaded on demand, satisfactorily reducing the storage requirements of main memory (although this is accomplished at the expense of Memory Map Table)

-The use of virtual memory requires cooperation between the Memory Manager (which tracks each page or segment) and the processor hardware (which issues the interrupt and resolves the virtual address) -When a page is needed thats not already in memory, a page fault is issued and the Memory Manager choose a page frame, loads the page, and updates entries in the memory map table and the page map table. -Virtual memory works very well in a multiprogramming environment because most program spend a lot of time waiting they wait for I/O to be performed; they wait for pages to be swapped in or out; and, in a time-sharing environment, they wait when their time slice is up (their turn to use the processor is expired). In a multi programming environment, the waiting time isnt lost , and the CPU simply moves to another job; this was the advantages of partitions. - To facilitate copying virtual memory into real memory, the operating system divides virtual memory into pages, each of which contains a fixed number of addresses. Each page is stored on a disk until it is needed. When the page is needed, the operating system copies it from disk to main memory, translating the virtual addresses into real addresses. - The process of translating virtual addresses into real addresses is called mapping. The copying of virtual pages from disk to main memory is known as paging or swapping.

Virtual Memory Pages -The computer's real memory is broken up into smaller segments, called "pages," typically 4KB in size. - When real memory fills up, pages not currently in use by open applications are written to a virtual memory "swap file" on the disk for temporary storage. - When any swapped out page is required again, once again a page in real memory is written to the disk to make room, and the disk page is retrieved. -Memory is the computer's workspace, and since there is often a hundred times more disk space than memory space, virtual memory dramatically increases the computer's capacity to do work. -However, there is a penalty. When a user has too many open programs, there can be excessive amounts of page swapping, causing applications to slow down. -In addition, switching between applications is no longer immediate (thrashing).

-Page Tables : used to translate the virtual addresses seen by the application into physical addresses used by the hardware to process instructions; such hardware that handles this specific translation is often known as the memory management unit. Each entry in the page table holds a flag indicating whether the corresponding page is in real memory or not. If it is in real memory, the page table entry will contain the real memory address at which the page is stored. When a reference is made to a page by the hardware, if the page table entry for the page indicates that it is not currently in real memory, the hardware raises a page fault exception, invoking the paging supervisor component of the operating. Systems can have one page table for the whole system, separate page tables for each application and segment, a tree of page tables for large segments or some combination of these. If there is only one page table, different applications running at the same time use different parts of a single range of virtual addresses. If there are multiple page or segment tables, there are multiple virtual address spaces and concurrent applications with separate page tables redirect to different real addresses.

-Paging Supervisor Operating systems have memory areas that are pinned (never swapped to secondary storage). Interrupt mechanisms rely on an array of pointers to their handlers, such as I/O completion and page fault. If the pages containing these pointers or the code that they invoke were pageable, interrupt-handling would become far more complex and time-consuming, particularly in the case of page fault interrupts. Hence, some part of the page table structures is not pageable. Some pages may be pinned for short periods of time, others may be pinned for long periods of time, and still others may need to be permanently pinned.

The paging supervisor code and drivers for secondary storage devices on which pages reside must be permanently pinned, as otherwise paging wouldn't even work because the necessary code wouldn't be available. Timing-dependent components may be pinned to avoid variable paging delays. Data buffers that are accessed directly by, say, peripheral devices that use direct or I/O channels must reside in pinned pages while the I/O operation is in progress because such devices and the buses to which they are attached expect to find data buffers located at physical memory addresses; regardless of whether the bus has a memory management unit for I/O, transfers cannot be stopped if a page fault occurs and then restarted when the page fault has been processed. -Trashing When paging is used, a problem called "thrashing" can occur, in which the computer spends an unsuitable amount of time swapping pages to and from a backing store, hence slowing down useful work. Adding real memory is the simplest response, but improving application design, scheduling, and memory usage can help.

-Paging Advantages No external fragmentation A small amount of internal fragmentation A program can be stored in any available page Programs can occupy all the available memory Easy to share memory

-Paging disadvantages More complex addressing. The addressing hardware is more complex and slower Two RAM accesses are required for each memory request; one to the page table and one to access the data

-Translation Lookaside Buffer The Translation Lookaside Buffer (TLB) is a special cache for the page table. The TLB is on the CPU chip for fast access. Recently accessed page table entries are kept in the TLB. Most page table accesses are resolved in the TLB.

Segmentation -Memory can be separated into segments based on the program. Instruction segments for each function Data segments for global data and heap Stack segments

-Segmentation provides greater function isolation and makes linking easier. -Segments can have virtual memory pages.

Combining Paging and Segmentation -An addressing system can use both paging and segmentation. -Large segments can be composed of pages. -Allows simple memory allocation and logical program division.

Summary -Virtual Memory OS When a page fault interrupt occurs, the OS reads the desired page from disk into an available page of RAM. The users page table is updated top point to newly loaded page. The program is placed back on the ready list to be executed.

-Virtual Memory Advantages A jobs size is no longer restricted to the size of main memory (or the free space within main memory). Memory is used more efficiently because the only sections of a job stored in memory are those needed immediately, while those not needed remain in secondary storage. It allows unlimited amount of multiprogramming (which can apply to many jobs, as in dynamic and static portioning, or many users in a time-sharing environment). It eliminates external fragmentation and minimizes internal fragmentation by combining segmentation and paging (internal fragmentation occurs in the program). It allows the time sharing of code and data. It facilitates dynamic linking of program segments. Allows you to fit many large programs into a relatively small RAM. Eliminate the need to fit program into memory holes.

-Virtual Memory Disadvantages Increase processor hardware cost (required complex hardware support). Increase overhead for handling paging interrupts. Increase software complexity to prevent trashing. Can reduce performance. Makes program execution time less predictable.

Das könnte Ihnen auch gefallen