Professional Documents
Culture Documents
Chapter 3 Memory Management
Chapter 3 Memory Management
05/16/2024 F.
1
Contents
o f
o se
u rp
p
the
s
Department of Computer Science, School of Computing |DDUIoT at’ g?
Operating System byhKidanemariam
05/16/2024 F. W din 5
in
Address Binding(con’t…)
o Address binding of instructions and data to memory
addresses can happen at three different stages.
–Compile time:
» If memory location is known a prior, absolute
code can be generated; must recompile code if
starting location changes.
–Load time:
» Must generate re-locate-able code if memory
location is not known at compile time.
–Execution time:
»Binding delayed until run-time if the process can be
moved during its execution from one memory segment e of
p os
to another p ur
the
»Need hardware support for maps (e.g. basehat’and s
g ? limit
W di n
registers). bin
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
05/16/2024 F.
6
Logical vs. Physical Address Space
o T
h
e
c
o
n
c
e
p
t
l
ca
o
gi
lo
f
n
ee
? tw
es be
a
re nce
dd re
ss
l a iffe
ica d
l
ys e
ph th
o
d t’s
an ha
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
W
05/16/2024 F.
7 g
Swapping
p
r
o
c
e
s
s
i
s
c
o
n
t
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam a
05/16/2024 10
F. i
Contiguous Allocation(con’t…)
OS OS OS OS
Process 5 Process 5 Process 5 Process 5
Process 9 Process 9
Process 8 Process 10
Process 1
Input Queue )KB 7( 10
(in the disk) KB
KB 4 KB 8 KB 9 KB 7
Process 2
)KB 9( 10
KB
Internal Process 3
Fragmentation )KB 8( 10
KB
As shown
• This method suffers from internal fragmentations.
• The degree of multiprogramming is bounded to 3 although it
can beDepartment
4. of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
05/16/2024 F.
16
Dynamic Partitioning
• Partitions are of variable length and number
• Initially, all memory is available for user processes,
and is considered as one large block of available
memory.
Process 3
)KB 8(
OS
Base 999
1000
Start 1040 1010
address of Process
process 20
Legal range 1040
Limit
Process
1060
1070
Executable file
(Size =20 Process
memory words) 1100
1125
Process
1150
Loader 1200
Process
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
1250
05/16/2024 F.
20
1255
Memory
Using Best Fit
OS
Base 1000
Start 1100 1010
address of Process
process 20
Legal range 1040
Limit
1070
Executable file
(Size =20 Process
memory words) 1100
Process
1120
1125
Process
1150
Loader
1200
Limit
1070
Executable file
(Size =20 Process
memory words) 1100
1125
Process
1150
Process
1170
Loader
1200
OS
Process 4
Input Queue
(in the disk) Process 2
KB 4 KB 8 KB 9 KB 7
Process 3 External
Fragmentations
Process 9
Process 20
As shown:
dynamic partition is suffered from external Fragmentations.
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
05/16/2024 F.
24
Compaction
OS
Process 4
Process 4
Input Queue
(in the disk)
Process 2
Process 2
Process 3
KB 4 KB 8 KB 9 KB 7
Process 3
Process 9
Process 9
Process 20
Process 20 A new hole to store a
Compaction: new process
Is a movement of the memory contents to place all free memory in a one large
block sufficient to store new process.
It is a solution for the external fragmentation but it is expensive and is not always
possible.
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
05/16/2024 F.
25
Paging and Segmentation
p d
n
r
o th r a
use
Since units are managed in terms of pages 31 pages are
y
an ente
W h e O S ce s s r e a n
er
allocated.
―Internal fragmentation=2046 bytes!!!!.
to
e
r p is th
o In the worst case a process needs n pages plus 1 byte.
or
ro
pro ress r use me,
So it will be allocated n+1 pages.
y?
th
g
o
cha agin
ce s o f
s ?
p
In
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
05/16/2024
05/16/2024
F.
32
Page table
o Page table is used to map virtual pages onto page
frames.
o Page table can have the following important fields.
Page frame number: represented the page frame number in
physical memory.
Present/absent bit: indicate whether the page to which the
entry belongs is currently in memory or not.
bit 1- the entry is valid and can be used.
Bit 0 the virtual page is not currently in memory. Accessing a page
table entry with this bit set to 0 causes a page fault.
Protection bits: tell what kinds of access are permitted. In
the simplest form, this field contains 1 bit, with 0 for
read/write and 1 for read only.
Modified bit: is bit set when page is written. If the page in
it has been modified, it must be written back to the disk. If
it has not been
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
05/16/2024
05/16/2024
F.
33
Page table(con’t…)
Referenced bit: is set whenever a page is referenced, either for
reading or writing.
Its value is to help the operating system choose a page to
evict when a page fault occurs and plays an important role in
several of the page replacement algorithms
Cache disable: With this bit, caching can be turned off. This
feature is important for pages that map onto device registers
rather than memory.
4
1
3 22
4
33
0
1
0
0
page table
Graph of Page
Faults Versus
The Number of
Frames
2 4
6 page faults
3
5
o Used for measuring how well your algorithm performs.
o How can you know what the future references will be?
Department of Computer Science, School of Computing |DDUIoT Operating System by Kidanemariam
05/16/2024
05/16/2024
F.
55
Allocation of Frames
o Each process needs minimum number of pages allocation.
o If there is a single process, entire available memory can be
allocated.
o Multi-programming puts two or more processes in memory
at same time.
o We must allocate minimum number of frames to each
process.
o Two major allocation schemes.
– fixed allocation
– priority allocation