Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems...

99
Advanced Operating Systems: Review of Operating System Concepts

Transcript of Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems...

Page 1: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Advanced Operating Systems: Review of Operating System

Concepts

Page 2: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Review of OS Concepts

• Operating System Definition(s)

• Review of Computer System Architecture

• Functions of an Operating Systems

• Design Approaches

• Processes, Threads, Synchronization, and Deadlock

• Motivation for Advanced Operating Systems

• Types of Advanced Operating Systems

2 Review of Operating System Concepts

Page 3: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

What is an Operating System?

• An operating system is a program or a set of programs that manage computer resources

• A program that acts as an intermediary between a user of a computer and the computer hardware

• Operating system goals: – Execute user programs and make solving user

problems easier – Make the computer system convenient to use – Use the computer hardware in an efficient manner

3 Review of Operating System Concepts

Page 4: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Operating System Definition

• OS is a resource allocator

– Manages all resources

– Decides between conflicting requests for efficient and fair resource use

• OS is a control program

– Controls execution of programs to prevent errors and improper use of the computer

4 Review of Operating System Concepts

Page 5: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Operating System Definition (Cont)

• No universally accepted definition

• “Everything a vendor ships when you order an operating system” is good approximation – But varies wildly

• “The one program running at all times on the

computer” is the kernel. – Everything else is either a system program (ships with

the operating system) or an application program

5 Review of Operating System Concepts

Page 6: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Computer System Organization • Computer-system operation

– One or more CPUs, device controllers connect through common bus providing access to shared memory

– Concurrent execution of CPUs and devices competing for memory cycles

6 Review of Operating System Concepts

Page 7: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Computer-System Operation • I/O devices and the CPU can execute concurrently

• Each device controller is in charge of a particular device type

• Each device controller has a local buffer

• CPU moves data from/to main memory to/from local buffers

• I/O is from the device to local buffer of controller

• Device controller informs CPU that it has finished its operation by causing an interrupt

7 Review of Operating System Concepts

Page 8: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

How a Modern Computer Works

8 Review of Operating System Concepts

Page 9: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Computer-System Architecture

• Most systems use a single general-purpose processor (PDAs through mainframes) – Most systems have special-purpose processors as well

• Multiprocessors systems growing in use and importance

– Also known as parallel systems, tightly-coupled systems – Advantages include

• Increased throughput • Economy of scale • Increased reliability – graceful degradation or fault tolerance

– Two types • Asymmetric Multiprocessing • Symmetric Multiprocessing

9 Review of Operating System Concepts

Page 10: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Symmetric Multiprocessing Architecture

10 Review of Operating System Concepts

Page 11: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

A Dual-Core Design

11 Review of Operating System Concepts

Page 12: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Clustered Systems

• Like multiprocessor systems, but multiple systems working together – Usually sharing storage via a storage-area network

(SAN) – Provides a high-availability service which survives

failures • Asymmetric clustering has one machine in hot-standby

mode • Symmetric clustering has multiple nodes running

applications, monitoring each other

– Some clusters are for high-performance computing (HPC) • Applications must be written to use parallelization

12 Review of Operating System Concepts

Page 13: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Operating System Structure

• Multiprogramming needed for efficiency – Single user cannot keep CPU and I/O devices busy at all times – Multiprogramming organizes jobs (code and data) so CPU always has one to

execute – A subset of total jobs in system is kept in memory – One job selected and run via job scheduling – When it has to wait (for I/O for example), OS switches to another job

• Timesharing (multitasking) is logical extension in which CPU switches jobs

so frequently that users can interact with each job while it is running, creating interactive computing – Response time should be < 1 second – Each user has at least one program executing in memory process – If several jobs ready to run at the same time CPU scheduling – If processes don’t fit in memory, swapping moves them in and out to run – Virtual memory allows execution of processes not completely in memory

13 Review of Operating System Concepts

Page 14: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Functions of an Operating System

• Resource Management – Process Management – Time Management (CPU and disk scheduling) – Space Management (memory and disk space) – Accounting and status information

• User Friendliness (The Beautification Principle) – Execution Environment – Error Detection and Handling – Protection and Security – Fault Tolerance and Failure Recovery

14 Review of Operating System Concepts

Page 15: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Management

Page 16: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Management

• A process is a program in execution. It is a unit of work within the system. Program is a passive entity, process is an active entity.

