Operating System Organization Andy Wang COP 5611 Advanced

  • Slides: 60
Download presentation
Operating System Organization Andy Wang COP 5611 Advanced Operating Systems

Operating System Organization Andy Wang COP 5611 Advanced Operating Systems

Outline l Organizing operating systems l Some microkernel examples l Object-oriented organizations ¡Spring l

Outline l Organizing operating systems l Some microkernel examples l Object-oriented organizations ¡Spring l Organization for multiprocessors

Operating System Organization l What is the best way to design an OS? l

Operating System Organization l What is the best way to design an OS? l Put another way, what are the important software characteristics of an OS? l Decide on those, then design to match them

Important OS Software Characteristics l Correctness and simplicity l Power and completeness l Performance

Important OS Software Characteristics l Correctness and simplicity l Power and completeness l Performance l Extensibility and portability l Suitability for distributed and parallel systems l Compatibility with existing systems l Security and fault tolerance

Common OS Organizations l Monolithic l Virtual machine l Layered designs l Kernel designs

Common OS Organizations l Monolithic l Virtual machine l Layered designs l Kernel designs l Microkernels l Object-Oriented Note that individual OS components can be organized these ways

Monolithic OS Design l Build OS as single combined module ¡Hopefully using data abstraction,

Monolithic OS Design l Build OS as single combined module ¡Hopefully using data abstraction, compartmentalized function, etc. l OS lives in its own, single address space l Examples ¡DOS ¡early Unix systems ¡most VFS file systems

Pros/Cons of Monolithic OS Organization + Highly adaptable (at first. . . ) +

Pros/Cons of Monolithic OS Organization + Highly adaptable (at first. . . ) + Little planning required + Potentially good performance – Hard to extend and change – Eventually becomes extremely complex – Eventually performance becomes poor – Highly prone to bugs

Virtual Machine Organizations l A base OSprovides services in a very generic way l

Virtual Machine Organizations l A base OSprovides services in a very generic way l One or more other OSes live on top of the base system ¡Using the services it provides ¡To offer different views of system to users l Examples - IBM’s VM/370, the Java interpreter

Pros/Cons of VM Organizations + Allows multiple OS personalities on a single machine +

Pros/Cons of VM Organizations + Allows multiple OS personalities on a single machine + Good OS development environment + Can provide good portability of applications – Significant performance problems – Especially if more than 2 layers – Lacking in flexibility

Layered OS Design l Design tiny innermost layer of software l Next layer out

Layered OS Design l Design tiny innermost layer of software l Next layer out provides more functionality ¡Using services provided by inner layer l Continue adding layers until all functionality required has been provided l Examples ¡Multics ¡Fluke ¡layered file systems and comm. protocols

Pros/Cons of Layered Organization + More structured and extensible + Easy model – Layer

Pros/Cons of Layered Organization + More structured and extensible + Easy model – Layer crossing can be expensive – In some cases, multiple layers unnecessary – Duplicate caching/consistency issues

Kernel OS Designs l Similar to layers, but only two OS layers ¡Kernel OS

Kernel OS Designs l Similar to layers, but only two OS layers ¡Kernel OS services ¡Non-kernel OS services l Move certain functionality outside kernel ¡file systems, libraries l Unlike VMs, kernel doesn’t stand alone l Examples - Most modern Unix systems

Pros/Cons of Kernel OS Organization + Advantages of layering, without disadvantage of many layers

Pros/Cons of Kernel OS Organization + Advantages of layering, without disadvantage of many layers + Easier to demonstrate correctness – Not as general as layering – Offers no organizing principle for other parts of OS, user services – Kernels tend to grow to monoliths

Microkernel OS Design l Like kernels, only less so l Try to include only

Microkernel OS Design l Like kernels, only less so l Try to include only small set of required services in the microkernel l Moves even more out of innermost OS part ¡Like parts of VM, IPC, paging, etc. l Examples - Mach, Amoeba, Plan 9, Windows NT, Chorus

