Operating Systems
Steven Hand Michaelmas Term 2010 12 lectures for CST IA
Operating Systems — N/H/MWF@12
Operating Systems Steven Hand Michaelmas Term 2010 12 lectures for - - PowerPoint PPT Presentation
Operating Systems Steven Hand Michaelmas Term 2010 12 lectures for CST IA Operating Systems N/H/MWF@12 Course Aims This course aims to: explain the structure and functions of an operating system, illustrate key operating system
Operating Systems — N/H/MWF@12
Operating Systems — Aims i
Operating Systems — Outline ii
Operating Systems — Books iii
Operating Systems — Introduction 1
Operating Systems — Introduction 2
Operating Systems — Evolution 3
Operating Systems — Evolution 4
Operating System Job 1 Job 2 Job 3 Job 4 Operating System Job 1 Job 2 Job 3 Job 4 Operating System Job 1 Job 2 Job 3 Job 4
Operating Systems — Evolution 5
Operating Systems — Evolution 6
H/W S/W App. App. App.
Scheduler Device Driver Device Driver
App.
Operating Systems — Structures & Protection Mechanisms 7
Kernel Mode User Mode reset interrupt or fault set user mode
Operating Systems — Structures & Protection Mechanisms 8
Operating System Job 1 Job 2 Job 3 Job 4
0x0000 0x3000 0x5000 0x9800 0xD800 0xFFFF 0x5000 0x4800 limit register base register
Operating Systems — Structures & Protection Mechanisms 9
vector to OS (address error) yes no yes no
base base+limit
Operating Systems — Structures & Protection Mechanisms 10
Operating Systems — Structures & Protection Mechanisms 11
H/W S/W App. Priv Unpriv App. App. App. Kernel
Scheduler Device Driver Device Driver System Calls File System Protocol Code
Operating Systems — Structures & Protection Mechanisms 12
H/W S/W
App.
Priv Unpriv
Server Device Driver Server Server App. App. App.
Kernel Scheduler
Device Driver
Operating Systems — Structures & Protection Mechanisms 13
Operating Systems — Structures & Protection Mechanisms 14
Operating Systems — Functions 15
△
Operating Systems — Processes 16
Exit Running New Ready Blocked
dispatch timeout
release admit event-wait event
Operating Systems — Processes 17
Process Number (or Process ID) Current Process State Other CPU Registers Memory Mangement Information CPU Scheduling Information Program Counter Other Information (e.g. list of open files, name of executable, identity of owner, CPU time used so far, devices owned) Refs to previous and next PCBs
Operating Systems — Processes 18
Process A Process B Operating System
Save State into PCB A Restore State from PCB B Save State into PCB B Restore State from PCB A
idle idle idle executing executing executing
Operating Systems — Processes 19
admit
release timeout or yield dispatch
event-wait event
create (batch) (interactive) create
Operating Systems — Process Life-cycle 20
Operating Systems — Process Life-cycle 21
Operating Systems — Process Life-cycle 22
Operating Systems — Process Life-cycle 23
CPU Burst Duration (ms) Frequency
2 4 6 8 10 12 14 16
Operating Systems — Process Life-cycle 24
Operating Systems — CPU Scheduling 25
Operating Systems — CPU Scheduling 26
Operating Systems — CPU Scheduling 27
P
1
P
2
P
3
25 29 36
P
1
P
2
P
3
7 11 36
Operating Systems — CPU Scheduling 28
P
1
P
3
P
2
P
4
7 8 12 16
Operating Systems — CPU Scheduling 29
P
1
P
3
P
2
P
4
2 4 5 7 11 16 P
2
P
1
Operating Systems — CPU Scheduling 30
Operating Systems — CPU Scheduling 31
Operating Systems — CPU Scheduling 32
Operating Systems — CPU Scheduling 33
t+1 = f(uj t, pj t, uj t−1, pj t−1, . . .)
t+1 = pj t/2 + kuj t
Operating Systems — CPU Scheduling 34
Operating Systems — Memory Management 35
Operating Systems — Relocation 36
Operating Systems — Relocation 37
address fault no yes physical address
limit
base
logical address Relocation Register
Operating Systems — Relocation 38
Operating Systems — Contiguous Allocation 39
Partitioned Memory
Run Queue Blocked Queue
A B C D
Backing Store Main Store
OS
Operating Systems — Contiguous Allocation 40
0000 0C04 2200 3810 4790 91E8 B0F0 B130 D708 FFFF
Operating Systems — Contiguous Allocation 41
400K 1000K 2000K 2300K 2560K
OS P1 P2 P3 OS P1 P3 OS P1 P4 P3 OS P3 OS P5 P3 P4 P4
400K 1000K 2000K 2300K 2560K 1700K 400K 1000K 2000K 2300K 2560K 1700K 900K
Operating Systems — Contiguous Allocation 42
OS P1 P2 P3 OS P1 P3 OS P1 P4 P3 OS P3 P4 P4 P5 P6 OS P5 P3 P4 OS P5 P3 P4
Operating Systems — Contiguous Allocation 43
300K 1000K 1500K 1900K 2100K
OS P1 P3 P4
500K 600K
P2
1200K
400K 300K 200K
300K 800K 2100K
OS P1 P3 P4
500K 600K
P2
1200K
900K
300K 1000K 2100K
OS P1 P4 P3
500K 600K
P2
1200K
900K
300K 2100K
OS P1 P4 P3
500K 600K
P2
1500K
900K
1900K
Operating Systems — Contiguous Allocation 44
logical address physical address
Operating Systems — Paging 45
Page 0 Page 0 Page 1 Page 2 Page n-1 Page 3 Page 4 Page 1 Page 4 Page 3 1 2 3 4 5 6 7 8
1 1 1 1 4 6 2 1
Virtual Memory Physical Memory
Operating Systems — Paging 46
Operating Systems — Paging 47
logical address physical address
p1 p2 p3 p4 f1 f2 f3 f4
Operating Systems — Paging 48
Operating Systems — Paging 49
P1 Offset
Virtual Address L2 Address L1 Page Table
n N
P2 L1 Address
Base Register L2 Page Table
n N
Leaf PTE
Operating Systems — Paging 50
PTA V D R W U S W T C D A C Z O P S IGN
1024 entries
L1 L2 Offset
Virtual Address 20 bits
Operating Systems — Paging 51
PFA V D R W U S W T C D A C D Y Z O IGN
1024 entries
G L L1 L2 Offset
Virtual Address 20 bits
Operating Systems — Paging 52
Frame Number V X W R K
Operating Systems — Paging 53
Operating Systems — Paging 54
Operating Systems — Demand Paged Virtual Memory 55
Operating Systems — Demand Paged Virtual Memory 56
Operating Systems — Demand Paged Virtual Memory 57
Operating Systems — Page Replacement Algorithms 58
Operating Systems — Page Replacement Algorithms 59
Operating Systems — Page Replacement Algorithms 60
Operating Systems — Page Replacement Algorithms 61
Operating Systems — Page Replacement Algorithms 62
FIFO CLOCK LRU OPT
Page Faults per 1000 References
5 10 15 20 25 30 35 40 45 5 6 7 8 9 10
Number of Page Frames Available
11 12 13 14 15
Operating Systems — Page Replacement Algorithms 63
Operating Systems — Frame Allocation 64
CPU utilisation Degree of Multiprogramming
thrashing
Operating Systems — Frame Allocation 65
0x10000 0x20000 0x30000 0x40000 0x50000 0x60000 0x70000 0x80000 0x90000 0xa0000 0xb0000 0xc0000 10000 20000 30000 40000 50000 60000 70000 80000 Miss address Miss number Extended Malloc Initial Malloc I/O Buffers User data/bss User code User Stack VM workspace Kernel data/bss Kernel code Parse Optimise Output Kernel Init
move image clear bss Timer IRQs connector daemon
Operating Systems — Frame Allocation 66
Operating Systems — Frame Allocation 67
procedure stack main() symbols sys library stack sys library procedure symbols main() Limit Base 1 2 3 4 1 2 3 4 1000 200 5000 200 300 200 5200 5300 5600 5700 5900 6900 5900 200 5700 5300
Logical Address Space Physical Memory Segment Table
Operating Systems — Segmentation 68
Operating Systems — Segmentation 69
Operating Systems — Segmentation 70
Per-process Segment Tables
Physical Memory
Shared
A B A B
System Segment Table [DANGEROUS] [SAFE]
Operating Systems — Segmentation 71
Operating Systems — Segmentation 72
Operating Systems — Segmentation 73
Operating Systems — Virtual Addressing Summary 74
logical address physical address fault (to OS) translation
Operating Systems — Virtual Addressing Summary 75
Operating Systems — I/O Subsystem 76
Device Driver Layer
Device Driver Device Driver Device Driver
Common I/O Functions
Keyboard HardDisk Network
Device Layer Virtual Device Layer
H/W Unpriv Priv
I/O Scheduling I/O Buffering
Application-I/O Interface
Operating Systems — I/O Subsystem 77
status command data (r/w)
device-busy (R/O) command-ready (W/O) error (R/O) read (W/O) write (W/O)
*
Operating Systems — I/O Subsystem 78
Operating Systems — I/O Subsystem 79
Operating Systems — I/O Subsystem 80
Operating Systems — I/O Subsystem 81
Operating Systems — I/O Subsystem 82
Operating Systems — I/O Subsystem 83
Operating Systems — I/O Subsystem 84
Operating Systems — I/O Subsystem 85
Directory Service Storage Service Disk Handler
text name user file-id information requested from file user space I/O subsystem filing system
Operating Systems — Filing Systems 86
Operating Systems — Files and File Meta-data 87
Name SFID hello.java 23812 Makefile 12353 README 9742
Operating Systems — Files and File Meta-data 88
Type (file or directory) Location on Disk Size in bytes Time of creation Access permissions
File Control Block Metadata Table (on disk)
f(SFID) SFID
Operating Systems — Files and File Meta-data 89
Operating Systems — Directories 90
Ann Bob Yao
java mail A B C G H I J sent F E D
Operating Systems — Directories 91
Ann Bob Yao java mail A B C D E F G H I J sent
Operating Systems — Directories 92
/Ann/mail/B
Ann Bob Yao Name SFID 1034 179 7182 mail A Name SFID 2165 5797 sent B C Name SFID 434 2459 25 D D D Y Y Y Y Y N N N
Operating Systems — Directories 93
UFID SFID File Control Block (Copy) 1 2 3 4 23421 3250 10532 7122 location on disk, size,... " " " " " "
Operating Systems — Filesystem Interface 94
current file position end of file start of file already accessed to be read
Operating Systems — Filesystem Interface 95
Operating Systems — Filesystem Interface 96
Operating Systems — Protection 97
Operating Systems — Protection 98
Operating Systems — Protection 99
Operating Systems — Protection 100
Operating Systems — Protection 101
Operating Systems — Protection 102
Operating Systems — Protection 103
Operating Systems — Protection 104
Operating Systems — Protection 105
Operating Systems — Protection 106
Operating Systems — Protection 107
Operating Systems — Protection 108
Unix Case Study— Introduction 109
System V SVR2 SVR3 SVR4 4.2BSD 4.3BSD 4.3BSD/Tahoe 4.3BSD/Reno 4.4BSD Eighth Edition Ninth Edition Tenth Edition Mach OSF/1 SunOS 4 Solaris Solaris 2 SunOS SunOS 3 First Edition Fifth Edition Sixth Edition Seventh Edition 3BSD 4.0BSD 4.1BSD System III 32V 1974 1975 1977 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1969 1973 1976 1978 1979 1980 1981 1982
Unix Case Study— Introduction 110
Unix Case Study— Overview 111
System Call Interface Application (Process) Application (Process) Application (Process)
Kernel User Hardware
Process Management Memory Management
Block I/O Char I/O
File System
Device Driver Device Driver Device Driver Device Driver
Unix Case Study— Overview 112
Unix Case Study— Files and the Filesystem 113
etc/ bin/ usr/ dev/ home/ steve/ unix.ps index.html jean/ hda hdb tty
Unix Case Study— Files and the Filesystem 114
Unix Case Study— Files and the Filesystem 115
type mode timestamps (x3) direct blocks (x12) single indirect double indirect triple indirect direct blocks (512) data data data data data data
to block with 512 single indirect entries to block with 512 double indirect entries
userid groupid size nblocks nlinks flags
Unix Case Study— Files and the Filesystem 116
home/ steve/ jean/
doc/
unix.ps index.html 214 78 385 56 Filename I-Node misc 47
unix.ps hello.txt 2 78 107 13 Filename I-Node
misc/ index.html unix.ps hello.txt bin/
Unix Case Study— Files and the Filesystem 117
Super-Block Boot-Block
Inode Table Data Blocks
Super-Block
Inode Table Data Blocks
Partition 1 Partition 2
Hard Disk
1 2 i i+1 j j+1 j+2 l l+1 m
Unix Case Study— Files and the Filesystem 118
etc/ bin/ usr/ dev/ home/ hda1 hda2 hdb1 steve/ jean/
Root File-System File-System
Unix Case Study— Files and the Filesystem 119
Process A Process B 1 2 3 4 N 11 3 25 17 1 6 1 2 3 4 N 2 27 62 5 17 32 47 1 17 135 78
process-specific file tables system-wide
Inode 78
acitve inode table
Unix Case Study— Files and the Filesystem 120
Owner Group World
R W E R W E R W E
Owner Group World
R W E R W E R W E
Unix Case Study— Files and the Filesystem 121
Unix Case Study— Files and the Filesystem 122
Unix Case Study— Files and the Filesystem 123
grows downward as functions are called grows upwards as more memory allocated
Unix Case Study— Processes 124
execve exit fork wait parent process program executes child process zombie process parent process (potentially) continues
Unix Case Study— Processes 125
Unix Case Study— Processes 126
execve child process program executes fg? repeat ad infinitum yes no fork read get command line issue prompt write exit wait zombie process
Unix Case Study— Processes 127
# pwd /home/steve # ls -F IRAM.micro.ps gnome_sizes prog-nc.ps Mail/ ica.tgz rafe/ OSDI99_self_paging.ps.gz lectures/ rio107/ TeX/ linbot-1.0/ src/ adag.pdf manual.ps store.ps.gz docs/ past-papers/ wolfson/ emacs-lisp/ pbosch/ xeno_prop/ fs.html pepsi_logo.tif # cd src/ # pwd /home/steve/src # ls -F cdq/ emacs-20.3.tar.gz misc/ read_mem.c emacs-20.3/ ispell/ read_mem* rio007.tgz # wc read_mem.c 95 225 2262 read_mem.c # ls -lF r*
1 steve user 34956 Mar 21 1999 read_mem*
1 steve user 2262 Mar 21 1999 read_mem.c
1 steve user 28953 Aug 27 17:40 rio007.tgz # ls -l /usr/bin/X11/xterm
2 root system 164328 Sep 24 18:21 /usr/bin/X11/xterm*
Unix Case Study— Processes 128
Unix Case Study— Processes 129
Process B Process A
read(fd, buf, n) write(fd, buf, n)
new data free space
Unix Case Study— Interprocess Communication 130
Unix Case Study— Interprocess Communication 131
Hardware
Device Driver Device Driver Device Driver Device Driver
Generic File System Layer
Buffer Cache Raw Block I/O Raw Character I/O Cooked Character I/O
Kernel Kernel User
Unix Case Study— I/O Subsystem 132
Unix Case Study— I/O Subsystem 133
Unix Case Study— Process Scheduling 134
schedule wakeup sleep interrupt exit syscall return return preempt same state
Unix Case Study— Process Scheduling 135
Unix Case Study— Summary 136
NT Case Study— Introduction & Overview 137
NT Case Study— Introduction & Overview 138
NT Case Study— Introduction & Overview 139
OS/2 Subsytem
OS/2 Applications Win32 Applications Kernel Mode User Mode Hardware
Native NT Interface (Sytem Calls)
Object Manager Process Manager VM Manager I/O Manager
Win32 Subsytem POSIX Subsytem Security Subsytem
MS-DOS Applications Posix Applications Win16 Applications Logon Process
MS-DOS Subsytem Win16 Subsytem
ERNEL
K
EVICE
D
Hardware Abstraction Layer (HAL)
RIVERS
D
File System Drivers Cache Manager Security Manager LPC Facility XECUTIVE
E
NT Case Study— Introduction & Overview 140
NT Case Study— Low-level Functions 141
NT Case Study— Low-level Functions 142
NT Case Study— Low-level Functions 143
Temporary/Permanent
Object Header
Type Object
Type Name Common Info. Open Close Delete Parse Security Query Name Object Name Object Directory Security Descriptor Open Handle Count Reference Count Type Object Pointer Quota Charges Open Handles List
Object Body
Object-Specfic Data (perhaps including a kernel object) Methods: Process 1 Process 2 Process 3
NT Case Study— Executive Functions 144
??\ device\ BaseNamedObjects\ driver\ doc\ exams.tex A: C: COM1: Harddisk0\ Serial0\ Floppy0\ Partition1\ Partition2\ winnt\ temp\
NT Case Study— Executive Functions 145
NT Case Study— Executive Functions 146
NT Case Study— Executive Functions 147
I/O Manager File System Driver Intermediate Driver Device Driver HAL
I/O Requests
NT Case Study— Executive Functions 148
NT Case Study— Executive Functions 149
A B
8 7 4 EOF Free Free Free 3 n-2 Free EOF
Disk Info
1 2 6 7 8 9 n-1
File Name (8 Bytes)
AD R VSH
Extension (3 Bytes) Reserved (10 Bytes)
Time (2 Bytes) Date (2 Bytes) First Cluster (2 Bytes)
File Size (4 Bytes)
Attribute Bits
A: Archive D: Directory V: Volume Label S: System H: Hidden R: Read-Only
NT Case Study— Microsoft File Systems 150
NT Case Study— Microsoft File Systems 151
File Record
Master File Table (MFT)
1 2 3 4 5 6 7 16 17
$Mft $MftMirr $LogFile $Volume $AttrDef \ $Bitmap $BadClus
user file/directory user file/directory 15 Standard Information Filename Data...
NT Case Study— Microsoft File Systems 152
NT Case Study— Microsoft File Systems 153
Partition A1
Hard Disk A Hard Disk B
Partition A2 Partition A3 Partition B1 Partition B2
NT Case Study— Microsoft File Systems 154
NT Case Study— Microsoft File Systems 155
NT Case Study— User Mode Components 156
NT Case Study— Summary 157
NT Case Study— Summary 158
NT Case Study— Summary 159
NT Case Study— Summary 160
NT Case Study— Glossary 161
NT Case Study— Glossary 162
NT Case Study— Glossary 163
NT Case Study— Glossary 164