• 沒有找到結果。

Operating Systems Concept

N/A
N/A
Protected

Academic year: 2022

Share "Operating Systems Concept"

Copied!
8
0
0

加載中.... (立即查看全文)

全文

(1)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Operating Systems Concept

?What is an operating system?

?Operating system architecture

?Process concept

?CPU scheduling

?Memory management

?File and I/O systems

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Memory Management

?Logical address vs Physical Address

* “Operating system concept”, Silberschatz and Galvin, Addison Wesley, pp. 245-246.

CPU

Logical Address for Instructions or Data

Memory Management

Unit

Physical Address

Process Image Memory Process

Image

PC

(2)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Memory Management

?Contiguous Allocation

?Single Partition

* “Operating system concept”, Silberschatz and Galvin, Addison Wesley, pp. 249-264.

The User Process Memory

OS

CPU

Memory Management

Unit

If logical -address < Limit-Register Then

physical-address = logical address + Relocation -Register Else

Signal the user process!

Limit-Register Relocation-Register

345

10000

10345

5000

Memory Management

?Contiguous Allocation

?Multiple Partitions

P1 OS

400K

1000K

P2

2000K P3

2300K 2560K

P1 OS

400K

1000K

P4

2000K P3

2300K 2560K 1700K -P2+P4

P5 OS

400K

1000K

P4

2000K P3

2300K 2560K 1700K -P1+P5

900K

3holes = 660KB!!!

(3)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Memory Management

?Contiguous Allocation

?Multiple Partitions

?First-Fit

?Best-Fit

?Worst-Fit

?Fragmentation

?External

?Internal P5

OS

400K

1000K

P4

2000K P3

2300K 2560K 1700K

900K P5

OS

400K

P6

2300K 2560K 1700K 900K

Next request is for 819000B, i.e., 800KB-200B

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Memory Management

?Solutions to Fragmentation

?Compaction

P5

400K OS

1300K

P4

2000K P3

2300K 2700K 1700K 1000K

P5

400K OS

1400K P4

P3

2700K 1700K 1000K

Move 700KB!

P5

400K OS

P4

2000K P3

2300K 2700K 1000K

P5

400K OS

1300K

P4 P3

2700K 1700K 1000K

Move 400KB! Move 300KB!

(4)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Memory Management

?Paging – Another solution to external fragmentation!

Page 0 Page 1 Page 2 Page 3

Frame #

Page 0

Page 2 Page 1

Page 3

7 3

3 2

4 1

1 0

Frame # Page #

0 1 2 3 4 5 6

logical 7

memory

physical memory A page

table for each process

Paging

? Address Translation

page number offset

p bits d bits

frame number offset

f bits d bits

F

P D

Logical Addr.

P

F D

(5)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Paging

Page 0 Page 1 Page 2 Page 3

physical address

Page 0

Page 2 Page 1

Page 3

111 11

011 10

100 01

001 00

F P

00000 00100 01000 01100 10000 10100 11000 11100

logical memory

physical memory page

table

P D

2 bits 2 bits

F D

3 bits 2 bits

0000 0100 1000 1100

01 10 100 10

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Paging

Page 0 Page 1 Page 2 Page 3

physical address

Page 0

Page 2 Page 1

Page 3

111 11

011 10

100 01

001 00

F P

00000 00100 01000 01100 10000 10100 11000 11100

logical memory

physical memory page

table

0000 0100 1000 1100

1100 A 1101 B 1110 C 1111 D

Page 3

11100 A 11101 B 11110 C 11111 D

Frame 7

(6)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Paging

?Hardware Support for Paging

?Registers as Page Tables

?Memory-Resident Page Tables

?Translation Look-aside Buffer (TLB)

F

P D

P

F D

P F

TLB

Paging

? Paging-TLB

?TLB Hit

?Access time = TLB-access-time + Inst/Data- Memory -Access

?E.g., 20ns + 100ns

?TLB Miss

?Access Time = TLB-access-time + Page- Table-Memory-Access + Inst/Data-Memory- Access

?E.g., 20ns + 100ns + 100ns

? Hit Ratio 80%

?Effective access time = 20ns + 100ns +

0.2 *100ns = 140ns

(7)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Virtual Memory

?Definition

?A technique that allows the execution of

processes that may not be completed in memory.

?Swapping

?Process image may reside in the backing store rather than swap the entire image in.

?Page fault: occurs when program references a non-memory-resident page.

?Thrashing

?A process is spending more time in page faults than executing.

* “Operating system concept”, Silberschatz and Galvin, Addison Wesley, pp. 289,291-293,317.

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Context Switching-Revisiting

?Def.

?Switch the CPU from one process to another process

?Save the state (or called context) of the running process

?Reload the state of the ready process

?Context Switching Time

?Hardware-dependent!

?Multiple register sets!

?Special hardware instructions!

(8)

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.

Process Concept-Revisiting

?Process Control Block Struct PCB {

char p_pid;

char p_pri;

char p_ppid;

int pc; /* program counter */

int files[NFILE];

} PCB[NPROC];

參考文獻

相關文件

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.. Operating

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005!.

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.. Operating

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.. Operating

* All rights reserved, Tei-Wei Kuo, National Taiwan University,

* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.. Operating

* All rights reserved, Tei-Wei Kuo, National Taiwan University,

* All rights reserved, Tei-Wei Kuo, National Taiwan University,