Memory Management Memory Manager Requirements Minimize primary - - PowerPoint PPT Presentation

memory management memory manager
SMART_READER_LITE
LIVE PREVIEW

Memory Management Memory Manager Requirements Minimize primary - - PowerPoint PPT Presentation

Memory Management Memory Manager Requirements Minimize primary memory access time Maximize primary memory size Primary memory must be cost-effective Todays memory manager: Allocates primary memory to processes Maps


slide-1
SLIDE 1

Memory Management

slide-2
SLIDE 2

Memory Manager

¥ Requirements

Ð Minimize primary memory access time Ð Maximize primary memory size Ð Primary 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

slide-3
SLIDE 3

Address Space vs Primary Memory

Mapped to object

  • ther than memory

Process Address Space Primary Memory

slide-4
SLIDE 4

Building the Address Space

Source code

Translation

Library code

¥Compose elements

Other

  • bjects
slide-5
SLIDE 5

Building the Address Space

Source code

Translation

Library code

Secondary memory

¥Compose elements ¥Adjust addresses ¥Translation time ¥Load time

Other

  • bjects

Process address space

slide-6
SLIDE 6

Building the Address Space

Source code

Translation

Library code

Loader Process address space Executable memory Secondary memory

¥Compose elements ¥Adjust addresses ¥Translation time ¥Load time ¥Allocate executable memory space

Other

  • bjects
slide-7
SLIDE 7

Memory Hierarchies

CPU Registers Cache Memory Primary Memory Rotating Magnetic Memory Optical Memory Sequentially Accessed Memory Executable Memory Secondary Memory

slide-8
SLIDE 8

Memory Hierarchies

CPU Registers Cache Memory Primary Memory Rotating Magnetic Memory Optical Memory Sequentially Accessed Memory Executable Memory Secondary Memory

slide-9
SLIDE 9

Managing the Hierarchy

¥ Move across executable-secondary memory boundary (or lower) requires I/O operation ¥ Upward moves are copy operations

Ð Require allocation in upper memory Ð Image exists in both memories

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

Ð Deallocate upper memory Ð Updates image in secondary memory

slide-10
SLIDE 10

Memory Allocation

Operating System Process 3 Process 0 Process 2 Process 1 Unused In Use

slide-11
SLIDE 11

Fixed-Partition Memory

Operating System Region 3 Region 2 Region 1 Region 0 N0 N1 N2 N3 pi pi needs ni units ni

slide-12
SLIDE 12

Fixed-Partition Memory -- Best-Fit

Operating System Region 3 Region 2 Region 1 Region 0 N0 N1 N2 N3 pi Internal Fragmentation ¥Loader must adjust every address in the absolute module when placed in memory

slide-13
SLIDE 13

Fixed-Partition Memory -- Worst-Fit

Operating System Region 3 Region 2 Region 1 Region 0 N0 N1 N2 N3 pi

slide-14
SLIDE 14

Fixed-Partition Memory -- First-Fit

Operating System Region 3 Region 2 Region 1 Region 0 N0 N1 N2 N3 pi

slide-15
SLIDE 15

Fixed-Partition Memory -- Next-Fit

Operating System Region 3 Region 2 Region 1 Region 0 N0 N1 N2 N3 pi Pi+1

slide-16
SLIDE 16

Variable Partition Memory

Operating System

slide-17
SLIDE 17

Variable Partition Memory

Operating System Operating System Process 0 Process 1 Process 2 Process 3 Process 4 ¥Loader must adjust every address in every absolute module when placed in memory

slide-18
SLIDE 18

Variable Partition Memory

Operating System Operating System Process 0 Process 1 Process 2 Process 3 Operating System Process 4 Process 0 Process 6 Process 2 Process 5 Process 4 ¥External fragmentation

slide-19
SLIDE 19

Variable Partition Memory

Operating System Operating System Process 0 Process 1 Process 2 Process 3 Operating System Operating System Process 4 Process 0 Process 6 Process 2 Process 5 Process 4 Process 0 Process 6 Process 2 Process 5 Process 4 ¥Compaction moves program in memory

slide-20
SLIDE 20

Cost of Moving Programs

load R1, 0x02010 3F013010

Program loaded at 0x01000

slide-21
SLIDE 21

Cost of Moving Programs

load R1, 0x02010 3F013010

Program loaded at 0x01000

3F016010

Program loaded at 0x04000 ¥Must run loader over program again!

slide-22
SLIDE 22

Dynamic Memory Allocation

¥ Common to use dynamically allocated memory ¥ Process wants to change the size of its address space

Ð Smaller ⇒ Creates an external fragment Ð Larger ⇒ Have to move/relocate the program

¥ Allocate ÒholesÓ in memory according to

Ð Best- /Worst- / First- /Next-fit

slide-23
SLIDE 23

Swapping

¥ 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

¥ Have same problems as dynamic memory allocation

slide-24
SLIDE 24

Dynamic Address Relocation

CPU

Relative Address Relocation Register

+

MAR load R1, 0x02010 3F012010

¥Program loaded at 0x01000 ⇒ Relocation Register = 0x01000 ¥Program loaded at 0x04000 ⇒ Relocation Register = 0x04000

slide-25
SLIDE 25

Runtime Bound Checking

CPU

Relative Address Relocation Register

+

MAR Limit Register

< ∧ Interrupt

slide-26
SLIDE 26

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

¥ Virtual Memory

Ð Paging -- mainstream in contemporary systems Ð Segmentation -- the future

slide-27
SLIDE 27

NT Memory-mapped Files

Memory mapped 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

Section

  • bject