socsams e-learning dept. of computer applications, mes college marampally virtualmemory

19
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally VIRTUAL VIRTUAL MEMORY MEMORY

Upload: nigel-underwood

Post on 04-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

VIRTUALVIRTUAL

MEMORYMEMORY

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

IntroductionIntroduction

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

OverlayingOverlaying

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

Virtual Memory – overviewVirtual Memory – overview

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

Virtual Memory – overviewVirtual Memory – overview

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

Virtual Memory – overviewVirtual Memory – overview

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

Demand PagingDemand Paging

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

Demand PagingDemand Paging

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

Demand PagingDemand Paging

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

Demand PagingDemand Paging

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

Demand PagingDemand Paging

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

Demand PagingDemand Paging

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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:

Demand Paging - Handing Page FaultDemand Paging - Handing Page Fault

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

1. Location for a free page frame in memory and allocation it

to the process.

2. Swaps the desired page into this allocated page frame.

3. 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.

Demand Paging - Handing Page FaultDemand Paging - Handing Page Fault

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

Demand Paging – page-inDemand Paging – page-in

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

• 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.

Demand Paging - AdvantagesDemand Paging - Advantages

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

COPY-ON-WRITECOPY-ON-WRITE

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

COPY-ON-WRITECOPY-ON-WRITE

SOCSAMS e-learning

Dept. of Computer Applications, MES College Marampally

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.

COPY-ON-WRITECOPY-ON-WRITE