Operating System Support
Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary
Principles of Operating Systems
Network Operating System (1)
General structure of a network operating system.
1-19
Principles of Operating Systems
Network Operating System (2)
rlogin machine rcp machine1:file1 machine2:file2 A better approach (in terms of convenience and sharing): client server approach, shared global file server
Principles of Operating Systems
Network Operating System (3)
Different clients may mount the servers in different places.
1.21
Principles of Operating Systems
Distributed Operating Systems
But no longer have shared memory
Provide message passing Can try to provide distributed shared memory
But tough to get acceptable performance
Principles of Operating Systems
Middleware and the Operating System
What is a distributed OS?
Presents users (and applications) with an integrated computing platform that hides the individual computers. Has control over all of the nodes (computers) in the network and allocates their resources to tasks without user involvement. In a distributed OS, the user doesn't know (or care) where his programs are running.
Examples:
Cluster computer systems
Principles of Operating Systems V system, Sprite
Combination of middleware and network OS
No distributed OS in general use
Users have much invested in their application software Users tend to prefer to have a degree of autonomy for their machines
Network OS provides autonomy Middleware provides network-transparent access resource
Principles of Operating Systems
Chapter 5: Operating System Support
Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary
Principles of Operating Systems
The relationship between OS and Middleware
Operating System
Tasks: processing, storage and communication Components: kernel, library, user-level services
Middleware
runs on a variety of OS-hardware combinations remote invocations
Architecture
Principles of Operating Systems
Functions that OS should provide for middleware Encapsulation
provide a set of operations that meet their clients needs
Protection
protect resource from illegitimate access
Concurrent processing
support clients access resource concurrently
Invocation mechanism: a means of accessing an encapsulated resource
Communication
Pass operation parameters and results between resource managers
Scheduling
Schedule the processing ofOperating the invoked Principles of Systems operation
The core OS components
Process manager
Handles the creation of and operations upon processes.
Thread manager
Thread creation, synchronization and scheduling
Communication manager
Communication between threads attached to different processes on the same computer
Memory manager
Management of physical and virtual memory
Supervisor
Dispatching of interrupts, system call traps and other exceptions control of memory management unit and hardware caches processor and floating point unit register manipulations
Figure
Principles of Operating Systems
Positioning Middleware
Network OSs are not transparent. Distributed OSs are not independent of computers.
Middleware can help.
Principles of Operating Systems
Middleware
What is middleware? What is its function? Where is it located? Why does it exist?
Principles of Operating Systems
Positioning Middleware
General structure of a distributed system as middleware.
Principles of Operating Systems
Figure 2.1 Software and hardware service layers in distributed systems
Applications, serv ic es
Middleware
Operating s y stem Platf orm Computer and network hardware
Principles of Operating Systems
Middleware and Openness
1.23
In an open middleware-based distributed system, the protocols used by each middleware layer should be the same, as well as the interfaces they offer to applications. Why should they be open? Why should they not be open?
Principles of Operating Systems
Typical Middleware Services
Communication Naming Persistence Distributed transactions Security
Principles of Operating Systems
Middleware Models
Distributed files
Examples?
Remote procedure call
Examples?
Distributed objects
Examples?
Distributed documents
Examples?
Others?
Message-oriented middleware (MOM) Service oriented architecture (SOA) Document-oriented
Principles of Operating Systems
Middleware and the Operating System
Middleware implements abstractions that support networkwide programming. Examples:
RPC and RMI (Sun RPC, Corba, Java RMI) event distribution and filtering (Corba Event Notification, Elvin) resource discovery for mobile and ubiquitous computing support for multimedia streaming
Traditional OS's (e.g. early Unix, Windows 3.0)
simplify, protect and optimize the use of local resources
Network OS's (e.g. Mach, modern UNIX, Windows NT)
do the same but they also support a wide range of communication standards and enable remote processes to access (some) local resources (e.g. files).
Principles of Operating Systems
DOS vs. NOS vs. Middleware Discussion
What is good/bad about DOS?
Transparency Other issues have reduced success. Problems are often socio-technological.
What is good/bad about NOS?
Simple. Decoupled, easy to add/remove. Lack of transparency.
What is good/bad about middleware?
Easy to make multiplatform. Easy to start something new.
But this can also be bad.
Principles of Operating Systems
Types of Distributed OSs
System DOS Description Main Goal
Tightly-coupled operating system for multiprocessors and homogeneous multicomputers
Loosely-coupled operating system for heterogeneous multicomputers (LAN and WAN) Additional layer atop of NOS implementing general-purpose services
Hide and manage hardware resources
Offer local services to remote clients
NOS
Middleware
Provide distribution transparency
Principles of Operating Systems
Chapter 5: Operating System Support
Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary
Principles of Operating Systems
Illegitimate access
Maliciously contrived code Benign code
contains a bug have unanticipated behavior
Example: read and write in File System
Illegal user vs. access right control Access the file pointer variable directly (setFilePointerRandomly) vs. type-safe language
Typesafe language, e.g. Java or Modula-3 Non-type-safe language, e.g. C or C++
Principles of Operating Systems
Kernel and Protection
Kernel
always runs complete access privileges for the physical resources
Different execution mode
An address space: a collection of ranges of virtual memory locations, in each of which a specified combination of memory access rights applies, e.g.: read only or read-write supervisor mode (kernel process) / user mode (user process) Interface between kernel and user processes: system call trap
The price for protection
switching between different processes take many processor cycles a system call trap is a more expensive operation than a Principles of Operating Systems simple method call
The System Clock
system clock frequency
clock period(One full period is also called a clock cycle )
"Hertz" (Hz) meaning one cycle per second
10 MHz : 100 nanoseconds 1GHz: 1 nanoseconds
Principles of Operating Systems
Chapter 5: Operating System Support
Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary
Principles of Operating Systems
Operation system concepts (six edition)
Abraham Silberschats, Peter Baer Galvin, Greg Gagne Chapter 4 Processes Chapter 5 Threads
Principles of Operating Systems
Single and Multithreaded Processes
Heavyweight process
Principles of Operating Systems
lightweight process
Process and thread
Process
A program in execution Problem: sharing between related activities are awkward and expensive Nowadays, a process consists of an execution environment together with one or more threads an analogy at page 215
Thread
Abstraction of a single activity Benefits
Responsiveness Resource sharing Economy Utilization of MP architectures
Principles of Operating Systems
Execution environment
the unit of resource management Consist of
An address space Thread synchronization and communication resources such as semaphores and communication interfaces (e.g. sockets) Higher-level resources such as open files and windows
Shared by threads within a process
Principles of Operating Systems
Address space
Address space
a unit of management of a processs virtual memory Up to 232 bytes and sometimes up to 264 bytes consists of one or more regions
Region
an area of continuous virtual memory that is accessible by the threads of the owning process
UNIX address space
Principles of Operating Systems
Address space continued
The number of regions is indefinite
Support a separate stack for each thread access mapped file Share memory between processes
Region can be shared
Libraries Kernel Shared data and communication Copy-on-write
Principles of Operating Systems
Creation of new process in distributed system
Creating process by the operation system
Fork, exec in UNIX
Process creation in distributed system
The choice of a target host The creation of an execution environment, an initial thread
Principles of Operating Systems
Choice of process host
Choice of process host
running new processes at their originators computer sharing processing load between a set of computers
Load sharing policy
Transfer policy: situate a new process locally or remotely? Location policy: which node should host the new process?
Static policy without regard to the current state of the system Adaptive policy applies heuristics to make their allocation decision
Load sharing system
Centralized Hierarchical Decentralized
Migration policy: when&where should migrate the running process?
Principles of Operating Systems
Creation of a new execution environment
Initializing the address space
Statically defined format With respect to an existing execution environment, e.g. fork
Copy-on-write scheme
Principles of Operating Systems
Threads concept and implementation
Process
Thread activations
Activation stacks (parameters, local variables)
Heap (dynamic storage, objects, global variables)
'text' (program code) system-provided resources (sockets, windows, open files)
Principles of Operating Systems
Client and server with threads
Thread 2 makes Receipt & requests to server queuing Thread 1 generates results
Input-output
Requests N threads
Client
Server
The 'worker pool' architecture
Principles of Operating Systems
Alternative server threading architectures
server process I/O
workers
server process per-connection threads
server process per-object threads I/O
remote objects
remote objects
remote objects
a. Thread-per-request
b. Thread-per-connection
c. Thread-per-object
(a) would be useful for UDP-based service, e.g. NTP (b) is the most commonly used - matches the TCP connection model (c) is used where the service is encapsulated as an object. E.g. could have multiple shared whiteboards with one thread each. Each object has only one thread, avoiding the need for thread synchronization within objects.
Principles of Operating Systems
Threads versus multiple processes
Creating a thread is (much) cheaper than a process (~10-20 times) Switching to a different thread in same process is (much) cheaper (5-50 times) Threads within same process can share data and other resources more conveniently and efficiently (without copying or messages) Threads within a process are not protected from each other
State associated with execution environments and threads
Execution environment Address space tables Communication interfaces, open files Semaphores, other synchronization objects List of thread identifiers Thread Saved processor registers Priority and execution state (such as BLOCKED ) Software interrupt handling information Execution environment identifier
Pages of address space resident in memory; hardware cache entries
Principles of Operating Systems
Threads implementation
Threads can be implemented:
in the OS kernel (Win NT, Solaris, Mach) at user level (e.g. by a thread library: C threads, pthreads), or in the language (Ada, Java).
+ + + lightweight - no system calls modifiable scheduler low cost enables more threads to be employed not pre-emptive can exploit multiple processors page fault blocks all threads
hybrid approaches can gain some advantages of both
user-level hints to kernel scheduler hierarchic threads (Solaris 2) event-based (SPIN, FastThreads)
Principles of Operating Systems
Chapter 5: Operating System Support
Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary
Principles of Operating Systems
Communication primitives & protocols
Communication primitives
TCP(UDP) Socket in Unix and Windows DoOperation, getRequest, sendReply in Amoeba Group communication primitives in V system
Protocols and openness
provide standard protocols that enable internetworking between middleware integrate novel low-level protocols without upgrading their application Static stack
new layer to be integrated permanently as a driver
protocol stack be composed on the fly E.g. web browser utilize wide-area wireless link on the road and faster Ethernet connection in the office
Dynamic stack
Principles of Operating Systems
Invocation performance Invocation costs
Different invocations The factors that matter
synchronous/asynchronous, domain transition, communication across a network, thread scheduling and switching
Invocation over the network
Delay: the total RPC call time experienced by a client Latency: the fixed overhead of an RPC, measured by null RPC Throughput: the rate of data transfer between computers in a single RPC An example
Threshold: one extra packet to be sent, might be an extra acknowledge packet is needed Principles of Operating Systems
Support for communication and invocation
The performance of RPC and RMI mechanisms is critical for effective distributed systems.
Typical times for 'null procedure call': Local procedure call < 1 microseconds 10,000 times slower! Remote procedure call ~ 10 milliseconds 'network time' (involving about 100 bytes transferred, at 100 megabits/sec.) accounts for only .01 millisecond; the remaining delays must be in OS and middleware - latency, not communication time.
Factors affecting RPC/RMI performance
marshalling/unmarshalling + operation despatch at the server data copying:- application -> kernel space -> communication buffers thread scheduling and context switching:- including kernel entry protocol processing:- for each protocol layer network access delays:- connection setup, network latency
Principles of Operating Systems
Improve the performance of RPC
Memory sharing
rapid communication between processes in the same computer
Choice of protocol
TCP/UDP
E.g. Persistent connections: several invocations during one
OSs buffer collect several small messages and send them together
Invocation within a computer
Most cross-address-space invocation take place within a computer LRPC (lightweight RPC) Principles of Operating Systems
Asynchronous operation
Performance characteristics of the Internet
High latencies, low bandwidths and high server loads Network disconnection and reconnection. outweigh any benefits that the OS can provide
Asynchronous operation
Concurrent invocations
E.g., the browser fetches multiple images in a home page by concurrent GET requests
Asynchronous invocation: non-blocking call
E.g., CORBA oneway invocation: maybe semantics, or collect result by a separate call
Principles of Operating Systems
Asynchronous operation continued
Persistent asynchronous invocations
Designed for disconnected operation Try indefinitely to perform the invocation, until it is known to have succeeded or failed, or until the application cancels the invocation QRPC (Queued RPC)
Client queues outgoing invocation requests in a stable log Server queues invocation results
The issues to programmers
How user can continue while the results of invocations are still not known?
Principles of Operating Systems
Chapter 5: Operating System Support
Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary
Principles of Operating Systems
Monolithic kernels and microkernels
Monolithic kernel
Kernel is massive: perform all basic operating system functions, megabytes of code and data Kernel is undifferentiated: coded in a non-modular way E.g. Unix Pros: efficiency Cons: lack of structure Kernel provides only the most basic abstractions: address spaces, threads and local interprocess communication All other system services are provided by servers that are dynamically loaded E.g., VM of IBM 370 Pros: extensibility, modularity, free of bugs Cons: relatively inefficiency
Microkernel
Hybrid approaches
Principles of Operating Systems
Chapter 5: Operating System Support
Introduction The operating system layer Protection Processes and Threads Communication and invocation Operating system architecture Summary
Principles of Operating Systems
Summary
Process & thread
A Process consists of multiple threads and an execution environment Multiple-threads: cheaper concurrency, take advantage of multiprocessors for parallelism
Remote invocation cost
Marshalling & unmarshalling data copying packet initialization thread scheduling and context switching Network transmission
OS architecture
Monolithic kernel & microkernel
Principles of Operating Systems
System layers
Applications, serv ic es Middleware
OS: kernel, libraries & serv ers
OS1 Proc es ses, threads , communication, ... Computer & network hardware Node 1
Figure 2.1 Software and hardware service layers in distributed systems
OS2 Proc es ses, threads , communication, ...
Applications, serv ic es
Platf orm
Computer & network hardware
Middleware Operating s y stem
Node 2
Computer and network hardware
Platf orm
Principles of Operating Systems
Core OS functionality
Proc es s manager
Communic ation manager
Thread m anager Superv is or
Memory manager
Principles of Operating Systems
Process address space
2
N
Regions can be shared
Auxiliary regions
kernel code libraries shared data & communication copy-on-write
Stack
Files can be mapped
Mach, some versions of UNIX
UNIX fork() is expensive
Heap
must copy process's address space
Text 0
Principles of Operating Systems
Copy-on-write scheme
Process As address space Process Bs address space
RA
RB copied from RA
RB
Kernel Shared frame
A's page table
B's page table b) After write
Principles of Operating Systems
a) Before write
Alternative server threading architecture
work ers I/O remote objec ts
per-c onnec tion threads
per-objec t threads I/O remote objec ts
remote objec ts
a. Thread-per-request
b. Thread-per-c onnection
c. Thread-per-objec t
Principles of Operating Systems
State associated with execution environments and threads
Execution environment Address space tables Communication interfaces, open files Thread Saved processor registers Priority and execution state (such as BLOCKED) Semaphores, other synchronization objects Software interrupt handling information
List of thread identifiers
Execution environment identifier
Pages of address space resident in memory; hardware cache entries
Principles of Operating Systems
Java Thread constructor and management methods
Thread(ThreadGroup group, Runnable target, String name) Creates a new thread in the SUSPENDED state, which will belong to group and be identified as name; the thread will execute the run() method of target. setPriority(int newPriority), getPriority() Set and return the threads priority. run() A thread executes the run() method of its target object, if it has one, and otherwise its own run() method (Thread implements Runnable). start() Change the state of the thread from SUSPENDED to RUNNABLE. sleep(int millisecs) Cause the thread to enter the SUSPENDED state for the specified time. yield() Enter the READY state and invoke the scheduler. destroy() Destroy the thread.
Principles of Operating Systems
Invocations between address spaces
(a) Sy stem c all Thread Control trans fer v ia trap instruc tion Control trans fer v ia priv ileged ins truc tions Us er Kernel Protec tion domain boundary
(b) R PC/RMI (within one c omputer)
Thread 1
Thread 2
Us er 1
(c) R PC/RMI (between computers)
Kernel
Us er 2
Thread 1
Network
Thread 2
Us er 1 Kernel 1 Kernel 2
Us er 2
Principles of Operating Systems
Delay of an RPC operation when returned data size varies
RPC delay
Request ed dat a size (by t es ) 0 1000 Pack et size
Principles of Operating Systems
2000
A lightweight remote procedure call
Client Serv er
A stac k
A 4. Ex ecute proc edure and copy res ults
1. Copy args
Us er Kernel
stub
stub
2. Trap to Kernel
3. Upc all
5. Return (trap)
Principles of Operating Systems
Times for serialized and concurrent invocations
Serialis ed inv ocat ions proces s args mars hal Send Concurrent inv ocat ions proces s args mars hal Send t rans mis sion proces s args mars hal Send Receiv e unmarshal ex ec ut e reques t mars hal Send Receiv e unmarshal proces s results Receiv e unmarshal proces s results Receiv e unmarshal ex ec ut e reques t mars hal Send
Receiv e unmarshal proces s results proces s args mars hal Send
Receiv e unmarshal ex ec ut e reques t mars hal Send Receiv e unmarshal ex ec ut e reques t mars hal Send
t im e
Receiv e unmarshal proces s results Client Serv er Client Serv er
Principles of Operating Systems
Monolithic kernel and Microkernel
S4 ....... S1 S1 S2 S3 ....... S2 S3 S4 .......
Key : Serv er:
Monolithic Kernel
Microk ernel
Kernel c ode and data:
Dy namic ally loaded s erv er program:
Middleware Language support subsystem Language support subsystem OS emulation subsystem
....
Microkernel
Hardware
The microkernel supports middleware via subsystems
Principles of Operating Systems