Download Lec10c-Memory Management 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
COMP 3500
Introduction to Operating Systems
Memory Management: Part 1
Dr. Xiao Qin
Auburn University
http://www.eng.auburn.edu/~xqin
[email protected]
Slides are adopted and modified from Drs. Stallings, Silberschatz, Galvin, Gagne, Nutt
The External View of the Memory
Manager
2
Slide courtesy of Dr. Gary Nutt
The Basic Memory Hierarchy
Primary Memory
(Executable Memory)
e.g. RAM
Faster access
Larger storage
CPU Registers
Speed?
Q1:
Capacity?
Slide courtesy of Dr. Gary Nutt
3
Secondary Memory
e.g. Disk or Tape
LBNL IT Backup Robotic Tape Libraries
URL: servback.lbl.gov/backups/equipment/robots.html
4
Memory Management Requirements
Q2: Can you list two functionalities?
• Relocation
• Protection
• Sharing
• Logical organization
• Physical organization
Address Space vs. Primary Memory
Process Address
Space
Mapped to object
other than memory
6
Hardware Primary Memory
Creating an Executable Program
Source
code
Library
code
Other
objects
Secondary
memory
C
Reloc
Object
code
Primary
memory
Link
Edit
•Compile time: Translate elements
•Link time: Combine elements
Loader
•Load time:
•Allocate primary memory
•Adjust addresses in address space
•Copy address space from secondary to primary memory
7
Process
address
space
A Sample Code Segment
...
static int gVar;
...
int proc_a(int arg){
...
gVar = 7;
put_record(gVar);
...
}
The Relocatable Object Module
Code Segment
Relative
Address
Generated Code
Data Segment
0000
...
Relative
...
Address
Generated variable space
0008
entry
proc_a
...
...
0036
[Space for gVar variable]
0220
load
=7, R1
...
0224
store
R1, 0036
0049
(last location in the data segment)
0228
push
0036
0232
call
‘put_record’
...
0400
External reference table
...
0404
‘put_record’
0232
...
0500
External definition table
...
0540
‘proc_a’ 0008
...
0600
(symbol table)
...
0799
(last location in the code segment)
The Absolute Program
After the link editor combines relocatable
modules
Code Segment
Relative
Data Segment
Address
Generated Code
Relative
0000
(Other modules)
Address
Generated variable space
...
...
1008
entry
proc_a
0136
[Space for gVar variable]
...
...
1220
load
=7, R1
1000
(last location in the data segment)
1224
store
R1, 0136
1228
push
1036
1232
call
2334
...
1399
(End of proc_a)
...
(Other modules)
2334
entry
put_record
...
2670
(optional symbol table)
...
2999
(last location in the code segment)
Q3: What is the difference
Between the absolute program and
the relocatable object module?
The Program Loaded at Location 4000
Relative
Address
0000
4000
...
5008
...
5036
...
5220
5224
5228
5232
...
5399
...
6334
...
6670
...
6999
7000
...
7136
...
8000
Generated Code
(Other process’s programs)
(Other modules)
entry
proc_a
[Space for gVar variable]
load
store
push
call
=7, R1
R1, 7136
5036
6334
(End of proc_a)
(Other modules)
entry
put_record
(optional symbol table)
(last location in the code segment)
(first location in the data segment)
[Space for gVar variable]
(Other process’s programs)
Dynamic Relocation using a
Relocation Register
• Hardware device that maps virtual to physical address
• The value in the relocation register is added to every address generated
by a user process at the time it is sent to memory
• The user program deals with logical addresses; it never sees the real
physical addresses
Static Memory Partitioning
Unused
In Use
Operating
System
Process 3
pi
Process 0
Issue:
Need a mechanism/policy for
loading pi’s address space into
primary memory
Process 2
Process 1
13
 Used in several
variations in some nowobsolete operating
systems
 Does not involve
virtual memory
14
Frame vs. Page vs. Segment
Frame
A fixed-length block of main memory.
Page
A fixed-length block of data that resides in secondary memory
(such as disk). A page of data may temporarily be copied into a
frame of main memory.
Segment
A variable-length block of data that
An entire segment may temporarily be
region of main memory (segmentation)
into pages which can be individually
(combined segmentation and paging).
resides in secondary memory.
copied into an available
or the segment may be divided
copied into main memory
Memory Management Terms
15
Static Memory Allocation (Cont.)
• Hole – block of available memory; holes of various size are
scattered throughout memory
• When a process arrives, it is allocated memory from a hole
large enough to accommodate it
• Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
OS
OS
OS
OS
process 5
process 5
process 5
process 5
process 9
process 9
process 8
process 2
process 10
process 2
process 2
process 2
Fixed-Partition Memory
Mechanism
Operating
System
pi needs ni units
ni
Region 0
N0
Region 1
N1
Region 2
N2
Region 3
N3
pi
Fixed-Partition Memory Best-Fit
Operating
System
Internal
Fragmentation
Region 0
N0
Region 1
N1
p
Regioni 2
N2
Region 3
N3
Loader must adjust
every address in the
absolute module
when placed in
memory
Q4: Pros and Cons?
Fixed-Partition Memory Worst-Fit
Operating
System
Q5: Pros and Cons?
pi
Region 0
N0
Region 1
N1
Region 2
N2
Region 3
N3
Fixed-Partition Memory First-Fit
Operating
System
Q6: Pros and Cons?
pi
Region 0
N0
Region 1
N1
Region 2
N2
Region 3
N3
Fixed-Partition Memory Next-Fit
Q7: Pros and Cons?
Operating
System
Region 0
N0
Fixed-Partition strategies were used in
batch multiprogramming systems (why?)
Not good for timesharing systems
pi 1
Region
N1
Pi+1
Region 2
N2
Region 3
N3
Disadvantages
• A program may be too big to fit in a partition
– program needs to be designed with the use of overlays
• Main memory utilization is inefficient
– any program, regardless of size, occupies an entire
partition
– internal fragmentation
• wasted space due to the block of data loaded being
smaller than the partition
22
Summary
• Memory Management Requirements
• Dynamic Relocation using a Relocation Register
• Static Memory Partitioning
• Frame vs. Page vs. Segment
23