CS 423 Operating System Design: Historical Memory Management - - PowerPoint PPT Presentation

cs 423 operating system design historical memory
SMART_READER_LITE
LIVE PREVIEW

CS 423 Operating System Design: Historical Memory Management - - PowerPoint PPT Presentation

CS 423 Operating System Design: Historical Memory Management Tianyin Xu (MIC) * Thanks for Prof. Adam Bates for the slides. CS 423: Operating Systems Design Storage Hierarchy CPU Registers Size Performance 32-64 bits Cache 4-128 words


slide-1
SLIDE 1

CS 423: Operating Systems Design

Tianyin Xu (MIC)

CS 423 Operating System Design: Historical Memory Management

* Thanks for Prof. Adam Bates for the slides.

slide-2
SLIDE 2

CS 423: Operating Systems Design

Storage Hierarchy

2

CPU Registers Cache Memory Secondary Storage

Performance Size 32-64 bits 4-128 words 512-16k words

slide-3
SLIDE 3

CS 423: Operating Systems Design

Problem Statement

3

We have limited amounts of fast resources, and large amounts of slower resources… How to create the illusion of an abundant fast resource?

slide-4
SLIDE 4

CS 423: Operating Systems Design

Overlay Area

History: Mem Overlays

4

Overlay Manager Main Program Overlay 1 Overlay 2 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

slide-5
SLIDE 5

CS 423: Operating Systems Design

Overlay 1

History: Mem Overlays

5

Overlay Manager Main Program Overlay 1 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

Overlay 2

slide-6
SLIDE 6

CS 423: Operating Systems Design

History: Mem Overlays

6

Overlay Manager Main Program Overlay 1 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

Overlay Area Overlay 2

slide-7
SLIDE 7

CS 423: Operating Systems Design

Overlay 2

History: Mem Overlays

7

Overlay Manager Main Program Overlay 1 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

Overlay 2

slide-8
SLIDE 8

CS 423: Operating Systems Design

History: Mem Overlays

8

Overlay Manager Main Program Overlay 1 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

Overlay Area Overlay 2

slide-9
SLIDE 9

CS 423: Operating Systems Design

History: Mem Overlays

9

Overlay Manager Main Program Overlay 1 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

Overlay 3 Overlay 2

slide-10
SLIDE 10

CS 423: Operating Systems Design

History: Mem Overlays

10

Overlay Manager Main Program Overlay 1 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

Overlay Area Overlay 2

slide-11
SLIDE 11

CS 423: Operating Systems Design

Overlay 1

History: Mem Overlays

11

Overlay Manager Main Program Overlay 1 Overlay 3 Secondary Storage

0K 5k 7k 12k

Used when process memory requirement exceeded the physical memory space

Overlay 2

slide-12
SLIDE 12

CS 423: Operating Systems Design 12

0k 4k 16k 64k 128k

  • Approach: Multiprogramming

with fixed memory partitions

  • Divides memory into n fixed

partitions (possibly unequal)

  • Problem?

Free Space

History: Fixed Partition Allocation

slide-13
SLIDE 13

CS 423: Operating Systems Design 13

0k 4k 16k 64k 128k

  • Approach: Multiprogramming

with fixed memory partitions

  • Divides memory into n fixed

partitions (possible unequal)

  • Problem?

Program 1 Program 2 Program 3

Free Space

History: Fixed Partition Allocation

slide-14
SLIDE 14

CS 423: Operating Systems Design 14

Free Space 0k 4k 16k 64k 128k

  • Approach: Multiprogramming

with fixed memory partitions

  • Divides memory into n fixed

partitions (possible unequal)

  • Problem?
  • Internal Fragmentation

History: Fixed Partition Allocation

Program 1 Program 2 Program 3

slide-15
SLIDE 15

CS 423: Operating Systems Design 15

History: Fixed Partition Allocation

■ Separate input queue for each partition

■ Sorting incoming jobs into separate queues ■ Inefficient utilization of memory

■ when the queue for a large partition is empty but the

queue for a small partition is full. Small jobs have to wait to get into memory even though plenty of memory is free.

■ One single input queue for all partitions.

■ Allocate a partition where the job fits in.

slide-16
SLIDE 16

CS 423: Operating Systems Design 16

History: Relocation

■ Correct starting address when a program should start in the

memory

■ Different jobs will run at different addresses

When a program is linked, the linker must know at what address the program will begin in memory.

■ Enter “Logical addresses”

Logical address space , range (0 to max)

Physical addresses, Physical address space range (R+0 to R+max) for base value R.

User program never sees the real physical addresses

■ Relocation register

Mapping requires hardware with the base register

slide-17
SLIDE 17

CS 423: Operating Systems Design 17

History: Relocation Register

Memory Base Register CPU Instruction Address + BA MA MA+BA Physical Address Logical Address

slide-18
SLIDE 18

CS 423: Operating Systems Design

Monitor Monitor Monitor Monitor Monitor

18

History: Variable Partition Allocation