• Process needs resources to accomplish its task – CPU, memory, I/O, files – Initialization data

• Process termination requires reclaim of any reusable resources • Single-threaded process has one program counter specifying

location of next instruction to execute – Process executes instructions sequentially, one at a time, until

completion

• Multi-threaded process has one program counter per thread • Typically system has many processes, some user, some operating

system running concurrently on one or more CPUs – Concurrency by multiplexing the CPUs among the processes / threads

16 Review of Operating System Concepts

Page 17: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Management Activities

• The operating system is responsible for the following activities in connection with process management: – Creating and deleting both user and system

processes

– Suspending and resuming processes

– Providing mechanisms for process synchronization

– Providing mechanisms for process communication

– Providing mechanisms for deadlock handling

17 Review of Operating System Concepts

Page 18: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Diagram of Process State

18 Review of Operating System Concepts

Page 19: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Control Block (PCB)

Information associated with each process • Process state • Program counter • CPU registers • CPU scheduling information • Memory-management information • Accounting information • I/O status information

19 Review of Operating System Concepts

Page 20: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Control Block (PCB)

20 Review of Operating System Concepts

Page 21: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

CPU Switch From Process to Process

21 Review of Operating System Concepts

Page 22: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Scheduling Queues

• Job queue – set of all processes in the system

• Ready queue – set of all processes residing in main memory, ready and waiting to execute

• Device queues – set of processes waiting for an I/O device

• Processes migrate among the various queues

22 Review of Operating System Concepts

Page 23: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Ready Queue And Various I/O Device Queues

23 Review of Operating System Concepts

Page 24: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Creation • Parent process create children processes, which,

in turn create other processes, forming a tree of processes

• Generally, process identified and managed via a process identifier (pid)

• Resource sharing – Parent and children share all resources – Children share subset of parent’s resources – Parent and child share no resources

• Execution – Parent and children execute concurrently – Parent waits until children terminate

24 Review of Operating System Concepts

Page 25: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Creation (Cont.)

• Address space

– Child duplicate of parent

– Child has a program loaded into it

• UNIX examples

– fork system call creates new process

– exec system call used after a fork to replace the process’ memory space with a new program

25 Review of Operating System Concepts

Page 26: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Process Creation

26 Review of Operating System Concepts

Page 27: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

C Program Forking Separate Process

int main()

{

pid_t pid;

/* fork another process */

pid = fork();

if (pid < 0) { /* error occurred */

fprintf(stderr, "Fork Failed");

exit(-1);

}

else if (pid == 0) { /* child process */

execlp("/bin/ls", "ls", NULL);

}

else { /* parent process */

/* parent will wait for the child to complete */

wait (NULL);

printf ("Child Complete");

exit(0);

}

}

27 Review of Operating System Concepts

Page 28: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Context Switch • When CPU switches to another process, the

system must save the state of the old process and load the saved state for the new process via a context switch.

• Context of a process represented in the PCB

• Context-switch time is overhead; the system does no useful work while switching

• Time dependent on hardware support

28 Review of Operating System Concepts

Page 29: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

CPU Switch From Process to Process

29 Review of Operating System Concepts

Page 30: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Interprocess Communication

• Processes within a system may be independent or cooperating

• Cooperating process can affect or be affected by other processes, including sharing data

• Reasons for cooperating processes: – Information sharing – Computation speedup – Modularity – Convenience

• Cooperating processes need interprocess communication (IPC)

• Two models of IPC – Shared memory – Message passing

30 Review of Operating System Concepts

Page 31: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Communications Models

31 Review of Operating System Concepts

Page 32: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Cooperating Processes

• Independent process cannot affect or be affected by the execution of another process

• Cooperating process can affect or be affected by the execution of another process

• Advantages of process cooperation – Information sharing – Computation speed-up – Modularity – Convenience

32 Review of Operating System Concepts

Page 33: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Time Management

Page 34: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Objectives • To introduce CPU scheduling, which is the

basis for multiprogrammed operating systems

• To describe various CPU-scheduling algorithms

• To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system

34 Review of Operating System Concepts

Page 35: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Basic Concepts • Maximum CPU utilization obtained with

multiprogramming

• CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait

• CPU burst distribution

35 Review of Operating System Concepts

Page 36: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Alternating Sequence of CPU and I/O Bursts

