Professional Documents
Culture Documents
Merged
Merged
Instructor:
Dr. F. Lalchhandama
P1 P2 P3
Q. Draw a resource-allocation graph for the above and find out whether there exist a cycle or not.
If yes, how many cycles are present and state with reason whether a deadlock can occur or not?
Instructor:
Dr. F. Lalchhandama
R1
R2
P1 P2 P3 P2
R3
R4
P3 Wait-for graph
• Steps:
• Avail = [0 0]
1. P3 releases R2
• Steps:
• Avail = [0 0]
1. P3 releases R2
Avail = [0 0] + [0 1] = [0 1]
• Steps:
• Avail = [0 1]
2. R2 --> P1, P1 releases R1
Avail = [0 1] + [1 0] = [1 1]
• Steps:
• Avail = [1 1]
3. R1 --> P2, P2 releases R2
Avail = [1 1] + [0 1] = [1 2]
• Steps:
• Avail = [1 2]
No deadlock. Safe sequence is {P3, P1, P2}
4M
6M
Memory
P1 14M P2 2M P3 11M P4 8M 8M
Queue 10M
12M
16M
4M
6M
Memory
P1 14M P2 2M P3 11M P4 8M P4 8M
Queue 10M
P3 11M
P1 14M
4M
6M
Memory
P1 14M P2 2M P3 11M P4 8M P4 8M
Queue 10M
P3 11M
Internal P1 14M
Fragmentation
School of Engineering, Jawaharlal Nehru University
Contiguous Memory Allocation
• Variable-Size Partition Scheme
• Also known as dynamic partitioning
• Partitions are of variable size
• Partition size is not declared initially
• Whenever any process arrives, a partition of equal size to the size of
the process is created and then allocated to the process
• Size of the partition is equal to the size of the process
• Eventually, we have holes in the memory – external fragmentation
P2 8M
P1 20M P2 8M P3 20M P4 2M
P3 20M
P4 2M
External
Fragmentation
• When a process is to be executed, its pages are loaded into any available
memory frames from their source (a file system or the backing store)
• The backing store is divided into fixed-size blocks that are the same size as
the memory frames or clusters of multiple frames
School of Engineering, Jawaharlal Nehru University
Paging
physical
Fig. Paging model of logical and physical memory memory
Paging 4 i
j
k
l
8 m
n
0 a
o
1 b p
2 c 0 5
3 d 12
1 6
4 e
5 f 2 1
6 g
16
7 h 3 2
8 i
9 j Page table
10 k 20 a
11 l b
c
12 m d
13 n
14 o 24 e
15 p f
Physical memory g
h
Logical memory 28
3 d 12
1 6 Frame 3
4 e
5 f
Physical
Page 1 2 1
6 g addresses 16
7 h 3 2
8 i
Frame 4
9 j
Page 2 Page table
Logical 10 k 20 a
11 l b
addresses c
Frame 5
12 m d
13 n
14 o Page 3 24 e
f
15 p
g
Frame 6
Physical memory h
Logical memory 28
Frame 7
Logical memory
3 d 12
1 6 Frame 3
4 e
5 f
Physical
Page 1 2 1
6 g addresses 16
7 h 3 2 32-byte
Frame 4
8 i memory
9 j
Page 2 Page table
Logical 10 k 20 a
11 l b
addresses c
Frame 5
12 m d
13 n
14 o Page 3 24 e
f
15 p
g
Frame 6
Physical memory h
Logical memory 28
Frame 7
Logical memory
So, no. of bits required to represent the frame = Frame number = 14 bits
Therefore, page table size = 220 x 14 bits ≈ 220 x 16 bits = 220 x 2 Bytes = 2 MB
CPU
p1 p2 p3 d
f d
Main
Memory
EMAT = p x s + (1 – p) x m
7 7
0
7 7 7
0 0
1
7 7 7
0 0
1
7 7 7 2 2
0 0 0 0
1 1 1
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2
0 0 0 0
1 1 1
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 2
0 0 0 0 3
1 1 1 1
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 2
0 0 0 0 3
1 1 1 1
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 2 2
0 0 0 0 3 3
1 1 1 1 0
7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 7 7 7
0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 0 0
1 1 1 1 0 0 0 3 3 3 3 3 2 2 2 2 2 1
7 7 7 2 2 2 2 4 4 4 0 0 0 0 0 0 0 7 7 7
0 0 0 0 3 3 3 2 2 2 2 2 1 1 1 1 1 0 0
1 1 1 1 0 0 0 3 3 3 3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