Lecture 3 - Memory Management
Lecture 3 - Memory Management
OPERATING SYSTEMS
Memory Management
Saipunidzam Mahamad
2011
Overview
Memory allocation and protection
Memory Management, Early Systems
Single-user
Fixed partitions
Dynamic partitions
Relocatable partitions
Swapping
Paging and Segmentation
Page replacement algorithms
Virtual Memory
Saipunidzam Mahamad
2011
Introduction
The main purpose of a computer system is
to execute programs and together with the
data they access, must be in main memory
(at least partially) during execution.
To improve both the utilisation of CPU and
the speed of its response to its user, the
computer must keep several processes in
memory
Saipunidzam Mahamad
2011
Introduction
There are many different memory management
schemes. These schemes reflects various
approaches to memory management, and
effectiveness of the different algorithm depends
on the particular situation.
Selection of a memory management scheme for
a specific system depends on many factors,
especially on the hardware design of the system
Saipunidzam Mahamad
2011
Background
Memory is central to the operation of a modern
computer system. It is a large array of words or
bytes, each with its own address.
The CPU fetches instruction from memory
according to the value of the program counter.
Then, this instruction may cause additional
loading from and storing to specific memory
addresses
Saipunidzam Mahamad
2011
Saipunidzam Mahamad
2011
Memory Management
A fundamental task of memory management
component of an O/S is to ensure safe
execution of programs by providing:
Sharing of memory
Memory protection
Saipunidzam Mahamad
2011
Efficiency
Relocation
number and location of
Ability of a program to
process
run in different memory
Safety (or protection)
allocation
Processes must not corrupt
each other (nor the OS)
Saipunidzam Mahamad
2011
Memory Protection
The second fundamental task of a memory
management system is to protect program sharing the
memory from each other. This protection also covers
the operating system itself. Memory protection can be
provided at either of the two levels:
Hardware
Address translation
Software
Language dependent: strong typing
Language independent: software fault isolation
Saipunidzam Mahamad
2011
Memory Allocation
Information stored in main memory can be
classified in a variety of ways:
Program(code) and data (variables, constants)
Read-only (code, constants) and read-write (variables)
Address (e.g., pointer) or data (other variables); binding
(when memory is allocated for the object): static or
dynamic
10
11
Saipunidzam Mahamad
2011
12
Saipunidzam Mahamad
2011
13
14
Saipunidzam Mahamad
2011
15
Function of a linker
A linker collects (if possible) and puts
together all the required pieces to form the
executable code.
Issues:
Relocation: where to put pieces
Cross-reference: where to find pieces
Re-organisation: New memory layout
Saipunidzam Mahamad
2011
16
Contd...
The figure illustrated
how a program is
stored in a memory
Saipunidzam Mahamad
2011
17
Function of a loader
A loader places the executable code in main memory
starting at a pre-determined location (base or start
address). This can be done in several ways, depending
on hardware architecture:
Absolute loading
Always loads programs into a designated memory location
Relocatable loading
Allows loading programs in different memory locations
18
Single-user systems
Fixed partitions
Dynamic partitions
Re-locatable dynamic partitions
19
20
21
22
Fixed-Partitions
Once partition was assigned to a job, no other
job could be allowed to enter its boundaries,
either accidentally or intentionally
The algorithm require a few more steps than the
one used for a single-user system because the
size job must be matched with the size of the
partition to make sure it fits completely. Then,
when a block is allocated, the status of the
partition must be checked to see if its available
Saipunidzam Mahamad
2011
23
24
25
Job List:
Job 1
Job 2
Job 3
Job 4
30K
50K
30K
25K
25K
25K
Partition 1
300K
325K
350K
Partition 2
Partition 3
Partition 4
50K
400K
Main Memory
Saipunidzam Mahamad
2011
26
Job List :
J1
30K
J2
50K
J3
30K
J4
25K
Original State
100K
Partition 1
Partition 1
Partition 2
25K
Partition 3
25K
Partition 4
Saipunidzam Mahamad
2011
50K
Job 4 (25K)
Partition 2
Partition 3
Job 2 (50K)
Partition 4
27
Saipunidzam Mahamad
2011
Memory
address
200K
300K
325K
350K
Access
Job 1
Job 4
Job 2
Partition
status
Busy
Busy
Free
Busy
28
29
30
Saipunidzam Mahamad
2011
31
Size
Time
J1
500K
15
J2
700K
J3
1000K
J4
300K
10
J5
600K
Operating
System
0
400K
Free
Space =
2160K
2560K
32
Summary
View of OS architecture
System Call
System structure
OS kernel
MS DOS and Unix Structure
Memory management
Introduction
Issues in sharing memory
Memory Allocation
Several step before program can be
executed by the CPU; compiling,
address binding, linker, loader
Single-user systems,Fixed
partitions and Dynamic Partition
Saipunidzam Mahamad
2011
33