36 Review of Operating System Concepts

Page 37: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

CPU Scheduler

• Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them

• CPU scheduling decisions may take place when a process: – Switches from running to waiting state – Switches from running to ready state – Switches from waiting to ready – Terminates

• Scheduling under 1 and 4 is nonpreemptive

• All other scheduling is preemptive

37 Review of Operating System Concepts

Page 38: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Dispatcher • Dispatcher module gives control of the CPU to

the process selected by the short-term scheduler; this involves: – switching context – switching to user mode – jumping to the proper location in the user

program to restart that program

• Dispatch latency – time it takes for the dispatcher to stop one process and start another running

38 Review of Operating System Concepts

Page 39: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Scheduling Criteria

• CPU utilization – keep the CPU as busy as possible

• Throughput – # of processes that complete their execution per time unit

• Turnaround time – amount of time to execute a particular process

• Waiting time – amount of time a process has been waiting in the ready queue

• Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)

39 Review of Operating System Concepts

Page 40: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Scheduling Algorithm Optimization Criteria

• Max CPU utilization

• Max throughput

• Min turnaround time

• Min waiting time

• Min response time

40 Review of Operating System Concepts

Page 41: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

First-Come, First-Served (FCFS) Scheduling

Process Burst Time P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3

The Gantt Chart for the schedule is:

• Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17

P1 P2 P3

24 27 30 0

41 Review of Operating System Concepts

Page 42: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

FCFS Scheduling (Cont.)

• Suppose that the processes arrive in the order: • P2 , P3 , P1 • The Gantt chart for the schedule is:

• Waiting time for P1 = 6; P2 = 0; P3 = 3 • Average waiting time: (6 + 0 + 3)/3 = 3 • Much better than previous case • Convoy effect short process behind long process

P1 P3 P2

6 3 30 0

42 Review of Operating System Concepts

Page 43: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Disk Scheduling • The operating system is responsible for using hardware

efficiently — for the disk drives, this means having a fast access time and disk bandwidth

• Access time has two major components – Seek time is the time for the disk are to move the heads to

the cylinder containing the desired sector – Rotational latency is the additional time waiting for the

disk to rotate the desired sector to the disk head

• Minimize seek time

• Seek time seek distance

• Disk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer

43 Review of Operating System Concepts

Page 44: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Disk Scheduling (Cont.)

• Several algorithms exist to schedule the servicing of disk I/O requests

• We illustrate them with a request queue (0-199)

98, 183, 37, 122, 14, 124, 65, 67

Head pointer 53

44 Review of Operating System Concepts

Page 45: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

FCFS

Illustration shows total head movement of 640 cylinders

45 Review of Operating System Concepts

Page 46: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

SSTF • Selects the request with the minimum seek

time from the current head position

• SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests

• Illustration shows total head movement of 236 cylinders

46 Review of Operating System Concepts

Page 47: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

SSTF (Cont.)

47 Review of Operating System Concepts

Page 48: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Space Management

Page 49: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Memory Management

• All data in memory before and after processing

• All instructions in memory in order to execute

• Memory management determines what is in memory when – Optimizing CPU utilization and computer response to users

• Memory management activities – Keeping track of which parts of memory are currently

being used and by whom

– Deciding which processes (or parts thereof) and data to move into and out of memory

– Allocating and deallocating memory space as needed

49 Review of Operating System Concepts

Page 50: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Paging • Logical address space of a process can be noncontiguous;

process is allocated physical memory whenever the latter is available

• Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8,192 bytes)

• Divide logical memory into blocks of same size called pages

• Keep track of all free frames

• To run a program of size n pages, need to find n free frames and load program

• Set up a page table to translate logical to physical addresses

• Internal fragmentation

50 Review of Operating System Concepts

Page 51: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

• Address generated by CPU is divided into: – Page number (p) – used as an index into a page table

which contains base address of each page in physical memory

– Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit

– For given logical address space 2m and page size 2n

Address Translation Scheme

page number page offset

p d

m - n n

51 Review of Operating System Concepts

Page 52: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Paging Hardware

52 Review of Operating System Concepts

Page 53: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Paging Model of Logical and Physical Memory

53 Review of Operating System Concepts

Page 54: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Paging Hardware With TLB

54 Review of Operating System Concepts

Page 55: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Effective Access Time • Associative Lookup = time unit

