Memory Management

checkboardmiceDéveloppement de logiciels

14 déc. 2013 (il y a 3 années et 8 mois)

158 vue(s)

Memory Management

Hardware Software Systems and Networks

CE0300
-
1

Degree


Level 1

Prepared by: KNT First Prepared on: 08
-
05
-
08 Last Modified on: 00
--
00
-
00

Quality checked by:

Copyright 2008 Asia Pacific Institute of Information Technology

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 2 (of 25)

Topic & Structure of the lesson


Memory Management


Logical and Physical Memory


Single Task with overlay


Memory Partitioning


Fragmentation

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 3 (of 25)

Learning Outcomes


At the end of this session you should be able
to:
-


understand the context of memory management


differentiate logical and physical memory


understand single tasking with overlay


differentiate between fixed and variable
partitioning


differentiate between internal and external
fragmentation

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 4 (of 25)

Key Terms you must be able to use


If you have mastered this topic,
you should be
able to use the following terms correctly in
your assignments and exams
:
-


single task with overlays


fixed partitioning


variable partitioning


internal fragmentation


external fragmentation

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 5 (of 25)

Memory Management


several processes to be in memory; need to share
memory management.


memory management


the
planned

organisation of
programs and data into memory.


goals of memory management is to make it
as

simple
as possible

for programs to find space to be loaded
and executed, to maximise the use of memory to
reduce

waste
.


memory manager


manages memory and to keep
track of which parts of the memory are in use and
which parts are free/available.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 6 (of 25)

Physical and Logical Memory


Logical Address


an address that is generated
by the CPU


Physical Address


address seen by the
memory

unit


loaded into the
memory

address

register

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 7 (of 25)

Single Task With Overlay


Allows for a program to be
larger

than the
amount of memory allocated.


Keeps in memory only instructions and data
that is
needed

at any given time.


When instructions are needed, they are
loaded

into space which was previously
occupied by instructions that are no longer
needed.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 8 (of 25)

Single Tasking With Overlay

At start
-
up of
execution

1.
Main program (100 bytes)

2.
Data Area (50 bytes)

3.
Overlay 1 (100 bytes)

4.
Overlay 2 (50 bytes)

5.
Overlay 3 (25 bytes)

Operating System

Data Area

Main Program

Overlay 3

Free space

Data Area

Main Program

Overlay 2

Operating System

Overlay 1

Operating System

Free space

250 bytes

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 9 (of 25)

Single Tasking With Overlay


Disadvantage



a program
cannot take advantage

of more
memory if it is available since the overlays are
designed around a given physical amount of
memory.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 10 (of 25)

Memory Partitioning


Dividing the memory space into
partitions

is
the
simplest

form of memory management.


Two types of
memory

partitioning
:
-


Fixed


Variable

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 11 (of 25)

Memory Partitioning
-

Fixed


Fixed partitioning


Dividing the memory into
fixed

spaces.

Operating System

100 bytes

250 bytes

200 bytes

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 12 (of 25)

Memory Partitioning
-

Fixed


Each partition may contain
exactly

one

process
.


The degree of multiprogramming is bound by
the
number

of

partitions
.


When a partition is free, a process is selected
from the input queue and is
loaded into the
free partitions
.


When the process terminates, the partition
becomes available

for another process.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 13 (of 25)

Memory Partitioning
-

Variable


Variable Partitioning


when a process arrives and needs memory, we search for
a
large enough space

for this process.


loads the program wherever the memory space is
available using
first fit
,
best fit

and
worst fit

algorithm.

Operating System

P1

P3

P2

400 k

1000 k

2000 k

2300 k

Free space

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 14 (of 25)

Memory Partitioning
-

Variable


first fit



allocates the
first space available

to fit the
program.


best fit


allocates the
smallest space

that will fit the
program.


worst fit


allocates the
largest

space

available.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:25 PM

Slide 15 (of 25)





Fragmentation

Internal

Fragmentation

External

Fragmentation

Memory Partitioning Issue


partitioning memory using fixed and variable
partitioning may suffer from a problem called
fragmentation
.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:26 PM

Slide 16 (of 25)

External Fragmentation


Too many
small pieces

of free space.


These small pieces of space
cannot

be used
for anything as they are
not

contiguous
.


Although enough total space exist but is not
contiguous, they
cannot

be

allocated
.


Variable partitioning leads to
external

fragmentation
.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:26 PM

Slide 17 (of 25)

External Fragmentation

o.s.

P3

P1

P2

P3

P3

P3

P3

2000

2300

2560

P4

P4

P4

P1

P1

P5

o.s.

o.s.

o.s.

o.s.

2000

2300

2560

2000

2300

2560

2000

2300

2560

2000

2300

2560

1700

1700

1700

1000

1000

1000

1000

1000

900

400

400

400

400

400

P2

terminates

allocate

P4

P1

terminates

allocate

P5

process

memory

time

P1

600 k

10

P2

1000 k

5

P3

300 k

20

process

memory

time

P4

700 k

8

P5

500 k

15

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:26 PM

Slide 18 (of 25)

External Fragmentation


One solution to the problem of external fragmentation is
compaction
.


The goal is to
shuffle

the

memory

contents

to place all free
memory
together

in one large block.

2000

2300

2560

1700

1000

400

P4

P5

o.s.

900

P3

compaction

P5

o.s.

400

900

P4

1600

P3

1900

2560

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:26 PM

Slide 19 (of 25)

Internal Fragmentation


When extra space is allocated to a process,
the
difference

between the two numbers
result in
internal

fragmentation
.


Fixed partitioning leads to
internal

fragmentation

as extra memory allocated to a
program which is not used cannot be used
elsewhere.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:26 PM

Slide 20 (of 25)

Operating System

100 bytes

250 bytes

200 bytes

Job Queue


process


memory


P1

95 bytes


P2

188 bytes


P3

230 bytes

Operating System

95 bytes

230 bytes

188 bytes



free

free

free

Internal Fragmentation

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:26 PM

Slide 21 (of 25)

Quick Review Questions

1.
Why is memory management important?

2.
Name the problems caused by fixed memory
partitioning and variable memory partitioning.



CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:26 PM

Slide 22 (of 25)

Follow Up Assignment

1.
How does single tasking with overlay work?

2.
Explain how variable partitioning leads to
external fragmentation and what is done to
overcome this.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:27 PM

Slide 23 (of 25)

Summary of Main Teaching Points


Memory management is to manage programs
in memory.


Single tasking with overlay allows the loading
of programs bigger than memory.


There exists two types of memory partitioning,
which are variable partitioning or fixed
partitioning.


Memory partitioning leads to external and
internal fragmentation.

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:27 PM

Slide 24 (of 25)

Q & A

Question and Answer Session

CE0300
-
1 Hardware Software Systems and Networks

Memory Management

Saturday, December 14,
2013

3:47:27 PM

Slide 25 (of 25)

Next Session


Virtual Memory


Paging and Segmentation