CSC 453 Operating Systems: Memory Is A Resource
CSC 453 Operating Systems: Memory Is A Resource
Memory Is A Resource
• Main memory is an array of words or bytes that
can be accessed directly by their own unique
addresses.
• Executing an instruction will involve accessing
memory several times to :
– fetch the instruction
– fetch operand(s)
– store the result
• Memory allocated to one process cannot be used
by another process (unless the process allows it).
The Same Program May Be Loaded Into
Different Memory Locations
00000 00000 00000
Other
Object
Module(s)
System
Library
Address Binding
Address binding can occur at:
• Compile time
– when the program is translated, absolute addresses are
generated.
– This assumes that the compiler knows where in
memory the program will be loaded.
• Load time
– The compiler generates relocatable addresses.
– The binding occurs when the program is loaded
• Execution time
– If the process can moved during execution, address
binding is delayed until run time.
Dynamic Loading
Overlays
Operating Operating
System System
Common Common
procedures procedures
Overlay 1 Overlay 2
Common Common
data data
Logical Vs. Physical Address
• Logical Address – The address used by the
instructions to load and store data, jump to
other instructions, etc.
• Physical Address – Used by the hardware to
load and store data, fetch instructions, etc.
Relocatable Addressing
25000
Jump +
to 497 497 25497
physical
logical address address
What Is Swapping?
Operating
System
P1
User Space
Occupied by P2
Process P1
Backing Store
Operating
System
P1
Process P1
Is Written on P2
Backing Store
Backing Store
Swapping In A Process
Operating
System
P1
Process P2
Is Read From P2
Backing Store
Backing Store
Bare Machine
No Restrictions On
Memory Use
-
No Operating System
Services
Organizing Memory
• Main memory is comprised of two
partitions:
– Operating system
– User processes
• The operating system can be at the high end
or low end of memory – the location of the
interrupt vector is largely responsible for
where the operating system will reside.
Single-Partition Allocation
000000
Operating System
User Process
FFFFFF
Single-Partition Allocation With Transient
Operating-System Code
000000
User Process
FFFFFF
Limit Relocation
register register
yes Memory
CPU <? +
logical physical
no
address address
Multiple-Partition Allocation
• More than one user process can reside in
memory at a time in contiguous memory
allocations. There are two possible
approaches:
– There are a fixed maximum number of
processes than can be resident at a time.
– The number of process that can reside in
memory can vary.
MFT
• MFT (Multiprogramming with Fixed
number of Tasks) assumes that there will be
up to N processes resident in memory.
• Memory is divided into N partitions of fixed
sizes (that are not necessarily equal).
• MFT was used in IBM’s OS/360 and is no
longer used.
MVT
• MVT (Multiprogramming with Variable
number of Tasks) assumes that there is no
fixed maximum number of resident
processes.
• The operating system keeps track of what
parts of memory are in use and when a
process needs a memory allocation, it looks
for a partition in memory in which it will fit.
270000 270000
P2
Available allocate P 1 allocate P 2
memory
670000
E00000 E00000
FFFFFF FFFFFF FFFFFF P4
270000 270000
P2 Process P 4doesn’t fit
allocate P 4
670000 670000
P4
P3
P3
E00000 E00000
FFFFFF FFFFFF
The Dynamic Storage -Allocation
Problem
• There are three different algorithms that we
can use to select an available block of
memory into which the operating system
will load the program:
• First fit
– Best fit
– Worst fit
P1
Internal
fragmentation
External
P2
fragmentation
P3
Compaction
Operating Operating
System System
Before
P1 compaction P1
P2
After
P2
compaction
P3
P3
P1 P1
P1
P3 P2
P2
P2
P3
P3
What Is Paging?
• In a paged memory management system, physical
memory is divided into fixed-sized block called
frames into which are loaded blocks of logical
memory.
• All the addresses appear to be contiguous but they
are not necessarily stored in contiguous areas of
memory.
• This eliminates the problem of external
fragmentation.
physical
address
f d
Page
Table
logical address
p d p
Page 2
Page Table
Page 0 0 1 Page 0
Page 1
1 2
Page 2 Page 4
2 0
Page 3
3 4
Page 4
Page 6
4 6
Logical memory Physical memory
Loading a New Process
0 1 0 1
0 Free-frame list 0
1 1
7
2 2 2
6
0
3 2 2 3 2
1 10
4 3 4 3
2 9
5 3 8 5
6 11 6 1
12
7 New process 7 0
5
8 8
9 9
10 10 3
11 11
12 12
displacement
page #
Page Table
f
Associative Registers and Paging
CPU p d
p f TLB Hit
f d
Main
Memory
p
f
TLB Miss
logical address
10 bits 10 bits 12 bits
p1 p2 d
p2
Outer-page
Page of
table
Page Table
logical address
2 bits 21 bits 9 bits
s p d
Outer-page
table
d
Page of
Page Table
Inverted Page Tables
logical address physical address
pid p d
i d
i
search
pid p
Page Table
Shared Pages
0 data 1
pgm 1 2 1 pgm 2 2 pgm 1
pgm 2 2 pgm 1 pgm 2
1 1
3 data 2
pgm 3 pgm 3
6 4 pgm 4 6
pgm 4 pgm 4
5
data 1 4 6 pgm 3 4 data 1
data 2 7 data 2
0 8
8 data 1
Process 1 Process 2
3 9 data 2 9
10
Process 1 11 Process 2
Page Table Page Table
12
Physical memory
Segmentation
main Library
program routines
Sub 1 stack
global
Sub 2 data
Segmentation Hardware
STBR
s
s d
logical limit base
address
yes
< + physical
address
no
addressing error
Segmentation and Memory
Protection
• Segments represent different components of
a program, such as code and data.
– Code segments can be marked as read-only or
execute-only.
– Segments containing arrays can check array
indices automatically.
– Code and data segments can be shared by
different processes.