passhojao | home › ... › virtual+memory.docx · web viewvirtual memory is a space where large...

14
It is a technique that allows execution of processes which are not completely available in the memory. Virtual Memory is a space where large programs can store themselves in form of pages while their execution and only the required pages or portions of processes are loaded into the main memory. This technique is useful as large virtual memory is provided for user programs when a very small physical memory is there. We need to maintain entire image of the process in Disk Storage The main advantage of this scheme is program can be larger than the physical memory Benefits of having Virtual Memory 1. Large programs can be written, as virtual space available is huge compared to physical memory . 2. Less I/O required to load or swap each user program into memory leads to faster and easy swapping of processes.

Upload: others

Post on 26-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

It is a technique that allows execution of processes which are not completely available in the memory.

Virtual Memory is a space where large programs can store themselves in form of pages while their execution and only the required pages or portions of processes are loaded into the main memory. This technique is useful as large virtual memory is provided for user programs when a very small physical memory is there.

We need to maintain entire image of the process in Disk Storage

The main advantage of this scheme is program can be larger than the physical memory

Benefits of having Virtual Memory

1. Large programs can be written, as virtual space available is huge compared to

physical memory .

2. Less I/O required to load or swap each user program into memory leads to faster

and easy swapping of processes.

3. More physical memory available, as programs are stored on virtual memory, so they

occupy very less space on actual physical memory.

Page 2: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

4. Each user program could take less physical memory, more programs could be run

at the same time, with corresponding increase in CPU Utilization & throughput.

5. Logical address space is much larger than physical address space.

6. Error handling code is not needed unless that specific error occurs, some of which

are quite rare.

7. Certain features of certain programs are rarely used.

8. Arrays are often over-sized for worst-case scenarios, and only a small fraction of the

arrays are actually used in practice.

Page 3: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

Demang PagingThe basic idea behind demand paging is that when a process is swapped in, its pages are not swapped in all at once. Rather they are swapped in only when the process needs them(On demand). 

Demand Paging = Paging + Swapping

A page/process stays in secondary storage area which is disk in the form of pages & In this technique it is brought into the main memory(divided into frames) for execution when only it is demanded.The complete process should be in secondary storage area in the form of pages.

Secondary Storage = process is stored in the form of pagesMain memory = it is divided into frames

We have particular frames allocated for program A & B respectivelyWhenever the work of this page (A)is done it is swapped out & put back in secondary storage area ( disk) While swapping out it will leave the particular frame freeThe free page can hold the page of any other process alsoSuppose now (B) requires a page for the execution of its program , the particular frame will be swapped in the frame & this will make this frame unavailable for any page for the particular movement. ie now this frame will be occupied.This is how demand paging works.

->It is also known as the Lazy Swapper method because it swaps the pages only when it is needed.

Page 4: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

->We are not swapping in & swapping out the entire process, we are swapping only the part of the process ( which is the page). Hence swapping time is reduced->Many process can run in the main memory at a single point of time.

The only major issue with Demand Paging is, after a new page is loaded, the process starts execution from the beginning. Its is not a big issue for small programs, but for larger programs it affects performance drastically.

Page fault:

When the page(data) requested by the program is not available in the memory, it is called page fault. This usually results in the application being shut down.The term page fault is bit misleading as it implies something went seriously wrong . Although page faults are undesirable – as they results in slow access to the hard disk.They are quite common in any operating system that uses virtual memory.

Suppose process A is executed in main memory contains page no 1 & 2Now process A req. page no 3 , page no.3 is not present in the main memory so one page fault will occur at that particular point.Whenever there is a requirement of that particular page & that particular page is not present in the main memory, since it is not loaded form the disk into the main memory at that time. It is called as the page fault.

This page fault is used in the performance measurement.

Generally, As no. of pages increases page fault tends to decrease.Belady’s Anomaly:For some page replacement algo page fault may increase as no. of allocated frames increases.

Page 5: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

SWAPPING

Main Memory is limited We have ‘N’ no. of processes/jobs to be run in main memoryWe have jobs J1,J2----Jn that are waiting to be executed in the main memory

It is the process of swapping out or swapping in the processes/jobs from the disk to the physical memory & vice vera.Major part of swapping is total transfer time. It is directly propotional to the amount of memory.

A process needs to be in memory for execution. But sometimes there is not enough main memory to hold all the currently active processes in a timesharing system. So, excess process are kept on disk and brought in to run dynamically. Swapping is the process of bringing in each process in main memory, running it for a while and then putting it back to the disk.

Variations of swapping:

Backing store: Fast disk large enough to accommodate copies of all memory images for all users must provide direct access to these memory images.

Page 6: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

Following steps can be taken to deal with this problem :

Page 7: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

1. Put the process in the wait queue, until any other process finishes its execution thereby freeing frames.

2. Or, remove some other process completely from the memory to free frames.

3. Or, find some pages that are not being used right now, move them to the disk to get free frames. This

technique is called Page replacement and is most commonly used.

When page must be replaced the oldest page is choosen. Create FIFO to hold all the queues in the memory. We replace the page at the head of the queue.When page is brought into memory, we insert it at the tail of queue. FIFO algo. Is easy to understand & perform. Hence its performance is not always good.

Belady’s Anomaly:It is also known as FIFO Anomaly.uaually, As no. of pages increases page fault tends to decrease.

Page 8: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

Butsometimes reverse happens ie. For some page replacement algo page fault may increase as no. of allocated frames increases. This is true for certain page reference pattern.Eg: with frame 3 page fault =9 with frame 4 page fault =10

This is considered as one of the best page replacement algo. Because of the lower number of faults.

It considers looking forward in time. Looks for the pages in future It is very difficult to implement

Page 9: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

It is like optimal page replacement algo. Looking backward in time rather than forward. Gives less no. of page faults compared to FIFO Less Speed than FIFO

Page 10: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

Thrashing

Thrashing is high paging activity.It is the situation which is very common phenomenon in the virtual memory of operating system.

A process that is spending more time paging than executing is said to be thrashing.

In other words it means, that the process doesn't have enough frames to hold all the pages for its execution, so it is busy swapping pages in and out very frequently to keep executing. Sometimes, the pages which will be required in the near future have to be swapped out.

If a process does not have enough pages for execution then a page fault will occur. This page fault will leads to certain problems in the operating system.

For ‘N’ number of processes page fault rate will increase exponentially & there will be a time when the degree of multiprogramming/ CPU Utilization will decrease to almost zero when the no. of page faults will increase.

Page 11: PassHoJao | Home › ... › Virtual+memory.docx · Web viewVirtual Memory is a space where large programs can store themselves in form of pages while their execution and only the

To prevent thrashing we must provide processes with as many frames as they really need "right now".

Caused by: Very high degree of multiprogramming Global replacement algorithm Under allocation of the minimum no. of pages req. by process.

Eliminated by: reducing degree of multiprogramming use local replacement algorithm while allocating check minimum sufficient frame required for the process.