Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CSC 302
Operating
Systems
PART THREE: MEMORY MANAGEMENT:
Lecture12: Basic Memory Management:
Lecture 12:
Scope:
Introduction to memory management.
Basic memory management options.
Relocation and protection.
Goals:
Examine the basic principles and strategies
applied in memory management.
Discuss the relocation and protection problems
and some solutions to them
Memory Management 2
Introduction
Memory Management 3
Introduction
Lower in the hierarchy, storage capacities have
lesser speed and cost.
Consequently, most computers have a memory
hierarchy, with
a small amount of very fast, inexpensive, volatile cache
memory,
some number of megabytes of medium-speed, medium-
price volatile main memory (RAM) and
hundreds or thousands of megabytes of slow, cheap, non-
volatile disk storage.
It is the work of the operating systems to co-ordinate
how these memories are used.
Memory Management 4
Memory hierarchy
Memory Management 5
memory manager
Memory Management 7
Modular programming support - The programmers
should be able to define program modules and also be able
to dynamically create/destroy/alter the size of modules.
Protection and access control - Different programs
should be able to co-operate in sharing some memory
space. It is important to ensure that such sharing is
controlled and processes should not be able to
indiscriminately access the memory allocated to other
processes.
Long-term storage - Users and applications may require
means for storing information for extended periods of time.
This is implemented using a file system.
Memory Management 8
Basic memory
management:
Memory management systems can be
divided into two classes:
those that move processes back and forth
between main memory and disk during execution
(swapping and paging) and
those that do not.
Swapping and paging are caused by lack of
sufficient main memory to hold all the
programs at once.
Memory Management 9
Mono-programming without
swapping or paging:
The simplest possible memory management
scheme is to run one program at a time,
sharing the memory between the program
and the operating system.
In this scheme, there are three variations:
The operating system may be at the bottom of
memory in RAM, or
It may be at the top in ROM, or
Device drivers may at the top in ROM and the rest
of the system in RAM.
Memory Management 10
The later model is common with small MS-DOS
systems.
On IBM PCs, the portion of the system in ROM is
called the BIOS (Basic Input Output System).
System characteristics:
Only one process can be running.
As soon as the user types a command, the operating
system copies the requested program from disk to memory
and executes it.
When the operating system receives another command, it
loads a new program into memory and overwrites the
previous one.
Mono programming is common with small
computers with simple operating systems.
Memory Management 11
Memory Management 12
Multiprogramming with fixed
partitions:
It is desirable to have multiple processes
running at once.
On timesharing systems, having multiple
processes in memory at the same time
means that when one process is blocked
waiting for I/O to finish, another one can use
the CPU.
Memory Management 13
One way of achieving multiprogramming is to
divide memory into unequal partitions.
Partitioning can be done manually when the
system is started up.
When a job is started, it is put in the input
queue for the smallest partition that is
large enough to hold it.
Since partitions are fixed, any unused
space in the partition is lost.
Memory Management 14
Memory Management 15
Disadvantage:
The queue for a large partition may be empty
while several jobs are kept waiting for a smaller
partition.
An alternative is to maintain a single queue:
Whenever a partition becomes free, the job
closest to the front of the queue that fits in it could
be loaded into the empty partition and run.
Problem:
Wastes large partition on small job
Memory Management 16
It is undesirable to waste a large partition on
a small job
Thus, a different strategy;
search the whole input queue whenever a
partition becomes free and pick the largest job
that fits it.
Problem:
This algorithm discriminates against small jobs as
being unworthy of having a whole partition,
whereas, it is desirable to give small jobs the best
service and not the worst.
Memory Management 17
A solution is to have at least one small
partition around.
Another approach is to have a rule stating
that a job that is eligible to run may not be
skipped over more than k times.
Each time it is skipped over it is given one point.
When it has gained k points, it may not be skipped
again.
Memory Management 18
Relocation and protection:
Memory Management 20
Solutions to the relocation
problem
Modify the instructions as the program is loaded into
memory.
Programs loaded into partition 1 have 100K added to each
address; programs loaded into partition 2 have 200K added
to addresses.
However:- Relocation during loading does not
solve the protection problem.
A malicious program can always construct a new
instruction and jump to it.
In multi-user systems, it is undesirable to let processes
read and write memory belonging to other users.
Memory Management 21
Solution to protection
problem:
One solution is to divide memory into blocks
of 2K bytes and assign a 4-bit protection
code to each block.
The PSW contained a 4-bit key.
The hardware traps any attempt by a running
process to access memory whose protection code
differed from the PSW key.
It is only the operating system that was allowed to
change this key and not user processes.
Memory Management 22
Another solution to both the relocation and
protection problems is to equip the machine with two
special hardware registers, called the base and the
limit registers.
When a process is loaded the base and limit registers are
loaded with address of the start of its partition and length of
the partition respectively.
Every memory address generated automatically has the
base register contents added to it before being sent to
memory.
Addresses are also checked against the limit registers to
make sure that they do not attempt to address memory
outside the current partition.
Hardware protects the base and limit registers from user
programs.
Memory Management 23
With batch systems, organizing memory into fixed
partitions is simple and effective.
Each job is loaded into a partition when it gets to the head
of the queue.
It stays in memory until it is finished.
With timesharing systems, the situation is different.
Sometimes there is not enough main memory to hold all
the currently active processes,
so excess processes must be kept on disk and brought in
to run dynamically.
Memory Management 24
Two general approaches to memory
management can be used depending on the
available hardware.
The simplest strategy, called swapping, consists
of bringing each process in its entirety, running it
for a while then putting it back to disk.
The other strategy, called virtual memory, allows
programs to run even when they are only partially
in main memory.
Memory Management 25