• Assume memory cycle time is 1 microsecond

• Hit ratio – percentage of times that a page number is found in

the associative registers; ratio related to number of associative registers

• Hit ratio =

• Effective Access Time (EAT) EAT = (1 + ) + (2 + )(1 – ) = 2 + –

55 Review of Operating System Concepts

Page 56: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Storage Management

• OS provides uniform, logical view of information storage – Abstracts physical properties to logical storage unit - file – Each medium is controlled by device (i.e., disk drive, tape drive)

• Varying properties include access speed, capacity, data-transfer rate, access method (sequential or random)

• File-System management – Files usually organized into directories – Access control on most systems to determine who can access

what – OS activities include

• Creating and deleting files and directories • Primitives to manipulate files and dirs • Mapping files onto secondary storage • Backup files onto stable (non-volatile) storage media

56 Review of Operating System Concepts

Page 57: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Mass-Storage Management

• Usually disks used to store data that does not fit in main memory or data that must be kept for a “long” period of time

• Proper management is of central importance • Entire speed of computer operation hinges on disk subsystem and

its algorithms • OS activities

– Free-space management – Storage allocation – Disk scheduling

• Some storage need not be fast – Tertiary storage includes optical storage, magnetic tape – Still must be managed – Varies between WORM (write-once, read-many-times) and RW (read-

write)

57 Review of Operating System Concepts

Page 58: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

A Typical File Control Block

58 Review of Operating System Concepts

Page 59: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Contiguous Allocation of Disk Space

59 Review of Operating System Concepts

Page 60: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Linked Allocation

60 Review of Operating System Concepts

Page 61: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Example of Indexed Allocation

61 Review of Operating System Concepts

Page 62: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Combined Scheme: UNIX UFS (4K bytes per block)

62 Review of Operating System Concepts

Page 63: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Schematic View of NFS Architecture

63 Review of Operating System Concepts

Page 64: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

RAID Structure

• RAID – multiple disk drives provides reliability via redundancy

• Increases the mean time to failure

• Frequently combined with NVRAM to improve write performance

• RAID is arranged into six different levels

64 Review of Operating System Concepts

Page 65: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

RAID (Cont.) • Several improvements in disk-use techniques involve the use of

multiple disks working cooperatively

• Disk striping uses a group of disks as one storage unit

• RAID schemes improve performance and improve the reliability of the storage system by storing redundant data – Mirroring or shadowing (RAID 1) keeps duplicate of each disk – Striped mirrors (RAID 1+0) or mirrored stripes (RAID 0+1)

provides high performance and high reliability – Block interleaved parity (RAID 4, 5, 6) uses much less

redundancy

• RAID within a storage array can still fail if the array fails, so automatic replication of the data between arrays is common

• Frequently, a small number of hot-spare disks are left unallocated, automatically replacing a failed disk and having data rebuilt onto them

65 Review of Operating System Concepts

Page 66: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

RAID Levels

66 Review of Operating System Concepts

Page 67: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

RAID (0 + 1) and (1 + 0)

67 Review of Operating System Concepts

Page 68: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Protection and Security

• Protection – any mechanism for controlling access of processes or users to resources defined by the OS

• Security – defense of the system against internal and external attacks – Huge range, including denial-of-service, worms, viruses, identity theft, theft of

service

• Systems generally first distinguish among users, to determine who can do

what – User identities (user IDs, security IDs) include name and associated number,

one per user – User ID then associated with all files, processes of that user to determine

access control – Group identifier (group ID) allows set of users to be defined and controls

managed, then also associated with each process, file – Privilege escalation allows user to change to effective ID with more rights

68 Review of Operating System Concepts

Page 69: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Design Approaches

• Separation of mechanism and policy

– Policy: what should be done?

– Mechanism: how to do it?

• Good operating systems must separate policies from mechanisms.

– Policies make use of underlying mechanisms

– Results in a more flexible and adaptive system

69 Review of Operating System Concepts

Page 70: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Transition from User to Kernel Mode

• Timer to prevent infinite loop / process hogging resources – Set interrupt after specific period – Operating system decrements counter – When counter zero generate an interrupt – Set up before scheduling process to regain control or terminate

program that exceeds allotted time

70 Review of Operating System Concepts

Page 71: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Design Approach (cont.)

• Layered Approach

– Modular design

