## Numerical Solved by Least Recently Used Page Replacement Algorithm

Q1. If the reference string is

7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3,

we have taken the physical memory of three frames, then solve by Least Recently Used Page Replacement Algorithm.

Ans.

 7 0 1 2 0 3 0 4 2 3 0 3 Frame1 7 7 7 2 2 2 2 4 4 4 0 0 Frame2 0 0 0 0 0 0 0 0 3 3 3 Frame3 1 1 1 3 3 3 2 2 2 2 Faults + + + + + + + + +

Page Fault = 9 (better than FIFO)

## Numerical-I Solved For Belady’s Anomaly Problem

Q1. If the reference string is

0 1 2 3 0 1 4 0 1 2 3 4

then solve by First In First Out Disk Scheduling Algorithm using physical memory of three frames and four frames.

The below figure shows how with 3 frames the number of page faults are 9 while we get 10 page faults with 4 frames.

 7 0 1 2 0 3 0 4 2 3 0 3 Frame1 7 7 7 2 2 2 2 4 4 4 0 0 Frame2 0 0 0 0 3 3 3 2 2 2 2 Frame3 1 1 1 1 0 0 0 3 3 3 Faults + + + + + + + + + + +

Page faults = 9 (3 frames)

 0 1 2 3 0 1 4 0 1 2 3 4 Frame1 0 0 0 0 0 0 4 4 4 4 3 3 Frame2 1 1 1 1 1 1 0 0 0 0 4 Frame3 2 2 2 2 2 2 1 1 1 1 Frame4 3 3 3 3 3 3 2 2 2 Faults + + + + + + + + + +

Page faults = 4 (4 frames)

## Numerical Solved By First In First Out Disk Scheduling

Q1. If the reference string is

7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3,

we have taken the physical memory of three frames, then solve by First Come First Serve Disk Scheduling Algorithm.

Solu:

 7 0 1 2 0 3 0 4 2 3 0 3 Frame1 7 7 7 2 2 2 2 4 4 4 0 0 Frame2 0 0 0 0 3 3 3 2 2 2 2 Frame3 1 1 1 1 0 0 0 3 3 3 Faults + + + + + + + + + + +

Page Fault = 10

## Use of Page Replacement Algorithm

Q2. What is the Use of Page Replacement Algorithm?

Ans. If total memory requirement exceed the physical memory than it may be necessary to replace pages from memory for free space for new pages, various page algorithm are used.

## Demand Segmentation

Q1. Explain Demand Segmentation.

Ans. Operating system also uses demand segmentation, which is similar to demand paging. Operating system to uses demand segmentation where there is insufficient hardware available to implement ‘Demand Paging’.

The segment table has a valid bit to specify if the segment is already in physical memory or not. If a segment is not in physical memory then segment fault results, which traps to the operating system and brings the needed segment into physical memory, much like a page fault.

Demand segmentation allows for pages that are often referenced with each other to be brought into memory together, this decreases the number of page faults.

Another space server would be to keep some of a segment’s page tables on disk and swap them into memory when needed.

## Explain Virtual Memory

Q1. Explain Virtual Memory.

Ans. Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory, while in fact it may be physically fragmented and may even overflow on to disk storage.

The basic idea behind virtual memory is that the combined size of the program, data and stack may exceed the amount of physical memory available for it. The operating system keeps those parts of the program currently use in main memory and the rest on the disk.

For example:

A 16 MB program can run on a 4 MB machine by carefully choosing which 4 MB to keep in main memory at each instance, with pieces of the program being swapped between disk and memory as needed.

## Paging

Q1. Explain Paging.

Ans. Logical address space of a process can be non continuous. Process is allocated physical memory whenever the address is available.

Dividing physical memory into fixed-sized blocks is called frames.

Dividing logical memory into blocks of the same size is called pages.

It keeps track of all free frames.

To run a program of size ‘n’ pages, need to find ‘n’ free frames and load program.

Setup a page table to translate logical to physical address.

## Sharing of Memory

Q3. Explain Sharing of Memory.

Ans. Each process has a segment table associated with it, which the dispatcher uses to define the hardware segment table when this process is given the CPU. Segments are shared when entries in the segment table of two different processes point to the same physical location.

Figure: Sharing of Memory

P1

 Segment Limit Base 0 1000 1400 1 400 2400

P2

 Segment Limit Base 0 1000 1400 1 400 4300

Figure: Physical Memory