Top Banner
Memory Management
21

Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Dec 15, 2015

Download

Documents

Rey Calfee
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Memory Management

Page 2: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Memory Manager• Requirements

– Minimize executable memory access time– Maximize executable memory size– Executable memory must be cost-effective

• Today’s memory manager:– Allocates primary memory to processes– Maps process address space to primary memory– Minimizes access time using cost-effective

memory configuration– May use static or dynamic techniques

Page 3: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Address Space vs Primary Memory

Mapped to objectother than memory

Process Address Space Hardware Primary Memory

Page 4: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Building the Address Space

Sourcecode

Sourcecode

•Compile time: Translate elements

•Load time:•Allocate primary memory•Adjust addresses in address space•Copy address space from secondary to primary memory

LoaderLoader Processaddressspace

Primarymemory

C

RelocObjectcode

RelocObjectcode

LinkEdit

LinkEdit

Librarycode

Librarycode

Otherobjects

Otherobjects

Secondary memory

•Link time: Combine elements

Page 5: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Primary & Secondary Memory

CPU

Primary Memory(Executable Memory)

e.g. RAM

Secondary Memorye.g. Disk or Tape

• CPU can load/store• Ctl Unit executes code from this memory•Transient storage

• Access using I/O operations• Persistent storage

Load

Information can be loaded statically or dynamically

Page 6: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Static Memory Allocation

OperatingSystem

Process 3

Process 0

Process 2

Process 1

Unused

In Use

Issue: Need a mechanism/policy for loading pi’s address space into primary memory

pi

Page 7: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Fixed-Partition Memory Mechanism

OperatingSystem

Region 3

Region 2

Region 1

Region 0 N0

N1

N2

N3

pi

pi needs ni units

ni

Page 8: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Fixed-Partition Memory -- Best-Fit

OperatingSystem

Region 3

Region 2

Region 1

Region 0 N0

N1

N2

N3

pi

InternalFragmentation

•Loader must adjust every address in the absolute module when placed in memory

Page 9: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Fixed-Partition Memory -- Worst-Fit

OperatingSystem

Region 3

Region 2

Region 1

Region 0 N0

N1

N2

N3

pi

Page 10: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Fixed-Partition Memory -- First-Fit

OperatingSystem

Region 3

Region 2

Region 1

Region 0 N0

N1

N2

N3

pi

Page 11: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Fixed-Partition Memory -- Next-Fit

OperatingSystem

Region 3

Region 2

Region 1

Region 0 N0

N1

N2

N3

pi

Pi+1

Page 12: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Variable Partition Memory Mechanism

OperatingSystem

OperatingSystem

Process 0

Process 6

Process 2

Process 5Process 4

•Compaction moves program in memory

OperatingSystem

Process 0

Process 6

Process 2

Process 5

Process 4

•External fragmentation

OperatingSystem

Process 0

Process 1

Process 2

Process 3

Process 4

Loader adjusts every address in every absolute module when placed in memory

Page 13: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Cost of Moving Programs

load R1, 0x02010

3F013010

Program loaded at 0x01000 3F016010

Program loaded at 0x04000

•Must run loader over program again!

Consider dynamic techniques

Page 14: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Dynamic Memory Allocation• Could use dynamically allocated memory

• Process wants to change the size of its address space– Smaller Creates an external fragment– Larger May have to move/relocate the

program

• Allocate “holes” in memory according to– Best- /Worst- / First- /Next-fit

Page 15: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Special Case: Swapping• Special case of dynamic memory allocation

• Suppose there is high demand for executable memory

• Equitable policy might be to time-multiplex processes into the memory (also space-mux)

• Means that process can have its address space unloaded when it still needs memory– Usually only happens when it is blocked

Page 16: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Dynamic Address Relocation

CPU

0x02010

0x10000+

MARload R1, 0x02010

0x12010

•Program loaded at 0x10000 Relocation Register = 0x10000•Program loaded at 0x04000 Relocation Register = 0x04000

Relocation Register

Relative Address

We never have to change the load module addresses!

Page 17: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Runtime Bound Checking

CPU

Relative Address

Relocation Register

+

MAR

Limit Register <

Interrupt

•Bound checking is inexpensive to add•Provides excellent memory protection

Page 18: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Memory Hierarchies – Dynamic LoadingCPU Registers

“Main” Memory

Rotating Magnetic Memory

Optical Memory

Sequentially Accessed Memory

L1 Cache MemoryL2 Cache Memory

Sec

onda

ryP

rim

ary

(Exe

cuta

ble)

Lar

ger

stor

age

Fas

ter

acce

ss

Page 19: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Exploiting the Hierarchy• Upward moves are (usually) copy operations

– Require allocation in upper memory

– Image exists in both higher & lower memories

• Updates are first applied to upper memory• Downward move is (usually) destructive

– Destroy image in upper memory

– Update image in lower memory

• Place frequently-used info high, infrequently-used info low in the hierarchy

• Reconfigure as process changes phases

Page 20: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

Memory Mgmt Strategies• Fixed-Partition used only in batch systems• Variable-Partition used everywhere (except

in virtual memory)• Swapping systems

– Popularized in timesharing– Relies on dynamic address relocation– Now dated

• Dynamic Loading (Virtual Memory)– Exploit the memory hierarchy– Paging -- mainstream in contemporary systems– Segmentation -- the future

Page 21: Memory Management. Memory Manager Requirements –Minimize executable memory access time –Maximize executable memory size –Executable memory must be cost-effective.

NT Memory-mapped Files

Memorymapped

files

Memorymapped

files

Executable memory

Secondary memory

Ordinary file

•Open the file•Create a section object (that maps file)•Identify point in address space to place the file

Sectionobject