Memory Management Part2
Memory Management Part2
MEMORY MANAGEMENT
PART 2
3.3 Paging
2
Logical Physical
In paging,
memorthe OS PAGE TABLE memory
ydivide the
physical memory
page frame Attributes
into frames which
are blocks of 0 4
small and fixed 1 3
size 2 1
3 5
3.3 Paging
3
Logical Physical
In paging,
memorthe OS PAGE TABLE memory
ydivide the
physical memory
P0 whichpage
into frames
frame Attributes f0
P1
are blocks of 0 4 f1
smallP2
and fixed 1 3 f2
size 2 1
P3 f3
3 5 f4
f5
3.3 Paging
4
Logical Physical
memor OS divides
PAGE TABLEalso the memory
y logical memory
(program) into
page frame Attributes
pages which are f0
0 4
blocks of size f1
1 equal
3 to frame
f2
size.
2 1 f3
3 5 f4
f5
3.3 Paging
5
Logical Physical
memor OS divides
PAGE TABLEalso the memory
y logical memory
(program) into
P0 page frame Attributes
pages which are f0
P1 0 4
blocks of size f1
1 equal
3 to frame
P2 f2
size.
P3 2 1 f3
3 5 f4
f5
3.3 Paging
6
Logical Physical
memor PAGE TABLE memory
y
P0 page frame Attributes f0
P1 0 4 f1
P2 1 3 f2
P3 2 1 f3
3 5 f4
f5
Logical Physical
memor PAGE TABLE memory
y
P0 page frame Attributes f0
P1 0 4 f1
P2 1 3 f2
P3 2 1 f3
3 5 P0 f4
f5
Logical Physical
memor PAGE TABLE memory
y
P0 page frame Attributes f0
P1 0 4 f1
P2 1 3 f2
P3 2 1 P1 f3
3 5 P0 f4
f5
Logical Physical
memor PAGE TABLE memory
y
P0 page frame Attributes f0
P1 0 4 P2 f1
P2 1 3 f2
P3 2 1 P1 f3
3 5 P0 f4
f5
Logical Physical
memor PAGE TABLE memory
y
P0 page frame Attributes f0
P1 0 4 P2 f1
P2 1 3 f2
P3 2 1 P1 f3
3 5 P0 f4
P3 f5
Logical Physical
memor PAGE TABLE memory
y
P0 page frame Attributes f0
P1 0 4 P2 f1
P2 1 3 f2
P3 2 1 P1 f3
3 5 P0 f4
P3 f5
p is page number
p = logical address div S
d is displacement (offset)
Logical Physical
address address
p d f d
p f
logical physical
memory memory
3.3 Paging
16
Example 3.2
Consider the following information to form a
physical memory map.
Page Size = 8 words d : 3 bits
Physical Memory Size = 128 words
= 128/8=16 frames f : 4 bits
Assume maximum program size is 4 pages p :
2 bits
A program of 3 pages where P0 f3; P1 f6;
P2 f4
Logical memory Physical
memory
17 Word 0 … …
Word 1 Page 0 Word 0
… (P0) Word 1 Frame 3
Word 7 PAGE … (f3)
TABE
Word 8 Page Frame Word 7
Word 9 Page 1 0 3 Word 16
… (P1) 1 6 Word 17 Frame 4
Word 15 2 4 … (f4)
Word 16 Word 23
Word 17 Page 2
… (P2) … …
Word 23
Word 8
Word 9 Frame 6
… (f6)
Word 15
3.3 Paging
18
Program
Line
Word 0
Word 1
…
Word 7
Word 8
Word 9
…
Word 15
Word 16
Word 17
…
Word 23
3.3 Paging
19
Program Logical
Line Address
Word 0 00 000
Word 1 00 001
… …
Word 7 00 111
Word 8 01 000
Word 9 01 001
… …
Word 15 01 111
Word 16 10 000
Word 17 10 001
… …
Word 23 10 111
3.3 Paging
20
p d
physical address
access
YES f d access
PT in
P<PTLR registe memor
rs y
NO rat mat
ERROR
ERROR
emat=mat+mat=2mat
Use content-addressable associative
registers
29
mat mat
rat=30 ns
mat=470ns
h=0.9
Use content-addressable associative
registers
32
Example 3.4
45
main
For example, a C compiler may create segments for:
the code of each function
Func 1
the local variables for each function
Func 2
main
Data 1
Func 1 Func 2
Data 2
Data 1 Data 2
Data 3
Data 3
47
ERROR
Logical address No
s d 0≤d base
<limit
Segment Table
segment s
d
Yes
acess
seg. # the word at
limit base attr
physical
address
= base + d
Physical memory
3.4 Segmentation
48
Example 3.5
Generate the memory map according to
the given segment table. Assume the
generated logical address is <1,1123>;
find the corresponding physical address.
Segment Limit Base
0 1500 1000
1 200 5500
2 700 6000
3 2000 3500
0
3.4 Segmentation OS
49
s3 2000
5500
s1 200
5700
6000
s2 700
6700
Physical memory
0
3.4 Segmentation OS
50
s3 2000
5500
Logical address: <3,1123> s1 200
s=3, d=1123 5700
Check if d<limit? 1123<2000, OK 6000
Physical address= base+d=3500+1123=4623 s2 700
6700
Physical memory
0
3.4 Segmentation OS
51
s3 2000
5500
Logical address: <3,1123> s1 200
s=3, d=1123 5700
Check if d<limit? 1123<2000, OK 6000
Physical address= base+d=3500+1123=4623 s2 700
6700
Physical memory
0
3.4 Segmentation OS
52
Physical memory
3.4 Segmentation
53
Sharing Segments OS
54
user1 ST1
Editör seg lim base 1000
s0
0 1500 1000 Editör 1500
s1 Data-1 1 2000 3500
2500
3500
Data-1 2000
5500
Physical memory
0
Sharing Segments OS
55
user1 ST1
Editör seg lim base 1000
s0
0 1500 1000 Editör 1500
s1 Data-1 1 2000 3500
2500
Physical memory
0
Sharing Segments OS
56
user1 ST1
Editör seg lim base 1000
s0
0 1500 1000 Editör 1500
s1 Data-1 1 2000 3500
2500
Sharing Segments OS
57
user1 ST1
Editör seg lim base 1000
s0
0 1500 1000 Editör 1500
s1 Data-1 1 2000 3500
2500
3500
User 2 terminates:
Data-2 removed Data-1 2000
from memory, but
editör remains.. 5500
Sharing Segments OS
58
user3 6000
ST3 700
s0 Editör Data-3
seg lim base 6700
0 1500 100
s1 Data-3
1 700 6000 Physical memory
0
Sharing Segments OS
59
Physical memory