Operating System Support
Total Page:16
File Type:pdf, Size:1020Kb
Teaching material based on Distributed Systems: Concepts Learning objectives and Design, Edition 3, Addison-Wesley 2001. Distributed Systems Course Operating System Support Know what a modern operating system does to support distributed applications and middleware – Definition of network OS Copyright © George Coulouris, Jean Dollimore, – Definition of distributed OS Tim Kindberg 2001 Chapter 6: email: [email protected] This material is made 6.1 Introduction Understand the relevant abstractions and available for private study and for direct use by individual teachers. 6.2 The operating system layer techniques, focussing on: It may not be included in any product or employed in any – processes, threads, ports and support for invocation service without the written 6.4 Processes and threads permission of the authors. mechanisms. 6.5 Communication and invocation Viewing: These slides must be viewed in Understand the options for operating system slide show mode. 6.6 operating system architecture architecture – monolithic and micro-kernels 2 * System layers Middleware and the Operating System Figure 6.1 Middleware implements abstractions that support network- wide programming. Examples: Applications, services RPC and RMI (Sun RPC, Corba, Java RMI) event distribution and filtering (Corba Event Notification, Elvin) Middleware resource discovery for mobile and ubiquitous computing support for multimedia streaming Figure 2.1 Software and hardware service layers in distributed systems OS: kernel, OS1 OS2 libraries & Processes, threads, Processes, threads, Traditional OS's (e.g. early Unix, Windows 3.0) servers communication, ... communication,Applications, services ... Platform – simplify, protect and optimize the use of local resources Middleware Computer & Computer & Network OS's (e.g. Mach, modern UNIX, Windows NT) network hardware network hardware Operating system – do the same but they also support a wide range of communication Node 1 Node 2 Platform standards and enable remote processes to access (some) local Computer and network hardware resources (e.g. files). 3 * 4 * Networked OS to Distributed OS The support required by middleware and distributed applications Distributed OS OS manages the basic resources of computer – Presents users (and applications) with an integrated systems computing platform that hides the individual computers. Tasks: – Has control over all of the nodes (computers) in the network and allocates their resources to tasks without user – programming interface for these resources: involvement. abstractions such as: processes, virtual memory, files, communication channels In a distributed OS, the user doesn't know (or care) where his programs are running. Protection of the resources used by applications – One OS managing resources on multiple machines Concurrent processing – provide the resources needed for (distributed) services and – Examples: applications: Cluster computer systems Communication - network access Amoeba, V system, Sprite, Globe OS Processing - processors scheduled at the relevant computers 5 6 * 1 Core OS functionality Protection: Figure 6.2 Why does the kernel need to be protected? Kernels and protection – kernel has all privileges for the physical resources, processor, memory.. Process manager execution mode – kernel and user address space Communication – kernel and user manager user transferred to kernel - system call trap try to invoke kernel resources Thread manager Memory manager switch to kernel mode cost Supervisor – switching overhead to provide protection 7 * 8 Processes and Threads (1) Processes and Threads (2) process has one environment Address space – unit of management of a process' virtual memory thread: activity, "thread" of execution in one environment Regions – Text, heap, stack execution environment: Each region – an address space – beginning virtual address and size – read/write/exe permissions for the process' threads – synchronization and communication resources – growth direction – i/o resources Why regions: – different functionalities, for example: why execution environment? different stack regions for threads memory-mapped file threads share one execution environment, why? Shared memory regions among processes? – libraries older names: heavyweight and lightweight processes – kernel – data sharing and communication Address space 9 10 Processes and Threads (3): Process address space Processes and Threads (4): process creation Distributed OS Figure 6.3 N – choice of target host 2 – actual creation of execution env choice of target host Auxiliary – transfer policy: local or remote? regions – location policy: if not local, which host/processor V and Sprite system: user has a command and OS chooses Amoeba: a run server decides, more transparent static and adaptive location policies Stack – static: predetermined function – adaptive: depends on current state of the processing nodes load-sharing systems – centralized: one load manager Heap – hierarchical: tree of managers – decentralized: nodes exchange information, local decision Text – sender-initiated 0 – receiver-initiated process migration – moved while it's running 11 12 * – what need to be sent? 2 Processes and Threads (5) Processes and Threads (6): Copy-on-write Figure 6.4 creating an execution env Process A’s address space Process B’s address space – address space with initial contents RB copied from RA – initialization RA RB statically defined format from a list of regions derived from an existing exe env • fork in unix • derived from the parent • shares the text region Kernel • a copy of the heap and stack Shared • copy-on-write frame A's page B's page table table a) Before write b) After write 13 14 * Processes and Threads (7): Thread memory regions Processes and Threads (8): Client and server Figure 6.5 Process Thread activations Thread 2 makes Input-output Receipt & requests to server queuing Thread 1 generates results Requests Activation stacks N threads (parameters, local variables) Client Server Heap (dynamic storage, 'text' (program code) objects, global variables) The 'worker pool' architecture system-provided resources (sockets, windows, open files) See Figure 4.6 for an example of this architecture programmed in Java. 15 * 16 * Processes and Threads (9) Processes and Threads (10): server threading architectures Figure 6.6 average interval of successive job completions server server server – one request: 2 milliseconds of processing and 8 for i/o process workers process per-connection threads process per-object threads delay I/O remote remote remote I/O objects – one thread: 2+8 = 10 milliseconds, 100 requests/second objects objects – two threads: 125 requests/second, serial i/o, why? – two threads: 200 requests/second, concurrent i/o, why? a. Thread-per-request b. Thread-per-connection c. Thread-per-object – two threads with cache (75% hit): – Implemented by the server-side ORB in CORBA 2 milliseconds (.75*0 + .25*8), 500 requests/sec (a) would be useful for UDP-based service, e.g. NTP (network time protocol) (b) is the most commonly used - matches the TCP connection model – cpu overhead of caching: 2.5 milliseconds, 400 (c) is used where the service is encapsulated as an object. E.g. could have requests/sec multiple shared whiteboards with one thread each. Each object has only one thread, avoiding the need for thread synchronization within objects. 17 18 * 3 Processes and Threads (11): Threads vs processes Processes and Threads (12): Concurrency Creating a thread is (much) cheaper than a process (~10-20 times) Issues in concurrency: Switching to a different thread in same process is (much) cheaper (5-50 times) – Race condition Threads within same process can share data and other resources more – Deadlock conveniently and efficiently (without copying or messages) – Starvation Threads within a process are not protected from each other Programming support Figure 6.7 State associated with execution environments and threads – library (POSIX pthreads) Execution environment Thread Address space tables Saved processor registers – language support (Ada95, Modula-3, Java) Communication interfaces, open files Priority and execution state (such as BLOCKED ) Semaphores, other synchronization Software interrupt handling information objects List of thread identifiers Execution environment identifier Pages of address space resident in memory; hardware cache entries 19 * 20 Processes and Threads (13) Processes and Threads (14) thread (process) execution Synchronization – create/fork – coordinate current tasks and prevent race conditions on – exit shared objects – join/wait – Critical region: only one thread/process at a time is – yield allowed – Why critical regions should be as small as possible? Programming support – Mutual exclusion – Condition Variables – Semaphores 21 22 Processes and Threads (15): Mutual Exclusion Processes and Threads (16) Mutual exclusion (mutex) One producer, one consumer, producer can produce many items (1P1CinfD) – critical region/section How about nPnCinfD ? – before entering critical region, try to lock Producer Consumer – mutex_lock(l): mutex_lock(D) mutex_lock(D) if try to lock is successful while (no data) // count <= 0 • lock and continue mutex_unlock(D) else • blocked sleep (how long? spin poll) – mutex_unlock(l): release the lock mutex_lock(D) produce one item consume one item mutex_unlock(D) mutex_unlock(D) 23 24 4 Processes and Threads (17): Condition Variables Processes and Threads (18) Condition variable cv_wait(c,