The Mach System Abraham Silberschatz, Peter Baer Galvin, Greg Gagne Presentation By: Agnimitra Roy Agenda Microkernel – What is it? What is Mach? Design Goals Mach Primitives (2 slides) Key Mach Characteristics Support for Higher Level OS Functionality Access by Applications Process Management Inter-process Communication (3 slides) Memory Management (2 slides) System Calls Summary Microkernel – What is it? Highly modular collection of OS-neutral abstractions Modularity enables scalability, extensibility, and portability not typically found in monolithic or conventional operating systems Moves many OS services into "user space" that on other operating systems are kept in the kernel User Programs User Programs UNIX System Call Interface Microkernel System Call Interface Privileged Mode Non Privileged Mode TH Trap Handler Operating System IPC TH Microkernel Hardware Microkernel Based OS TH Hardware Monolithic OS Microkernel – Advantages & Disadvantages Advantages Robustness – Services can be started independently Security – Services run as lower level user processes have restricted access to system resources Configurability – Can change service without restarting system Easier Coding – Easier to write user mode code Lower memory footprint – user mode service code can be moved out of memory Near real time performance – interrupts turned off in kernel mode – less code in kernel implies less “interrupts are interrupted” Disadvantages Most microkernels are not tiny, despite the name Need formalized message-passing mechanisms to be used New kinds of deadlocks and other error conditions are possible between system components What is Mach? Earliest example of microkernel Simple abstraction over the hardware Set of primitives to implement minimal OS services Design Vision OS will ultimately consist of minimal kernel that runs in privileged mode Supported by larger collection of OS servers (modules) that runs in non-privileged mode Microkernel is protected from all server modules, which are protected from each other Design Goals Simple kernel with few extensible abstractions Support diverse architecture – uni-processor & multiprocessor Network speed independence Support distributed operation Integrated memory management & inter-process communication Simple API Portability Full compatibility with UNIX BSD Mach Primitives Task Thread Group of ports sharing message queue Message Object reference mechanism Secure pipe for IPC between tasks Operations on objects are requested by sending messages to ports Port Set Unit of execution – runs in the context of task Single unit of code running on a processor Port Execution environment supporting basic resource allocation Set of resources that enable "threads" to run Method of communication between threads Passed between tasks on ports Memory Object Source of memory Mach Primitives (contd.) Key Mach Characteristics Blends memory and inter-process communication features Each server module contained in its own address space called Task Server modules support parallelism Supports message passing primitives Within themselves – using threads Across modules – using micro-kernel system calls Lower level than RPC Can be used in combination to build RPC – not as efficient as optimized RPC Primitives include send, recv, message queues etc Passes messages by moving memory pointers to shared memory objects where possible – avoids object copy Uses virtual memory re-mapping to transfer large messages – also known as virtual copy or copy-on-write. Memory management is based on the use of memory objects Memory objects may reside on remote systems and accessed transparently Process Management Task primitive is equivalent to traditional process without instruction pointer or register set Task by itself does nothing unless threads execute on it Threads can be in two states (1/1) Running Suspended Provides thread synchronization primitives C threads package provides low level, flexible C routines for process management CPU Scheduling enabled via 32 global run queues with locking facility Varies size of time quantum inversely with number of threads Supports two granularities for exception handling Per thread Per task Inter-process Communication Components: Ports & Messages Depends on ports & messages for communication (1/3) Delivers location independence Delivers secure communication Security ensured with rights (port name + capability) for senders and receivers Interprocess Communication (2/3) Ports, Messages, NetMsg Server Ports Protected, bounded queue in the kernel where objects reside Enables one thread to send data to another Several ports created by kernel when a task or thread is created Can be collected into port sets Messages Header (destination port + reply port + message length) + Typed data objects (variable count) Inline Data: Mach 3 – No limit; Mach 2.5 < 8KB Message passing to Receiver On same computer: virtual memory management using pointers On different computers: NetMsgServer Interprocess Communication (3/3) Ports, Messages, NetMsg Server NetMsgServer Location transparent naming & transport to extend IPC across multiple computers Maintains distributed database for port rights Uses type information stored in messages to translate data from sender’s to receiver’s format Synchronization Port can be used as synchronization variable Can be used for threads in same task – not among different tasks Memory Management Memory Object (1/2) Principle abstraction in Mach Used to manage secondary storage; represents files, pipes or other data mapped into VM for read & write Backed by user level memory managers Virtual address space for task is generally sparse Maintains cache of memory resident pages of all mapped objects Can use user level memory managers However, supports a default memory manager Memory Management (2/2) Shared Memory Mach uses shared memory to reduce complexity of system services Supports consistent shared memory for tasks running on processors that share memory Tasks # Shared memory OS constructs such as fork Parent tasks can declare which regions of memory can be inherited by children No copy-on-write inheritance External memory managers Handles shared read-write from different machines willing to share memory Programmer Interface System Call flow Traps to the kernel Upcalls into emulation library Switch to thread waiting on a port Returns to emulation library Returns from trap Calls are slower compared to traditional systems Handling single system call might involve several IPC exchanges Each IPC exchange requires trap to kernel & various scheduler overheads Summary Satisfies critical goals Supports multiprocessing & parallel execution Multiple threads of execution within one task Complete & efficient security mechanisms Can execute UNIX executables Supports many memory models + parallel & distributed computing Extensible kernel Messages are the only communication methods Integrates messages with virtual memory system Reduced size of kernel – but allows user level emulation Backup History of Mach Traces root to Accent developed at CMU Initially developed inside 4.2 BSD kernel Evolved further with 4.3 BSD release Mach 2 capabilities made kernel size larger Mach 3 moved BSB code outside of kernel Pioneered several OS concepts Unable to execute UNIX applications Difficult to port – tied to HW architecture Resulted in smaller microkernel Only basic Mach features in kernel – UNIX code evicted Allowed execution of multiple OS on top of microkernel In 1989 OSF used Mach as basis for new OS OSF/1 Mach research continues at CMU and OSF