Pros/Cons of Microkernel Organization + Those of kernels, plus: + Minimizes code for most

Pros/Cons of Microkernel Organization + Those of kernels, plus: + Minimizes code for most important OS services + Offers model for entire system – Microkernels tend to grow into kernels – Requires very careful initial design choices – Serious danger of bad performance

Object-Oriented OS Design l Design internals of OS as set of privileged objects, using

Object-Oriented OS Design l Design internals of OS as set of privileged objects, using OO methods l Sometimes extended into application space l Tends to lead to client/server style of computing l Examples ¡Mach (internally) ¡Spring (totally)

Pros/Cons of OO OS Organization + Offers organizational model for entire system + Easily

Pros/Cons of OO OS Organization + Offers organizational model for entire system + Easily divides system into pieces + Good hooks for security – Can be a limiting model – Must watch for performance problems

Some Important Microkernel Designs Micro-ness is in the eye of the beholder l Mach

Some Important Microkernel Designs Micro-ness is in the eye of the beholder l Mach l Amoeba l Plan 9 l Windows NT

Mach l Mach didn’t start life as a microkernel ¡Became one in Mach 3.

Mach l Mach didn’t start life as a microkernel ¡Became one in Mach 3. 0 l Object-oriented internally ¡Doesn’t force OO at higher levels l Microkernel focus is on communications facilities l Much concern with parallel/distributed systems

Mach Model User processes Software emulation 4. 3 BSD Sys. V HP/UX other emul.

Mach Model User processes Software emulation 4. 3 BSD Sys. V HP/UX other emul. layer Microkernel User space Kernel space

What’s In the Mach Microkernel? l Tasks & Threads l Ports and Port Sets

What’s In the Mach Microkernel? l Tasks & Threads l Ports and Port Sets l Messages l Memory Objects l Device Support l Multiprocessor/Distributed Support

Mach Tasks l An execution environment providing basic unit of resource allocation l Contains

Mach Tasks l An execution environment providing basic unit of resource allocation l Contains ¡Virtual address space ¡Port set ¡One or more threads

Kernel User space Mach Task Model Address space Process Thread Process port Bootstrap port

Kernel User space Mach Task Model Address space Process Thread Process port Bootstrap port Exception Registered ports

Mach Threads l Basic unit of Mach execution l Run in context of one

Mach Threads l Basic unit of Mach execution l Run in context of one task l All threads in one task share its resources l Unix process similar to Mach task with single thread

Task and Thread Scheduling l Very flexible l Controllable by kernel or user-level programs

Task and Thread Scheduling l Very flexible l Controllable by kernel or user-level programs l Threads of single task can run in parallel ¡On single processor and multiple processors ¡Local and global schedulers for multicore machines l User-level scheduling can extend to multiprocessor scheduling

Mach Ports l Basic Mach object reference mechanism ¡Kernel-protected communication channel l Tasks communicate

Mach Ports l Basic Mach object reference mechanism ¡Kernel-protected communication channel l Tasks communicate by sending messages to ports l Threads in receiving tasks pull messages off a queue l Ports are location independent l Port queues protected by kernel; bounded

Port Rights l Mechanism by which tasks control who may talk to their ports

Port Rights l Mechanism by which tasks control who may talk to their ports l Kernel prevents messages being set to a port unless the sender has its port rights l Port rights also control which single task receives on a port

Port Sets l A group of ports sharing a common message queue l A

Port Sets l A group of ports sharing a common message queue l A thread can receive messages from a port set ¡Thus servicing multiple ports l Messages are tagged with the actual port l A port can be a member of at most one port set

Mach Messages l Typed collection of data objects ¡Unlimited size l Sent to particular

Mach Messages l Typed collection of data objects ¡Unlimited size l Sent to particular port l May contain actual data or pointer to data l Port rights may be passed in a message l Kernel inspects messages for particular data types (like port rights)

