a genda for today what is memory management source code to execution address binding logical and...

27

Upload: amos-perry

Post on 28-Dec-2015

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
Page 2: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Agenda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

and overlays

Page 3: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Memory Hierarchy Very small, extremely fast, extremely

expensive, and volatile CPU registers Small, very fast, expensive, and volatile

cache Hundreds of megabytes of medium-

speed, medium-price, volatile main memory

Hundreds of gigabytes of slow, cheap, and non-volatile secondary storage

Page 4: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Purpose of Memory Management

To ensure fair, secure, orderly, and efficient use of memory

Page 5: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Memory ManagementKeeping track of used and free

memory spaceWhen, where, and how much

memory to allocate and deallocate

Swapping processes in and out of main memory

Page 6: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Source to ExecutionCompile/Assemble

Link

Load

Execute

Page 7: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,
Page 8: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Binding instructions and data to memory addresses

Compile time

Load time

Execution time

Address Binding

Page 9: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Compile timeCompile time: If you know at compile time where the process will reside in memory, the absolute code can be generated. Process must reside in the same memory region for it to execute correctly.

Address Binding

Page 10: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Load timeLoad time: If the location of a process in memory is not known at compile time, then the compiler must generate re-locatable code. In this case the final binding is delayed until load time. Process can be loaded in different memory regions.

Address Binding

Page 11: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Address Binding Execution timeExecution time: If the process

can be moved during its execution from one memory region to another, then binding must be delayed until run time. Special hardware must be available for this to work.

Page 12: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Logical and Physical Addresses

Logical address: An address generated by the process/CPU; refers to an instruction or data in the process

Physical address: An address for a main memory location where instruction or data resides

Page 13: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Logical and Physical Address Spaces

The set of all logical addresses generated by a process comprises its logical address space.

The set of physical addresses corresponding to these logical addresses comprises the physical address space for the process.

Page 14: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Logical and Physical Address Spaces

The run-time mapping from logical to physical addresses is done by a piece of the CPU hardware, called the memory management unit (MMU).

Page 15: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

ExampleThe base register is called the

relocation register.

The value in the relocation register is added to every address generated by a user process at the time it is sent to memory.

Page 16: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Example

14000Process

Page 17: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Example In i8086, the logical address of

the next instruction is specified by the value of instruction pointer (IP). The physical address for the instruction is computed by shifting the code segment register (CS) left by four bits and adding IP to it.

Page 18: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Example

CPU

CS * 24

+

MMU

Logical

address

Physical

address

Page 19: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

ExampleLogical address (16-bit)

IP = 0B10hCS = D000h

Physical address (20-bit)

CS * 24 + IP = D0B10h

Sizes of logical and physical address spaces?

Page 20: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Dynamic LoadingWith dynamic loading, a routine

is not loaded into the main memory until it is called.

All routines are kept on the disk in a re-locatable format.

The main program is loaded into memory and is executed

Page 21: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Dynamic LoadingAdvantages

Potentially less time needed to load a program

Potentially less memory space needed

DisadvantageRun-time activity

Page 22: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Dynamic Linking

In static linking, system language libraries are linked at compile time and, like any other object module, are combined by the loader into the binary image

Page 23: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Dynamic Linking

In dynamic linking, linking is postponed until run-time.

A library call is replaced by a piece of code, called stub, which is used to locate memory-resident library routine

Page 24: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Dynamic Linking

During execution of a process, stub is replaced by the address of the relevant library code and the code is executed

If library code is not in memory, it is loaded at this time

Page 25: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Dynamic LinkingAdvantages

Potentially less time needed to load a program

Potentially less memory space needed

Less disk space needed to store binaries

Page 26: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

Dynamic LinkingDisadvantages

Time-consuming run-time activity, resulting in slower program execution

gcc compilerDynamic linking by default-static option allows static

linking

Page 27: A genda for Today What is memory management Source code to execution Address binding Logical and physical address spaces Dynamic loading, dynamic linking,

What is memory management From source code to execution Address binding Logical and physical address

spaces Dynamic loading Dynamic linking