You are on page 1of 7

Lovely Professional University

Department of CA
HOMEWORK-1

Homework Title/No: 1 Course


Code: CAP 316
Course Instructor: Lect.Ms.Deepti Mam Course Tutor (if applicable): NA
Date of Allotment: 03/04/2010 Date of submission: 16/04/2010
Student’s Roll Number: RE3902A29 Section No.: E3902

Declaration:
I declare that this assignment is my individual work. I have not copied
from any other student’s work or from any other source except where due
acknowledgement is made explicitly in the text, nor has any part been written for me by
another person.

Student’s Sign:
AMAR SINGH

Evaluator’s Comments: ___________________________________________________

Marks obtained ____________ out of ___________ _______


PART A

1Q.a) “External Fragmentation can be reduced using the technique of Compaction


but it suffers from the overhead to be incurred to perform compaction. Moreover,
at certain times, compaction might not be possible and/or economical.” Suggest
some alternative solution to the problem of external fragmentation and analyze it.
Ans:- :- Solution for problem of external fragmentation is Compaction.
Compaction:- The compaction technique shuffles the memory contents so as to place all
free memory together in one large block.
The goal is to shuffle the memory contents to place all free memory together in
one large block. Compaction is not always possible. If relocation is static and is done at
assembly or load time, Compaction is not always possible. If relocation is static and is done at
assembly or load time, compaction cannot be done: compaction is possible only if relocation is
dynamic, and is done at execution time. If addresses are relocated dynamically, relocation
requires only mo0ving the program and data, and then changing the base register to reflect the
new base address. When compaction is possible, we must determine its cost.
The simplest compaction algorithm is simply to move all processes toward one end
of memory; all holes move in the other direction, producing one large hole of available
memory. This scheme can be expensive.
An other possible solution of external fragmentation is tp permit the logical-
address space of a process to be noncontiguous, thus allowing a process to be allocated physical
memory wherever the latter is available.
The alternative solutions to the External fragmentation is:
 First Fit
 Best Fit
 Next Fit
 Worst Fit
Two techniques does achieve this solution and they are:-

a). Paging
B). Segmentation

Paging
Paging is a memory management scheme that permits the physical address space of a processs
to be noncontiguous. Paging avoids the considerable problem of fitting memory chunks of
varying sizes onto the backing store; most memory management schemes used before the
introduction of paging suffered from this problem. The problem arises because, when some
code fragmentation or data residing in main memory need to be swapped out, space must be
found on the backing store. The backing store also has the fragmentation problems discussed in
connection with main memory, except that access is much slower, so compaction is impossible.
Because of its advantages over earlier methods. Traditionally support for paging has been
handled by hardware, however recent designs have implemented paging by closely integrating
the hardware and operating system.

Segmentation
An important aspect of memory management that became unavoidable with paging is the
separation of the user’s view of memory and the actual physical memory. Segmentation is a
memory management scheme that supports this user view of memory. A logical address space
is a collection of segments. Each segment has a name and a length. The addresses specify both
the segment name and the offset within the segment. The user therefore specifies both each
address by two quantities: a segment name and an offset. For simplicity of implementation,
segments are numbered and are referred to by a segment number, rather than by a segment
name. thus, a logical address consist of two tuple:
<segment-number, offset>.

b) Assume that an OS implementing MVT has batch processes arriving in order


with following request for storage: 20K, 30K, 10K, 100K, and 60K. There are 4
holes of size 50K, 30K, 200K, 16K, and 30K in memory. Where would each of the
first fit and the worst fit algorithms place the processes in memory?
Ans:-
First fit algorithm:-
a. 20k will put into 60k
b. 30k will put into 200k
c. 10k will put into 40k(where 40=60-20)
d. 100k will put into 170k hole (where 170=200-30)
e. 60k will have to wait.

Worst fit algorithm:-


a. 20k will put into 200k
b. 30k will put into 50k
c. 10k will put into 30k
d. 100k will put into 180k (where 180=200-20)
e. 60k will have to wait.
2 A system uses multi-programming with variable no. of tasks, with a memory of
110K for user processes. Draw the memory map corresponding to the current
memory allocation table:
A new job D arrives needing 15K of memory. Show the memory allocation table
entry for job D using each the allocation strategy of first fit, best fit and worst fit.

3Q : Suppose a fixed partitioning memory system with partitions of


100K, 500K, 200K, 300K and 600K (in memory order) exists with all 5
partitions currently unused (or free).
a) Using the best fit algorithm, show the state of memory after
processes of 212K, 417K, 112K and 350K (in request order) arrive.
b) Using the best available algorithm, show the state of memory after processes of
212K, 417K, 112K and 350K (in request order) arrive.

Ans:-The best available algorithm is best fit rather than first fit and
worst fit because in best fit algorithm there is less internal fragmentation
as compared to other available algorithms. If the processes come in the
order given above then the state of processes is same as that of part a.
c) Compute the total internal fragmentation for part (a), if any.
Ans:- the total internal fragmentation is given below:
500k-417k=83k
200k-112k=88k
330k-212k=118k
600k-350k=250k
Thus the total internal fragmentation is 539k

d) Compute the total external fragmentation for part (b), if any.


Ans:- There is no external fragmentation because, in fixed partitioning
there is only the internal fragmentation, no external fragmentation at all.

PART B

Consider a logical address space of 8 pages of 1024 bytes each, mapped onto a
physical memory of 32 frames. Determine the no. of bits in the logical address and
that in physical address.
5 Consider the page reference string: 0, 1, 7, 0, 1, 2, 0, 1, 2, 3, 2, 7, 1, 0, 3, 1, 0, 3.
Calculate the total no. of page faults (with no pre-paging at all) using OPT, FIFO, LRU
and Clock algorithms such that 3 frames are allocated to the process.
Ans:-
Reference String

0 1 7 0 1 2 0 1 2 3 2 7 1 0 3 1 0 3
0 0 0 3 3 3 0 0
1 1 1 2 2 2 3
7 7 7 1 1 1

6 A virtual memory system exhibits the follow trace of page nos. as:
1,2,3,2,6,3,4,1,5,6,1,6,4,2. Simulate the page replacements for the following
scenarios:

a) FIFO with 3 page frames

b) FIFO with 4 page frames

Determine the total no. of page faults for each. State whether Belady’s anomaly
occurs?

Ans:-
a) FIFO with 3 page frames:

1 2 3 2 6 3 4 1 5 6 1 6 4 2

1 2 3 3 6 6 4 1 5 6 6 6 4 2
1 2 2 3 3 6 4 1 5 5 5 6 4
1 1 2 2 3 6 4 1 1 1 5 6

Here Total Number of page faults = 8

b) FIFO With 4 page Frames:

1 2 3 2 6 3 4 1 5 6 1 6 4 2

1 2 3 3 6 6 4 1 5 5 5 5 5 2
1 2 2 3 3 6 4 1 1 1 1 1 5
1 1 2 2 3 6 4 4 4 4 4 1
1 1 2 3 6 6 6 6 6 4

Here Total Number of page Faults = 10


The above charts are the algorithm by Belady’s Anomaly. According to Belady’s
Anomaly the When more frames are allotted to a process(to accommodate more pages of
the process), it generates more page faults whereas it should be the other way round.

as it should be the other way round.