Docsity

Memory Management Part 1 - Operating Systems | COP 4600, Study notes of Operating Systems

Toggle sidebar
bg1
COP 4600: Intro To OS (Memory Management –Part 1) Page 1 © Dr. Mark Llewellyn
COP 4600 –Summer 2011
Introduction To Operating Systems
Memory Management –Part 1
Department of Electrical Engineering and Computer Science
Computer Science Division
University of Central Florida
Instructor : Dr. Mark Llewellyn
HEC 236, 407-823-2790
http://www.cs.ucf.edu/courses/cop4600/sum2011
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a

Partial preview of the text

Download Memory Management Part 1 - Operating Systems | COP 4600 and more Study notes Operating Systems in PDF only on Docsity!

COP 4600 – Summer 2011

Introduction To Operating Systems

Memory Management – Part 1

Department of Electrical Engineering and Computer Science

Computer Science Division

University of Central Florida

Instructor : Dr. Mark Llewellyn

[email protected]

HEC 236, 407-823-

http://www.cs.ucf.edu/courses/cop4600/sum

Memory Management

• In a uniprogramming environment, main memory is divided into

two parts: one part for the OS and one part for the program

currently being executed.

• In a multiprogramming environment, the “user” part of memory

must be further subdivided to accommodate multiple processes.

• The task of subdivision is carried out dynamically by the OS and

is referred to as memory management.

• Effective memory management is vital in a multiprogramming

environment. If only a few processes are in memory, then for

much of the time all of the processes will be waiting for I/O and

the processor will be idle. Thus memory needs to be allocated to

ensure a reasonable supply of ready processes to consume the

available processor time.

Memory Management Requirements

• The memory management component of the operating

system must satisfy five basic requirements:

1) Relocation

2) Protection

3) Sharing

4) Logical organization

5) Physical organization

• We’ll consider each of these requirements separately.

(1) Relocation

• In a multiprogramming system, the available main memory is

generally shared among a number of processes.

• Typically, it is not possible for the programmer to know in advance

which other programs will be resident in main memory at the time of

execution of their program.

• In addition, we would like to be able to swap active processes in and

out of main memory to maximize processor utilization by providing a

large pool of ready processes to execute. (See next page for an

illustration of swapping.)

• Once a program has been swapped out to disk, it would be quite

limiting to require that it be placed into the same memory region it

previously vacated when it is swapped back into the main memory.

Rather, we would like to relocate the process to a different area of the

memory.

Aside on Linking and Loading

• The first step in the creation of an active process is to load

a program into main memory and create a process image.

Program
Data

Object code

Program
Data
Process Control Block
Stack

Process Image in main memory

Aside on Linking and Loading (cont.)

• Typically, applications consist of a number of compiled or

assembled modules in object code form.

• These are linked to resolve any references between the

modules. At the same time, references to library routines

are resolved. The library routines themselves may be

incorporated into the program or referenced as shared code

that must be supplied by the OS at run time.

• This scenario is illustrated on the next page.

Relocation (cont.)

• A physical address, or absolute address, is an actual location in main

memory. These are the addresses with which the memory unit works.

• A logical address or virtual address is a reference to a memory location

independent of the current assignment of data to memory. A translation

must be made to a physical address before the memory access can be

achieved. Logical addresses are generated by the CPU.

• A relative address is a particular example of a logical address, in which

the address is expressed as a location relative to some known point,

usually a value in a processor register.

• Programs that employ relative addressing are loaded using dynamic run-

time loading. Typically, all of the memory references in the loaded

process are relative to the origin of the program. Thus, a hardware

mechanism is required for translating relative addresses into physical

addresses at the time of execution of the instruction that contains the

reference.

Aside on Linking and Loading (cont.)

Loading

• Looking at the figure on page 9, you’ll see that the loader

places the load module in main memory starting at location x.

In loading the program, the addressing requirements of the

program (see next page) must be satisfied.

• In general three different approaches can be taken:

1. Absolute loading

2. Relocatable loading

3. Dynamic run-time loading

Aside on Linking and Loading (cont.)

Absolute Loading

• An absolute loader requires that a given load module always be

loaded into the same location in main memory.

• Thus, in the load module presented to the loader, all address

references must be specific, or absolute, main memory

addresses.

– For example, if x in the figure on page 9 is location 1024, then the first

word in a load module destined for that region of memory has address

• The assignment of specific address values to memory

references within a program can be done either by the

programmer or at compile or assembly time.

Aside on Linking and Loading (cont.)

Relocatable Loading

• The disadvantage of binding memory references to specific addresses prior

to loading is that the resulting load module can only be placed in one region

of main memory.

• The relocation requirement implies that we would like to be able to load a

module anywhere in main memory.

• To satisfy this requirement, the assembler or compiler produces not absolute

addresses but relative addresses.

• The start of the load module is assigned relative address 0 and all memory

references within the module are expressed in terms relative to 0.

• The loader now has the simple task of placing the module wherever room is

available. If, as in the example, the module is placed beginning at memory

location x , then the loader must simply add x to each memory reference as it

loads the module into memory.

Aside on Linking and Loading (cont.)

Dynamic Run-Time Loading

• Relocatable loaders are common and provide obvious benefits over absolute

loaders. However, in a multiprogramming environment, even one that does

not depend on virtual memory, the relocating scheme is inadequate.

• Since we may swap a given process in and out of main memory many times

during its lifetime, binding relative addresses to absolute addresses at the

initial load time will not give us the flexibility needed to relocate the same

process image into different locations.

• The alternative is to defer the calculation of an absolute address until it is

actually needed at run time.

• For this purpose, the load module is loaded into main memory with all

memory references in relative form. It is not until an instruction is executed

that the absolute address is calculated.

• To assure that this function does not degrade performance, it is handled by

special processor hardware rather than software.

Aside on Linking and Loading (cont.)

Dynamic Run-Time Loading

Aside on Linking and Loading (cont.)

Memory Management Unit (MMU)

• The MMU is a hardware device that maps logical addresses to

physical addresses.

• Base register replaced by relocation register.

• In MMU scheme, 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

Hardware Support For Relocation