Sunday, December 18, 2011

Virtual memory

Discuss need for Virtual Memory.

Virtual Memory Provides three important capabilities:

  1. It uses main memory efficiently by treating it as a cache for an address space stored on disk, keeping only active areas in main memory, and transferring data back and forth between disk and memory as needed.
  2. It simplifies memory management by providing each process with uniform adress space.
  3. It protects the address space of each process from corruption by other process.
VM system must have some way to determine if a virtual page is cached somewhere in DRAM. if so, the system must determine which physical page it is cached in. if there is a miss, the system must determine where the virtual page is stored on disk, select a victim page in physical memory, and copy the virtual page from Disk to DRAM, replacing the victim page. These capabilities are provided by a combination system software, address translation hardware in the MMU and a data structure stored in physical memory know as page tables that maps virtual pages to physical pages.

The combination of demand paging and separate virtual address space for each process has a profound impact on the way that memory is used and managed in a system. VM simplifies Linking and loading, sharing of code and data and allocating memory to applications.

Simplifies Linking and Loading: A seperate address space allows each process to use the same basic format for its memory image, regardless of where the code and data actually resides in physical memory.
Such uniformity greatly simplifies the design and Implementation of linkers, allowing them to produce fully linked executables that are independent of the ultimate location of code and data in physical memory.

Simplifying sharing: In general, each process has its own private code, data, heap and stack areas that are not shared with any other process. In this case operating system, creates a page table that map the corresponding virtual pages to disjoint physical pages. In some instance it is desirable for a process to share a code and data. For example, every process must call same operating system kernel. Rather than including separate copies of the kernel, the operating sytem can arrange for multiple process to share a single copy of this code by mapping appropriate virtual pages in different process to the same physical pages.

Simplyfying memory allocation:  When a program running a user process request additional heap space, the operating system allocates an appropriate number say k, of contiguous virtual memory pages, and maps them to k arbitrary physical pages located any where in physical memory. Because of way page table works, there is no need for the operating system to locate k contiguous pages of physical memory.

Simplifying loadingThe .data and .text sections in ELF executables are contiguous. To load these sections into newly created process, the Linux loader allocates a contiguous chunk of virtual pages starting at address 0x0804 8000, mark them as invalid and point their page table entries to the appropriate locations in the object file. The interesting point is that the loader never actually copies any data from disk into memory. The data is paged in automatically and on demand by virtual memory system the first time each page is referenced, either by the CPU when it fetches an instruction, or by an executing instruction when it reference a memory location.

Useful Links:
http://computer.howstuffworks.com/question684.htm
https://www.linux.com/news/software/applications/8208-all-about-linux-swap-space
https://secure.wikimedia.org/wikipedia/en/wiki/Virtual_memory

No comments:

Post a Comment