Mach Memory Objects l A source of memory accessible by tasks l May be

Mach Memory Objects l A source of memory accessible by tasks l May be managed by user-mode external memory manager ¡a file managed by a file server l Accessed by messages through a port l Kernel manages physical memory as cache of contents of memory objects

Mach Device Support l Devices represented by ports l Messages control the device and

Mach Device Support l Devices represented by ports l Messages control the device and its data transfer l Actual device driver outside the kernel in an external object

Mach Multiprocessor and Distributed System Support l Messages and ports can extend across processor/machine

Mach Multiprocessor and Distributed System Support l Messages and ports can extend across processor/machine boundaries ¡Location transparent entities l Kernel manages distributed hardware l Per-processor data structures, but also structures shared across the processors l Intermachine messages handled by a server that knows about network details

Mach’s Net. Msg. Server l User-level capability-based networking daemon l Handles naming and transport

Mach’s Net. Msg. Server l User-level capability-based networking daemon l Handles naming and transport for messages l Provides world-wide name service for ports l Messages sent to off-node ports go through this server

Net. Msg. Server in Action User space User process Net. Msg. Server Kernel space

Net. Msg. Server in Action User space User process Net. Msg. Server Kernel space Sender Receiver

Mach and User Interfaces l Mach was built for the UNIX community l UNIX

Mach and User Interfaces l Mach was built for the UNIX community l UNIX programs don’t know about ports, messages, threads, and tasks l How do UNIX programs run under Mach? l Mach typically runs a user-level server that offers UNIX emulation l Either provides UNIX system call semantics internally or translates it to Mach primitives

Amoeba l Amoeba presents transparent distributed computing environment (a la timesharing) l Major components

Amoeba l Amoeba presents transparent distributed computing environment (a la timesharing) l Major components ¡processor pools ¡server machines ¡X-terminals ¡gateway servers for off-LAN communications l Microkernel runs everywhere

Amoeba Diagram Workstations Server pool LAN WAN Gateway Specialized servers

Amoeba Diagram Workstations Server pool LAN WAN Gateway Specialized servers

Amoeba’s Basic Primitives l Processes l Threads l Low level memory management l RPC

Amoeba’s Basic Primitives l Processes l Threads l Low level memory management l RPC l I/O

Kernel User space Amoeba Software Model Address space Process Thread Process mgmt. Memory mgmt.

Kernel User space Amoeba Software Model Address space Process Thread Process mgmt. Memory mgmt. Comm’s I/O

Amoeba Processes l Similar to Mach processes l Process has multiple threads ¡But each

Amoeba Processes l Similar to Mach processes l Process has multiple threads ¡But each thread has a dedicated portion of a shared address space l Thread scheduling by microkernel

Amoeba Memory Management l Amoeba microkernel supports concept of segments ¡To avoid the heavy

Amoeba Memory Management l Amoeba microkernel supports concept of segments ¡To avoid the heavy cost of fork across machine boundaries l A segment is a set of memory blocks l Segments can be mapped in/out of address spaces

Remote Procedure Call l Fundamental Amoeba IPC mechanism l Amoeba RPC is thread-to-thread l

Remote Procedure Call l Fundamental Amoeba IPC mechanism l Amoeba RPC is thread-to-thread l Microkernel handles on/off machine invocation of RPC

Plan 9 l Everything in Plan 9 is a file system (almost) ¡Processes ¡Files

Plan 9 l Everything in Plan 9 is a file system (almost) ¡Processes ¡Files ¡IPC ¡Devices l Only a few operations are required for files l Text-based interface

Plan 9 Basic Primitives l Terminals l CPU servers l File systems l Channels

Plan 9 Basic Primitives l Terminals l CPU servers l File systems l Channels

File Systems in Plan 9 l File systems consist of a hierarchical tree l

File Systems in Plan 9 l File systems consist of a hierarchical tree l Can be persistent or temporary l Can represent simple or complex entities l Can be implemented ¡In the kernel as a driver ¡As a user level process ¡By remote servers

