clippersdogheartedΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 7 χρόνια και 8 μήνες)

229 εμφανίσεις

Systems Software

Chapter 2

Memory Management

Early Systems

Operating systems bear the responsibility of
managing the memory resource.

It would be the rare computer which had more primary
memory than it needed.

OS Allocates Memory to Tasks

Memory is a shared resource, and it is vital that the
operating system manage this resource so that each
executing task receives the memory that it needs in order to
execute successfully

Memory allocation to a job must not interfere with other
tasks which also need memory allocations.

Four major Memory
Management Schemes

Four major schemes have evolved for
allocating and managing memory.

In this chapter we shall consider each of
these briefly:


Single User Contiguous
Memory Allocation

Characteristics of this Algorithm:

a. The program to be executed is loaded
entirely and loaded into contiguous memory

It is executed in its entirety and when
execution ceases the memory is de
for reuse.

Today's personal computer OS usually work in
a way similar to this.

Most PC operating systems (Mac OS,
Windows, Unix ) are able to perform

However, the mode in which people use them
is often single
time (real time) mode.

Whether the memory allocated to a task in a
PC is contiguous depends upon the allocation
algorithm in use. Often the memory allocation
is contiguous, if possible

This mode of computing was not particularly
cost effective, especially when system was

Today memory is relatively inexpensive so
that allocating memory to a single task at one
time is not as "expensive" as it once was.

The mode described here does not permit
multiprogramming, rather, this mode of
computing preceded multiprogramming.

II. Fixed Partition Memory

This mode was developed during early
attempts at the development of
multiprogramming (multitasking).

When an operating system using this
strategy was being configured a systems
engineer or manager would specify fixed
sized partitions of memory.

Fixed partitions, continued

Jobs are then assigned and loaded into fixed

This system insured against intrusion on
one task by another.

The partitions in which the operating
system is loaded were considered protected.

Fixed partitions, continued

As with the previous method, tasks are still loaded
entirely and into contiguous memory. Each job
received one partition.

This may waste space since a very small task may
not need all of the memory of the partition to
which it is assigned.

Wasted memory within a block is known as
Internal Fragmentation

For efficiency, the partitions and their sizes must
be “tuned” to the average job mix on the system.
See figure 2.1 for an example.


Dynamic Partitions
Memory Management

The task is still loaded into contiguous
memory and loaded entirely,

Here the partition assigned is only as large
as requested.

Clearly, this makes much more efficient
use of memory.

Dynamic Partitions, continued

This method helps to eliminate
fragmentation as jobs are loaded initially,
but over time external fragmentation
develops and memory use becomes less

Figure 2.2

External Fragmentation refers to the wasted
memory between allocated memory blocks.

Allocation Algorithms

Operating system may use one of several
allocation schemes to assign memory to a
requesting task

1. First Fit

use first partition large enough. The
operating system keeps a list of available partitions
in location order. ( low
> high memory address)

2. Best Fit

the operating system keeps list of
available partitions arranged by size (smallest
largest) The first partition large enough will be the
one used.

First Fit Algorithm

Fit is faster allocating but Best
uses memory more efficiently.

See table 2.2

In the First
Fit algorithm the operating
system keeps two lists: the free list and the
busy list.

First Fit, continued

The operating system takes a job from the
Entry Queue, looks at the minimum
partition size it will need and then examines
the Free BlockList until large enough
available block is found.

The first one found is then assigned to the
job. If no block large enough is found then
the operating system will enqueue job in the
Waiting Queue.

First Fit, continued

It then takes the next job from Entry Queue
and repeats the procedure.

See table 2.4 for a First
Fit example.
Assume dynamic partition sizing

and a
request for a block of size 200.

Best Fit Algorithm

The operating system takes a job from the Entry
Queue, looks at the minimum partition size it will
need and then examines the Free Block List until
it finds the free block closest in size to the job.

When this block is found, it is then assigned to
the job.

If no block large enough is found then the
operating system will enqueue job in the Waiting

Best Fit Algorithm, continued

It then takes the next job from Entry Queue
and repeats the procedure.

See table 2.3 and 2.5 for a Best

In a Dynamic Block Size environment the
operating system would not keep the Free
Block Size list in order (smallest to largest)
even for a Best
Fit allocation scheme
because the block sizes change constantly
and there would be too much overhead.

See table 2.5. Note the small "sliver" of
memory which is useless.

Deallocation of Blocks.

In a Fixed Partition scheme this is very
straight forward, simply deallocate the
partition and declare it available.

In a Dynamic Partition Size scheme
deallocated partitions must be merged with any
others they are contiguous to and the new
block sizes calculated and entered into the Free
Blocks List

See tables 2.6, 2.7, 2.8, 2.9, 2.10, 2.11, 2.12,


Relocatable Dynamic

a. In this scheme the Memory Manager
"garbage collects" to reclaim fragments and
slivers of unused memory into larger groups
of free blocks.

b. In order to accomplish this a very
sophisticated "Compaction" algorithm is
used which actually relocates the code of
tasks in memory in order to push free
blocks together.

c. As programs are relocated downwards
and all of the free space gets pushed to high
end of memory

d. Every reference to a location within a
program must be altered in order to be
correct relative to the new program location
in memory.

Data and references to external locations,
however, must not be altered.

e. A relocation register holds information
about the “distance” the code is being
relocated in memory,

i.e. its new location in relation to its original

f. During execution an offset based on the
relocation register is added to all necessary
values in program.

See Fig. 2.5, 2.6.

The is a very slick method. It essentially
eliminates memory waste but clearly there
is a lot more overhead.

When should memory
compaction occur?

There are a number of strategies in use to decide
when to compact. Some of the strategies


Compact when a certain % memory in is use


Compact only at fixed time intervals

3. Compact only when there are jobs waiting to enter.

There are advantages and disadvantages to each.


Be ready to discuss problems #4, 5, 10 a, b,
c, d at end of Chapter 2. Write the solutions
out to turn in next class.

End of Chapter 2