Job 1 Job 2 Job 3 Job 4 Free 1 Job 1 Job 3 Job 4 Free 2 Job 1 Job 3 Job 4 Free Job 5 3 Job 3 Job 4 Free Job 5 Job 6 4 Job 3 Free Job 5 Job 6 Job 7 Job 8 5 Memory wasted by External Fragmentation

slide-19
SLIDE 19

CS 423: Operating Systems Design 19

History: Storage Placement Strategy

■ Best Fit?

■ Use the hole whose size is equal to the need, or if none is

equal, the hole that is larger but closest in size.

■ Problem: Creates small holes that can't be used

■ First Fit?

■ Use the first available hole whose size is sufficient to meet

the need.

■ Problem: Creates average size holes.

■ Next Fit?

■ Minor variation of first fit: search from the last hole used. ■ Problem: slightly worse performance than first fit.

■ Worst Fit?

■ Use the largest available hole. ■ Problem: Gets rid of large holes making it difficult to run

large programs.

slide-20
SLIDE 20

CS 423: Operating Systems Design

Virtual Memory

20

■ Provide user with virtual memory that is as big as

user needs

■ Store virtual memory on disk ■ Cache parts of virtual memory being used in real

memory

■ Load and store cached virtual memory without user

program intervention

slide-21
SLIDE 21

CS 423: Operating Systems Design

Paging

21

3 1 2 3 4 Memory Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 1 2 3 4 Page Table VM Frame

Request Page 3…

slide-22
SLIDE 22

CS 423: Operating Systems Design 22

Paging

3 1 1 2 3 4 Memory Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 1 2 3 4 Page Table VM Frame

Request Page 1…

slide-23
SLIDE 23

CS 423: Operating Systems Design 23

Paging

3 1 1 6 2 3 4 Memory Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 1 2 3 4 Page Table VM Frame

Request Page 6…

slide-24
SLIDE 24

CS 423: Operating Systems Design 24

Paging

3 1 1 6 2 3 4 Memory Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 1 2 3 4 Page Table VM Frame 2

Request Page 2…

slide-25
SLIDE 25

CS 423: Operating Systems Design 25

Paging

Request Page 8. Swap Page 1 to Disk First…

3 1 1 6 2 3 4 Memory Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 1 2 3 4 Page Table VM Frame 2

slide-26
SLIDE 26

CS 423: Operating Systems Design 26

Paging

Request Page 8. … now load Page 8 into Memory.

3 1 6 2 3 4 Memory Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 1 2 3 4 Page Table VM Frame 2 8

slide-27
SLIDE 27

CS 423: Operating Systems Design

Shared Pages

27

Note: Virtual Memory also supports shared pages.

slide-28
SLIDE 28

CS 423: Operating Systems Design

Page Mapping Hardware

28

Contents(P,D) Contents(F,D) P D F D P→F 1 1 1 1 Page Table Virtual Memory Virtual Address (P,D) Physical Address (F,D) P F D D 4 Physical Memory

slide-29
SLIDE 29

CS 423: Operating Systems Design

Page Mapping Hardware

29

Contents(4006) Contents(5006) 004 006 005 006 4→5 1 1 1 1 Page Table Virtual Memory Physical Memory Virtual Address (004006) Physical Address (F,D) 004 005 006 006 4 Page size 1000 Number of Possible Virtual Pages 1000 Number of Page Frames 8

slide-30
SLIDE 30

CS 423: Operating Systems Design

Page Faults

30

■ Occur when we access a virtual page that is not

mapped into any physical page

■ A fault is triggered by hardware

■ Page fault handler (in OS’s VM subsystem)

■ Find if there is any free physical page available

■ If no, evict some resident page to disk (swapping space)

■ Allocate a free physical page ■ Load the faulted virtual page to the prepared physical

page

■ Modify the page table

slide-31
SLIDE 31

CS 423: Operating Systems Design

Reasoning about Page Tables

31

■ On a 32 bit system we have 2^32 B virtual address space ■ i.e., a 32 bit register can store 2^32 values

■ # of pages are 2n (e.g., 512 B, 1 KB, 2 KB, 4 KB…)

■ Given a page size, how many pages are needed? ■ e.g., If 4 KB pages (2^12 B), then 2^32/2^12=… ■ 2^20 pages required to represent the address space ■ But! each page entry takes more than 1 Byte of space to

represent.

■ suppose page size is 4 bytes (Why?) ■ (2*2) * 2^ 20 = 4 MB of space required to represent our

page table in physical memory.

■ What is the consequence of this?

slide-32
SLIDE 32

CS 423: Operating Systems Design

Paging Issues

32

■ Page size is 2n

■ usually 512 bytes, 1 KB, 2 KB, 4 KB, or 8 KB ■ E.g. 32 bit VM address may have 220 (1 MB) pages with

4k (212) bytes per page

■ Page table:

■ 220 page entries take 222 bytes (4 MB) ■ Must map into real memory ■ Page Table base register must be changed for context

switch

■ No external fragmentation; internal fragmentation on

last page only