An Operating Systems Vade Mecum
Total Page:16
File Type:pdf, Size:1020Kb
An Operating Systems Vade Mecum Raphael A. Finkel University of Wisconsin at Madison Prentice Hall Englewood Cliffs, New Jersey 07632 Contents iii CONTENTS PREFACE xi Chapter 1 INTRODUCTION 1 1 Philosophy of the book 1 2 The Resource Principle 3 3 Historical development 4 3.1 Open shop 4 3.2 Operator-driven shop 5 3.3 Of¯ine transput 6 3.4 Spooling systems 8 3.5 Batch multiprogramming 8 3.6 Interactive multiprogramming 11 3.7 Distributed computing 12 4 The Beauti®cation Principle 12 5 The kernel and processes 14 5.1 Context blocks 14 5.2 Process lists 17 5.3 Service calls 17 6 Virtual machines 20 7 Further reading 24 8 Exercises 25 Chapter 2 TIME MANAGEMENT 27 1 Goals, measures, and assumptions 29 2 Policies 31 2.1 First come, ®rst served (FCFS) 34 2.2 Round robin (RR) 37 2.3 Shortest process next (SPN) 39 2.4 Preemptive shortest process next (PSPN) 41 2.5 Highest penalty ratio next (HPRN) 41 2.6 Multiple-level feedback (FB) 42 2.7 Sel®sh round robin (SRR) 44 2.8 Hybrid methods 46 2.9 State-dependent priority methods 46 2.10 External priority methods 47 3 Perspective 47 3.1 Classi®cation of scheduling policies 48 3.2 Evaluating policies 49 3.3 Scheduling levels 51 3.4 Countermeasures 52 3.5 Guiding principles 52 4 Further reading 53 iv Contents 5 Exercises 54 Chapter 3 SPACE MANAGEMENT 57 1 Preliminaries 57 1.1 Swapping 57 1.2 Storage hierarchies 58 1.3 Physical and virtual store 59 1.4 Address translation 60 1.5 Sharing 62 1.6 Initial loading and execution 63 2 Fixed partitions 65 2.1 Security 67 2.2 Overlays 69 3 Single segment 70 3.1 Mechanism 70 3.2 Bene®ts 73 3.3 Placement and replacement policies 74 4 Two segments 76 5 Segmentation 77 5.1 Implementation 78 5.2 Storing the necessary information 81 5.3 Swapping 81 5.4 Large segment spaces 82 5.5 Shared segments 83 5.6 Unusable space 83 5.7 Initial loading and execution 84 6 Paging 85 6.1 Implementation 87 6.2 Security and sharing 90 6.3 Case study: Multics 91 6.4 Case study: VAX 96 6.5 Paging in virtual machines 97 7 Page-replacement policies 101 7.1 Random replacement 103 7.2 Min 104 7.3 First in, ®rst out (FIFO) 105 7.4 Least recently used (LRU) 107 7.5 Not used recently (NUR) 108 7.6 Second-chance cyclic 110 7.7 Global policies 110 7.8 Working set 111 7.9 Page-fault frequency (PFF) 112 7.10 Working size 112 7.11 WSCLOCK 113 7.12 Missing Used ®eld 113 7.13 Classi®cation of replacement methods 113 When is a page swapped in? 114 Contents v Which page should be swapped out? 114 Startup-phase con¯icts. 115 8 Perspective 116 9 Further reading 118 10 Exercises 118 Chapter 4 RESOURCE DEADLOCK 121 1 Nuts and bolts 122 2 Deadlock and starvation 124 3 Dining philosophers 128 4 One-shot allocation 131 5 Hierarchical allocation 132 6 Advance-claim algorithm 133 7 Deadlock detection 138 8 Deadlock recovery 141 9 Starvation 141 10 Perspective 142 11 Further reading 144 12 Exercises 144 Chapter 5 TRANSPUT 147 1 Device hardware 148 1.1 Disks 148 1.2 Magnetic tape 150 1.3 Drums 152 1.4 Communication lines 152 Hardware characteristics. 153 Synchronous transmission. 153 Asynchronous transmission. 154 1.5 Summary of device characteristics 155 2 The device interface 156 2.1 Device registers 156 2.2 Direct memory access (DMA) 158 2.3 Channels 159 3 Device drivers 160 3.1 Two levels of device driver 161 3.2 Clock device driver 162 3.3 Terminal device drivers 163 3.4 Disk device drivers 164 4 Data modi®cation 168 4.1 Data compaction 168 4.2 Data encryption 168 4.3 Reliability 170 5 The process interface 172 5.1 To block or not to block 173 5.2 Main-store addresses 174 vi Contents 5.3 Implementing the service calls 177 5.4 Buffer depletion 179 6 Perspective 181 7 Further reading 182 8 Exercises 182 Chapter 6 FILE STRUCTURES 185 1 Naming structure of ®les 186 1.1 One-level (¯at) directories 187 1.2 Two-level directories 188 1.3 Aliases and indirect ®les 189 1.4 Hierarchical directories 192 2 Access control 195 2.1 A formal model of access control 196 2.2 Capability lists 198 2.3 Access lists 199 2.4 Directories and access control 202 2.5 Aliases and indirect ®les 204 3 Access methods 205 3.1 Sequential access 205 3.2 Direct access 206 3.3 Mapped access 206 3.4 Structured ®les 207 3.5 Databases 207 4 File recovery 208 4.1 Dumps 208 4.2 Backup ®les and versions 209 4.3 Partial deletion 210 5 Transactions 211 5.1 Synchronization atomicity 211 5.2 Failure atomicity 213 6 Physical representation 214 6.1 Allocation 215 6.2 File layout 217 6.3 Disk layout 222 6.4 Multiple disks 223 6.5 Multiple machines 225 6.6 Implementing transactions 227 7 Perspective 228 8 Further reading 231 9 Exercises 231 Chapter 7 THE USER INTERFACE 234 1 The command interpreter 235 1.1 Invoking programs and establishing environments 236 1.2 The User Principle 237 Contents vii 1.3 Interacting with programs 240 1.4 Advanced features 242 Wild cards. 242 History. 243 Command completion. 243 Subordinate command interpreters. 244 Redirection of transput. 244 Bit-mapped displays. 246 2 Interactive programs 248 3 Utility programs 249 3.1 Document preparation 249 3.2 Program preparation 250 3.3 Data management 251 3.4 Communication 253 4 Perspective 253 5 Further reading 254 6 Exercises 255 Chapter 8 CONCURRENCY 256 1 The problems 257 1.1 Mutual exclusion 258 1.2 Synchronization 259 2 Mechanisms 260 2.1 Disable interrupts 261 2.2 Busy wait on MutEx 262 2.3 Switch variable 263 2.4 Non-alternating switch 265 2.5 Locks 267 2.6 Semaphores 268 2.7 Critical regions 271 2.8 Conditional critical regions 272 2.9 Monitors 273 2.10 Crowd monitors 280 2.11 Event counts and sequencers 281 2.12 Path expressions 284 2.13 Invariant expressions 287 3 Perspective 289 4 Further reading 290 5 Exercises 291 Chapter 9 CO-OPERATING PROCESSES 294 1 Process creation and naming 295 1.1 Service calls 296 1.2 Programming language syntax 296 2 Inter-process communication 297 2.1 Semaphores 297 viii Contents 2.2 Virtual interrupts 297 2.3 Pipes 298 2.4 Ports 301 Data. 302 Access. 302 Naming and transfer. 303 2.5 Semantics of Read and Write 307 3 Distributed operating systems 308 3.1 Multiprocessors 308 3.2 Local-area networks 309 3.3 Long-haul networks 311 3.4 Multicomputers 312 4 The communication-kernel approach 313 4.1 Processes and threads 314 4.2 Communication 315 4.3 Space management 316 4.4 Other services 316 5 Perspective 317 6 Further reading 318 7 Exercises 319 REFERENCES 322 GLOSSARY 328 INDEX 352 Contents ix Balance is a registered trademark of Sequent Computer Systems, Inc. CMS is a registered trademark of IBM. CP/M is a registered trademark of Digital Research. Cray-1 is a registered trademark of Cray Research. Cray-2 is a registered trademark of Cray Research. Cyber is a registered trademark of Control Data Corporation. DEC is a registered trademark of Digital Equipment Corporation. DECnet is a registered trademark of Digital Equipment Corporation. Dynix is a registered trademark of Sequent Computer Systems, Inc. Exec-8 is a registered trademark of Sperry Rand. IBM is a registered trademark of International Business Machines Corporation. Locus is a registered trademark of Locus Computing Corporation. MS-DOS is a registered trademark of Microsoft Corporation. MVS is a registered trademark of IBM. NonStop is a registered trademark of Tandem Computers. OS/360 is a registered trademark of IBM. PDP-10 is a registered trademark of Digital Equipment Corporation. PDP-11 is a registered trademark of Digital Equipment Corporation. RT-11 is a registered trademark of Digital Equipment Corporation. Tenex is a registered trademark of BBN. Tops-10 is a registered trademark of Digital Equipment Corporation. Tops-20 is a registered trademark of Digital Equipment Corporation. Univac is a registered trademark of Sperry Rand. Unix is a registered trademark of Bell Laboratories. VAX is a registered trademark of Digital Equipment Corporation. VM/370 is a registered trademark of IBM. VMS is a registered trademark of Digital Equipment Corporation. PREFACE Traditionally, a vade mecum (pronounced ``VAHdee MAYkem'') is a laboratory manual that guides the student step by step through complex procedures. Operating systems are complex mixtures of policy and mechanism, of algorithm and heuristic, and of theoretical goals and practical experience. This vade mecum tries to unify these diverse points of view and guide the novice step by step through the complexities of the subject. As a text, this book is intended for a ®rst course in operating systems at the undergraduate level. The subject has so many individual parts that its practitioners and teachers often concen- trate on subareas and ignore the larger concepts that govern the entire subject. I have tried to rectify that situation in this book by structuring the presentation about the dual ideas of resource management and beauti®cation. To unify disparate threads of discussion, I have taken the liberty introducing names for recurrent themes and glorifying them with the title ``principles.'' I hope that this organization and nomenclature will help the reader to understand the subject better and to integrate new ideas into the same framework.