– Each layer provides entry points for higher layers

– Each layer can only use functions from lower layer(s)

– The challenging part is splitting the OS functionality appropriately such that there are no circular dependencies

71 Review of Operating System Concepts

Page 72: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

72 Review of Operating System Concepts

Page 73: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

73 Review of Operating System Concepts

Page 74: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

74 Review of Operating System Concepts

Page 75: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Design Approaches (cont.)

• Kernel-Based Approach – A small set of truly primitive operations – Mechanism only – Policy decisions are made outside the kernel

– Demand for more complex mechanism has “bloated

kernels” • Too much in kernel low flexibility • Too little in kernel low functionality

– Example is Hydra

75 Review of Operating System Concepts

Page 76: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

76 Review of Operating System Concepts

Page 77: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Design Approaches (cont.)

• Virtual Machine Approach

– Give each user the illusion he has the machine to himself

– The virtual machine can have different capabilities than the real machine

– Each user can run a different OS

– Example: VM Ware, VM /370, VM/CMS

77 Review of Operating System Concepts

Page 78: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

78 Review of Operating System Concepts

Page 79: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

79 Review of Operating System Concepts

Page 80: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Synchronization

• What is a process?

• Concurrent processes

• The critical section problem

• Other synchronization problems

• Language mechanisms for synchronization

80 Review of Operating System Concepts

Page 81: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Concurrent Processes

• Concurrency - simultaneous execution of multiple threads of control – concurrency appears in:

• mutiprogramming - management of multiple processes on a uniprocessor architecture

• mutliprocessing - management of multiple processes on a multiprocessor architecture

• distributed computing - management of multiple processes on multiple independent computers

• Synchronization — using atomic (indivisible) operations to ensure

cooperation between threads

• Race Condition - the outcome of the multiple process execution depends on the order of the execution of the instructions of the processes

81 Review of Operating System Concepts

Page 82: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Concurrent Processes (cont.)

• Two processes are concurrent if their execution can overlap in time – Multiprocessor systems

• Different processors executing different processes

– Uniprocessor systems • Time-slicing, or interleaving computations and I/O

• Two processes are serial if one must complete before the other begins

• Concurrent processes normally interact either through shared variables or through message passing

• If two processes don’t interact, they are transparent to each other (we do not care)

82 Review of Operating System Concepts

Page 83: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Concurrent Processes (cont.)

Thread A Thread B

i = 0 i = 0 while (i < 10) while (i > –10) i = i + 1 i = i – 1 print “A wins” print “B wins”

• Assumptions:

– Memory load and store are atomic

– Increment and decrement at not atomic

• Questions:

– Who wins?

– Is it guaranteed that someone wins?

– What if both threads have their own CPU, running concurrently at exactly the same speed? Is it guaranteed that it goes on forever?

– What if they are sharing a CPU?

83 Review of Operating System Concepts

Page 84: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Solution to Critical-Section Problem

• Mutual Exclusion - If process Pi is executing in its critical section, then no other processes can be executing in their critical sections

• Progress - If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely

• Bounded Waiting - A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted – Assume that each process executes at a nonzero speed – No assumption concerning relative speed of the N processes

84 Review of Operating System Concepts

Page 85: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Solutions to Critical-Section Problems

• Busy waiting

• Disabling interrupts

• Test-and-set

• Swap

• Binary semaphores

85 Review of Operating System Concepts

Page 86: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Other Synchronization Problems

• Dining Philosophers Problem – N Processes, N resources, a process requires two adjacent resources to execute – Care must be taken to avoid starvation and deadlock

• Producer-Consumer Problem

– A set of producer processes supplies input to a set of consumer processes – Producer’s cannot produce if there is no space – Consumer’s cannot consume if there is no input – Two producers should not fill the same space and consumers should not consume the same

input

• Readers-Writers Problem

– Shared data exists – Either one writer or multiple readers can access it at one time – Writer’s priority gives priority to arriving writers over waiting readers – Reader’s priority gives priority to arriving readers over waiting writers

86 Review of Operating System Concepts

Page 87: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Deadlock

• Deadlock occurs when a set of processes in a system is blocked waiting on requirements that can never be satisfied

87 Review of Operating System Concepts

Page 88: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Deadlock

• A wait-for-graph (WFG) can be used to represent the state of a system

