Virtual memory is a technique that allows programs to execute even if they do not fit entirely in physical memory by using secondary storage. It offers advantages such as unlimited address space and efficient memory utilization, but also has disadvantages like the need for additional hardware support. Various page replacement algorithms, including Optimal, FIFO, and LRU, are used to manage memory effectively, each with its own pros and cons.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
11 views8 pages
Chapter 8
Virtual memory is a technique that allows programs to execute even if they do not fit entirely in physical memory by using secondary storage. It offers advantages such as unlimited address space and efficient memory utilization, but also has disadvantages like the need for additional hardware support. Various page replacement algorithms, including Optimal, FIFO, and LRU, are used to manage memory effectively, each with its own pros and cons.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8
CHAPTER-8
VIRTUAL MEMORY
Virtual memory is a technique of executing program instructions that may
not fit entirely in the system memory. In this scheme, the programs can be larger than the actual physical memory available. The basic concept of virtual memory is to store instruction and data of a program in the secondary memory and to load them in the main memory when they are required. Virtual memory thus separates the user logical memory from physical memory. Virtual memory is commonly implemented by demand paging and demand segmentation.
Advantages of virtual memory:
1. Unlimited address space: using virtual memory user is able to write programs for a very large virtual address space. 2. Increased degree of multiprogramming: with the implementation of virtual memory, each user program occupies less physical memory, as a result more programs occupies less physical memory, as a result more programs can be run at the same time. 3. Reduced I/O: less I/O is needed to load or swap each user program into memory, so each user program will run faster. 4. Automatic memory allocation: memory is allocated automatically on the basis of demand. 5. Efficient memory utilization: it utilizes memory efficiently as entire process need not be in the main memory. Disadvantages of virtual memory: 1. It requires additional hardware support for address translation. 2. Possibility of thrashing due to excessive paging and page faults. DEMAND PAGING: Demand paging is a technique used to implement the concept of virtual memory. It combines the concept of paging and swapping. Whenever a process is to be executed, it is brought into the main memory. In demand paging, only those pages of the process are brought into the memory that are required. All other pages reside on secondary storage and are brought into the memory when needed. This task of bringing in and out the various pages is done by pager. This concept is called demand paging because the page is not loaded into the memory until it is not required.
PURE DEMAND PAGING:
It is the form of demand paging in which not even single page is loaded into the memory, initially. Thus very first instruction causes a page fault in this case as it is not residing in main memory. This kind of demand paging may significantly decrease the performance of a computer system. PAGE REPLACEMENT ALGORITHMS: When a page fault occurs, the operating system has to choose a page to remove from memory to make space for that page to be brought in. If the page to be removed has been modified in memory, it must be rewritten to the disk to bring the disk copy up-to-date. Thus page replacement algorithm is the logic or the policy regarding how to select a page to be swapped out from main memory to create a space for the page that has caused a page fault. OPTIMAL PAGE REPLACEMENT ALGORITHM: This algorithm considered as the best page replacement algorithm in a virtual memory. This algorithm is also called OPT or MIN. In this algorithm, we replace a page that will not be used for longer period of time. The page which is not used for longer period of time is swapped out from the main memory to create space for the requested page.
Advantages of optimal page replacement:
It has the lowest rate of occurrence of page faults. It improves the system performance by reducing overhead for numbering of page faults and swapping pages in and out, when a page fault occurs. Disadvantages of optimal page replacement: It is difficult to implement because it requires future knowledge of the reference string. First-in First out (FIFO) page replacement algorithm: It is simplest page replacement algorithm and associates with each page the time when that page was brought into memory. In this algorithm, whenever a page is to be replaced, the oldest page is chosen it means the page is swapped out which has been in the main memory for longest period of time. It is implemented by creating FIFO queue that holds all pages in memory. The page at the head of the queue is replaced and when a page is brought into memory, it is inserted at the tail of the queue. The main difference between FIFO and OPT algorithm is that FIFO algorithm uses the time when a page was brought into the memory. The OPT algorithm uses the time when a page is to be used. ADVANTAGES OF FIFO PAGE REPLACEMENT: It is simple and easy to implement. It can be easily coded. DISADVANTAGES OF FIFO PAGE REPLACEMENT: It replaces heavily used pages. It suffers from belady’s anomaly. Belady’s anomaly: When number of page frames allocated to a process is increased, the number of page faults also increases.
Least recently used (LRU) page replacement algorithm:
This algorithm uses information about the pages accessed in recent past to predict near future. In this algorithm, whenever a page is to be replaced, we select the page that has not been used for the longest period of time. This algorithm keeps track of the last time each page was used. Thus, LRU algorithm is based on the strategy of looking backward in time.
Implementation of LRU page replacement:
1. Using Counters: In this method a counter or clock is used. Whenever a reference to a particular page is made, its counter is incremented. The LRU algorithm searches the page table for entry with lowest counter value and selects that page for replacement. 2. Using Matrix: On a system with n page frames, an n*n matrix can be used to implement LRU algorithm. The matrix is initialized to contain all 0’s. When a page frame k is accessed, all bits in row k are set to 1. Then all bits in column k are set to 0. At any instant, the row whose binary value is least recently used, the row whose value is next lowest is next least recently used and so on. 3. Using Linked list: Whenever a page frame is referenced, the entry for that page is placed at the head of the list. Older entries move towards tail of the list. Whenever a page is to be replaced, the entry at the tail of the list is selected for replacement. Advantages of LRU page replacement: It does not suffer from belady’s anomaly. It is less complicated. Disadvantages of LRU page replacement: It requires expensive hardware. It requires additional data structure such as linked list to implement. Least Frequently used (LFU) page replacement algorithm: It is the approximation of LRU algorithm. A counter is used to count the number of references that have been made to each page. Whenever a page is to be replaced, that page is chosen that is least frequently used or least intensively referenced. Most frequently used (MFU) page replacement algorithm: it is the reverse of LFU. This algorithm is also an approximation of LRU and uses a counter to count the number of references made to each page. Whenever a page to be replaced that page is chosen which has been used most frequently. Not frequently used (NFU) page replacement algorithm: NRU is an approximation of LRU. The page in the lowest number group should be replaced first and those in the highest numbered groups should be replaced last. Pages within a group are selected randomly for replacement. Second chance page replacement algorithm: It is the combination of LIFO and NRU algorithm. In this algorithm, the page present for the longest time in the memory is given second chance to remain loaded in the main memory. When a page is selected, its reference bit is checked. Clock page replacement algorithm: it is the variation of second chance page replacement algorithm. It uses a circular queue to contain all the pages in the form of a clock. It make use of a pointer to indicate the position of the page to be replaced. LOCALITY: Locality can be exhibited in two forms: 1. Temporal locality 2. Spatial locality Temporal locality: it means the storage locations referenced recently are likely to be referenced in the near future. Example: if weather is sunny at 3.PM, then there is a good chance that weather was sunny at 2.30PM and will be sunny at 3.30PM. Spatial locality: it means that storage references tends to be clustered so that once a location is referenced, it is highly likely that nearly locations will be referenced. Example: if it is sunny in one town, then it is likely to be sunny in nearby town. ALLOCATION ALGORITHM: There are two different methods of allocating frames: 1. Equal allocation 2. Proportional allocation Equal allocation: this allocation method divides the available page frames equally among all the processes Example: there are 93 frames and 5 processes. We can divide 18 frames to each of the 5 processes. The remaining 3 frames are used as free frame buffer pool. Proportional allocation: it divides the frame in proportion to the size of the process. It means memory is allocated to each process according to its size. Global versus local allocation: 1. Global replacement: in this, the replacement frame selected by a process can be any frame from the set of all frames. In this strategy, one process can take frames from another process. 2. Local replacement: in this, the replacement frame selected by a process can only be from the set of frames which are allocated to it. the process cannot select the frame which is currently allocated to other process.