Sample Plan 9 File Systems l Device file systems - Directory containing data and

Sample Plan 9 File Systems l Device file systems - Directory containing data and ctl file l Process file systems - Directory containing files for memory, text, control, etc. l Network interface file systems

Plan 9 Channels and Mounting l A channel is a file descriptor ¡Since a

Plan 9 Channels and Mounting l A channel is a file descriptor ¡Since a file can be anything, a channel is a general pointer to anything l Plan 9 provides 9 primitives on channels l Mounting is used to bring resources into a user’s name space l Users start with minimal name space, build it up as they go along

Typical User Operation in Plan 9 l User logs in to a terminal ¡Provides

Typical User Operation in Plan 9 l User logs in to a terminal ¡Provides bitmap display and input l Minimal name space is set up on login l Mounts used to build space l Pooled CPU servers used for compute tasks l Substantial caching used to make required files local

Windows NT l More layered than some microkernel designs l NT Microkernel provides base

Windows NT l More layered than some microkernel designs l NT Microkernel provides base services l Executive builds on base services via modules to provide user-level services l User-level services used by ¡privileged subsystems (parts of OS) ¡true user programs

Windows NT Diagram User Processes Protected Subsystems Win 32 Executive Microkernel Hardware POSIX User

Windows NT Diagram User Processes Protected Subsystems Win 32 Executive Microkernel Hardware POSIX User Mode Kernel Mode

NT Microkernel l Thread scheduling l Process switching l Exception and interrupt handling l

NT Microkernel l Thread scheduling l Process switching l Exception and interrupt handling l Multiprocessor synchronization l Only NT part not preemptible or pageable ¡All other NT components runs in threads

NT Executive l Higher level services than microkernel l Runs in kernel mode ¡but

NT Executive l Higher level services than microkernel l Runs in kernel mode ¡but separate from the microkernel itself ¡ease of change and expansion l Built of independent modules ¡all preemptible and pageable

NT Executive Modules l Object manager l Security reference monitor l Process manager l

NT Executive Modules l Object manager l Security reference monitor l Process manager l Local procedure call facility (a la RPC) l Virtual memory manager l I/O manager

Typical Activity in NT Win 32 Protected Subsystem Client Process Executive Kernel Hardware

Typical Activity in NT Win 32 Protected Subsystem Client Process Executive Kernel Hardware

Windows NT Threads l Executable entity running in an address space l Scheduled by

Windows NT Threads l Executable entity running in an address space l Scheduled by kernel l Handled by kernel’s dispatcher l Kernel works with stripped-down view of thread - kernel thread object l Multiple process threads can execute on distinct processors--even Executive ones

Microkernel Process Object l A proxy for the real process l Microkernel’s interface to

Microkernel Process Object l A proxy for the real process l Microkernel’s interface to the real process l Contains pointers to the various resources owned by the process ¡e. g. , threads and address spaces l Alterable only by microkernel calls

Microkernel Thread Objects l Proxies for the real thread ¡One per thread l Contains

Microkernel Thread Objects l Proxies for the real thread ¡One per thread l Contains minimal information about thread ¡Priorities, dispatching state l Used by the microkernel for dispatching

Microkernel Process and Thread Object Diagram m. Kernel Process m. Kernel Thread

Microkernel Process and Thread Object Diagram m. Kernel Process m. Kernel Thread

Other Microkernel Process Information Process Object m. Kernel Process Virtual Address Space Descriptors m.

Other Microkernel Process Information Process Object m. Kernel Process Virtual Address Space Descriptors m. Kernel Thread Object Table Thread Objects

More On Microkernels l Microkernels were the researchitecture of the 80 s l But

More On Microkernels l Microkernels were the researchitecture of the 80 s l But few commercial systems really use microkernels l To some extent, “microkernel” is now a dirty word in OS design l Why?