• The nodes in the graph represent processes, and a directed edge between nodes means that the process at the tail of the edge is waiting for a resource held by the process at the head

• A cycle in the WFG indicates a deadlock

88 Review of Operating System Concepts

Page 89: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Deadlock

89 Review of Operating System Concepts

Page 90: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Deadlock vs. Starvation

• Starvation occurs when a process waits for a resource that is repeatedly available but is never assigned to the waiting process

• Two differences between deadlock and starvation – With starvation, it is not certain that a process will never get the

resource. With deadlock, a process is blocked forever (absent outside intervention)

– With starvation, the requested resource is used continuously; with deadlock, it is idle

• Recall the readers-writers problem as an example of starvation

90 Review of Operating System Concepts

Page 91: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Deadlock Characterization

• Deadlock can arise if four conditions hold simultaneously. • Four necessary conditions for deadlock to occur:

– Mutual exclusion: only one process at a time can use a resource

– Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes

– No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task

– Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0.

91 Review of Operating System Concepts

Page 92: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Deadlock Handling Strategies

• Deadlock Prevention – Ensure that at least one of the four necessary conditions cannot hold. – For example, do not allow a process to hold resources and ask for others – Design time

• Deadlock Avoidance

– Check each resource request and make sure that granting it will not cause deadlock. – The Banker’s Algorithm is an example of deadlock avoidance – Run-Time

• Deadlock Detection and Recovery

– Periodically check the state of the system and look for a deadlock. – If one is present, break it, typically by aborting processes

• Ignore It

92 Review of Operating System Concepts

Page 93: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Computing Environments

• Traditional computer – Blurring over time

– Office environment • PCs connected to a network, terminals attached to

mainframe or minicomputers providing batch and timesharing

• Now portals allowing networked and remote systems access to same resources

– Home networks • Used to be single system, then modems

• Now firewalled, networked

93 Review of Operating System Concepts

Page 94: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Computing Environments (Cont) Client-Server Computing

Dumb terminals supplanted by smart PCs

Many systems now servers, responding to requests generated by clients

Compute-server provides an interface to client to request services (i.e. database)

File-server provides interface for clients to store and retrieve files

94 Review of Operating System Concepts

Page 95: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Peer-to-Peer Computing

• Another model of distributed system

• P2P does not distinguish clients and servers – Instead all nodes are considered peers – May each act as client, server or both – Node must join P2P network

• Registers its service with central lookup service on network, or

• Broadcast request for service and respond to requests for service via discovery protocol

– Examples include Napster and Gnutella

95 Review of Operating System Concepts

Page 96: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Web-Based Computing

• Web has become ubiquitous

• PCs most prevalent devices

• More devices becoming networked to allow web access

• New category of devices to manage web traffic among similar servers: load balancers

• Use of operating systems like Windows 95, client-side, have evolved into Linux and Windows XP, which can be clients and servers

96 Review of Operating System Concepts

Page 97: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Motivation for Advanced Operating Systems

• Early OS design focused on “traditional” OS, running large, uniprocessor systems

• The 1970’s and 1980’s saw huge gains in processor and network technology

• Economies of scale lead to multiprocessor systems

• Conventional OS’s are insufficient for the task

• Therefore, research into advanced OS design was (and still is) needed

97 Review of Operating System Concepts

Page 98: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Types of Advanced Operating Systems

• Distributed Operating Systems – Loosely-coupled systems (no shared memory or clock) – Spatially separated processes – Interconnection network – Typically a set of workstations or LAN or WAN

• Multiprocessor (Parallel) OS

– Tightly-coupled systems (shared memory, clock, often bus-based)

– Spatially adjacent processors – Interconnection network – “Typically a bunch of mP in a box”

98 Review of Operating System Concepts

Page 99: Advanced Operating Systems: Review of Operating … · •Motivation for Advanced Operating Systems •Types of Advanced Operating Systems Review of Operating System Concepts 2 .

Types of Advanced Operating Systems (cont.)

• Database OS – Special purpose to support database operations – Transactions – Facilities for concurrency control – Failure recovery – Airline reservations, credit card transactions, stock market

• Real-Time OS

– Not time-sharing (non-interactive) – A set of jobs, each with a deadline – OS provides guarantees that jobs will finish by deadline – Factory floor automation, safety sytems

• Multimedia OS

99 Review of Operating System Concepts