1 / 19

VIRTUAL MEMORY

VIRTUAL MEMORY. Introduction. To execute a program, the entire process should be loaded into the main memory. Thus the size of the process is limited to the size of the physical memory. A memory management scheme called “Overlaying” can be used to overcome this situation. Overlaying.

von
Download Presentation

VIRTUAL MEMORY

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VIRTUAL MEMORY

  2. Introduction To execute a program, the entire process should be loaded into the main memory. Thus the size of the process is limited to the size of the physical memory. A memory management scheme called “Overlaying” can be used to overcome this situation.

  3. Overlaying The programmer splits a program into smaller parts called overlays in such a way that no two overlays are required to be in main memory at the same time. An overlay is loaded into memory only when it is needed. One major disadvantage of this technique is that it requires major involvement of the programmer and time consuming.

  4. Virtual Memory – overview Virtual memory is a technique that allows execution of a program that is bigger than the physical memory of the computer system. In this technique, the operating system loads only those parts of program in memory that are currently needed for the execution of the process. The rest part is kept in the disk and is loaded into memory only when needed.

  5. Virtual Memory – overview

  6. Virtual Memory – overview • Virtual memory gives the illusion that the system has a much larger memory than is actually available. • Virtual memory frees programs from the constraints of physical memory limitation. • The virtual memory can be implemented by: • Demand Paging. • Demand Segmentation.

  7. Demand Paging Demand paging is a system which a page is loaded into the memory only when it is needed during program execution. Pages that are never accessed are never loaded into the memory. A demand paging system combines the features of paging with swapping. To facilitates swapping, the entire virtual address space is stored contiguously on the disk.

  8. Demand Paging Whenever a process is to be executed, an area on the disk is allocated to it on which pages are copied, called swap space of the process. During the execution of a process, whenever a page is required, it is loaded into the main memory from the swap space. Similarly, when a process is to be removed from main memory, it is written back into the swap space if it has been modified.

  9. Demand Paging Other than swap space, some form of hardware support is also needed to differentiate the pages that are in memory from the ones on disk. For this, only an additional bit valid is maintained in each page table entry to indicate whether the page is in memory. If a page is valid, that is it exists in the virtual address space of the process, the associated valid bit is set to 1, otherwise it is set to 0.

  10. Demand Paging

  11. Demand Paging Whenever a process request for a page, the virtual address is sent to MMU. The MMU checks the valid bit in the page table entry of that page. If the valid bit is 1, it is access as in paging. Otherwise, the MMU raises an interrupt called page fault or a missing page interrupt and the control is passed to the page fault routine in the operating system.

  12. Demand Paging

  13. Demand Paging - Handing Page Fault To handle the page fault, the page fault routine first of all checks whether the virtual address for the desired page is valid from its PCB stored in the process table. If it is invalid, it terminates the process giving error. Otherwise, it takes the following steps:

  14. Demand Paging - Handing Page Fault Location for a free page frame in memory and allocation it to the process. Swaps the desired page into this allocated page frame. Update the process table and page table to indicate that the page is in memory. After performing these steps, the CPU restarts from the instruction that it left off due to the page fault.

  15. Demand Paging – page-in In demand paging, the process of loading a page in memory is known as page-in operation instead of swap-in. It is because the whole process is not loaded; only some pages are loaded into the memory.

  16. Demand Paging - Advantages • It reduces the swap time since only the required pages are swapped in instead of the whole process. • It increases the degree of multiprogramming by reducing the amount of physical memory required for a process. • It minimizes the initial disk overhead as not all pages are to be read initially. • It does not need extra hardware support.

  17. COPY-ON-WRITE A process may need to create several processes during its execution and the parent and child processes have their own distinct address spaces. If the newly created process is the duplicate of the parent process, it will contain the same pages in its address space as that of parent. In this case, copying the parent’s address space may be unnecessary. To avoid copying, copy-on-write – a virtual memory technique can be employed.

  18. COPY-ON-WRITE In this technique, initially, parent and child processes are allowed to share the same pages and these shared pages are marked as copy-on-write pages. Now, if either process attempts to write on a shared page, a copy of that page is created for that process. Only the pages that can be modified (containing data) are marked as copy-on-write pages while the pages that cannot be modified (containing executable code) are shared between parent and child processes.

  19. COPY-ON-WRITE To implement this, a bit is associated in page table entry of each shared page to indicate that it is a copy-on-write page. Whenever either process say, child process tries to modify a page, the operating system creates a copy of that page, maps it to the address space of the child process and turns off the copy-on-write bit. Now the child process can modify the copied page without affecting the page of the parent process. Thus, it saves memory.

More Related