Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

5 – Memory Management

 The basic idea behind virtual memory is that each program has its own address
space, which is broken up into pages.
 Each page is a contiguous range of addresses.
 These pages are mapped onto the physical memory but, to run the program, all
pages are not required to be present in the physical memory.
 The operating system keeps those parts of the program currently in use in main
memory, and the rest on the disk.
 Virtual memory works fine in a multiprogramming system, with bits and pieces of
many programs in memory at once.
 While a program is waiting for part of itself to be brought in, it is waiting for I/O and
cannot run, so the CPU can be given to another process.
 In a system using virtual memory, the physical memory is divided into page frames
and the virtual address space is divided in into equally-sized partitions called pages.

(5) What is paging? Explain the conversion of virtual address in paging with example.
Paging
 The program generated address is called as Virtual Addresses and form the Virtual
Address Space.
 Most virtual memory systems use a technique called paging.
 Virtual address space is divided into fixed-size partitions called pages.
 The corresponding units in the physical memory are called as page frames.
 The pages and page frames are always of the same size.
 Size of Virtual Address Space is greater than that of Main memory, so instead of
loading entire address space in to memory to run the process, MMU copies only
required pages into main memory.
 In order to keep the track of pages and page frames, OS maintains a data structure
called page table.
The conversion of virtual address to physical address
 When virtual memory is used, the virtual address is presented to an MMU (Memory
Management Unit) that maps the virtual addresses onto the physical memory
addresses.
 A very simple example of how this mapping works is shown in Fig. 5-6.
 In this example, we have a computer generated 16-bit addresses, from 0 up to 64K.
These are the virtual addresses.

Gopi Sanghani, CE Department | 2140702 – Operating System (2015-16) 7


5 – Memory Management
 However, only 32 KB of physical memory is available, so although 64-KB programs
can be written, they cannot be loaded in to memory in their entirety and run.
 A complete copy of a program’s core image, up to 64 KB, must be present on the
disk. Only required pages are loaded in the physical memory.

Figure 5-5. The relation between virtual addresses and physical memory addresses is
given by the page table.

 With 64 KB of virtual address space and 32 KB of physical memory, we get 16 virtual


pages and 8 page frames.
 Transfers between RAM and disk are always in units of a page.
 The virtual address is split into a virtual page number (high order bits) and an offset
(low-order bits).
 With a 16-bit address and a 4 - KB page size, the upper 4 bits could specify one of
the 16 virtual pages and the lower 12 bits would then specify the byte offset (0 to
4095) within the selected page.
 The virtual page number is used as an index into the Page table.
 If the present/absent bit is 0, it is page-fault; a trap to the operating system is
caused to bring required page into main memory.
 If the present/absent bit is 1, required page is there with main memory and page

Gopi Sanghani, CE Department | 2140702 – Operating System (2015-16) 8


5 – Memory Management
frame number found in the page table is copied to the higher order bit of the output
register along with the offset.
 Together Page frame number and offset creates physical address.
Physical Address = Page frame Number + offset of virtual address.

Figure 5-6. The internal operation of the MMU with 16 4-KB pages.

(6) Explain page table in brief. OR


Explain Structure of Page Table.
Page Table
 Page table is a data structure which translates virtual address into equivalent
physical address.
 The virtual page number is used as an index into the Page table to find the entry for
that virtual page and from the Page table physical page frame number is found.
 Thus the purpose of page table is to map virtual pages onto page frames.
 Typical fields of page table are Page frame number, Present / absent bit, Protection
Gopi Sanghani, CE Department | 2140702 – Operating System (2015-16) 9

You might also like