02 - Operating System Structure
02 - Operating System Structure
Lecture 2
Soumyabrata DEV
https://soumyabrata.dev/
Operating Systems Structure
3
Operating System Structure
} It is important to remember:
} The concepts we study will exist in some form in
every operating system
} But they will be implemented in different ways
4
Operating System Components
} Kernel: software containing the core OS
components; it may typically include:
} Memory Manager
} Provides efficient memory allocation and
deallocation of memory
} I/O manager
} Handles input and output requests from and to
hardware devices (through device drivers)
5
Operating System Components
} Inter-process communication (IPC) manager
} Provides communication between different
processes (programs in execution)
6
Operating System Components
} An OS kernel may consist of many more
components:
} System service routines
} File System (FS) manager
} Error handling systems
} Accounting systems
} System programs
} And many more
7
Operating System Interface
} Original OS interfaces were very simple and
called Command Line Interface (CLI) or
Command Interpreter (CI)
10
OS Structure Issues:
} How are all these components organised?
11
Operating System Goals
} When we design an operating system we want
it to be:
} Efficient – (High throughput)
} Interactive
} Robust – (Fault tolerant & reliable)
} Secure
} Scalable
} Extensible
} Portable
12
Monolithic Architecture
} Traditionally, systems were built around
monolithic kernels
} every OS component is contained in the kernel
13
Example : MS DOS
} Written to provide
the most functionality
in the least space
15
Layered Structure
} To try and solve the problems with the
monolithic structure, the layered structure was
developed
16
Advantages of Layered Structure
} Designing the system as a number of modules
gives the system structure and consistency
17
each layer is a virtual ma
Layered
a Architecture
higher layer provides a h
} Each layer
communicates only Layer 3
with layers
immediately above Layer 2
and below it
} each layer is a virtual
Layer 1 ←
machine to the layer
above
Layer 0 ←
} a higher layer provides Hardware
a higher-level virtual
machine
18
First Layers-based OS
} Layering was first used in Dijkstra’s THE OS
(1968)
19
ayers-based OS
The Layers
Layering was first used in Dijkstra’s THE OS (1968)
layer 4 User Programs
layer 3 I/O Management
layer 2 Console Device (commands), IPC
layer 1 Memory Management
layer 0 CPU Scheduling (multiprogramming)
Hardware
21
Problems with layering
} Appropriate definition of layers is difficult
} A layer is implemented using only those
operations provided by lower-lever layers
} A real system structure is often more complex
than the strict hierarchy required by layering
22
Problems with Layering
} Performance issues
} Processes’ requests might pass through many
layers before completion (layer crossing)
} System throughput can be lower than in
monolithic kernels
23
Problems with Layering
} Still susceptible to malicious/errant code if all
layers can have unrestricted access to the
system
} As we will see later, this can only be avoided
through hardware
24
Microkernel Architecture
} The microkernel (μ-kernel) architecture was
designed to minimise the services offered by
the kernel
25
Introduction to Microkernel Architecture
} Microkernel architecture is a design approach
for operating systems that aims to minimize
the kernel's size and complexity by moving
most system functions out of the kernel and
into user space.
26
Key Concepts
} Microkernel: The core of the operating system is
minimal, containing only essential functions such as
inter-process communication and hardware
abstraction.
} User Space Servers: Additional functionality
traditionally found in the monolithic kernel, such as
device drivers and file systems, is implemented as
separate user space processes or servers.
} Message Passing: Communication between user space
servers and the microkernel is typically achieved
through message passing.
27
Advantages of Microkernel Architecture
} Modularity: The system is more modular and extensible,
as additional services can be added or removed without
modifying the core kernel.
} Reliability: Isolation of user space servers from the core
kernel improves system stability. If a server crashes, it
can be restarted without affecting the entire system.
} Portability: Microkernels are often more portable across
different hardware platforms because the core kernel is
minimal and hardware-specific code is in user space
servers.
} Security: Enhanced security as user space servers can be
isolated from each other, reducing the attack surface.
28
Examples of Microkernel-based Operating
Systems
} MINIX: Originally created as an educational
tool by Andrew S. Tanenbaum, MINIX is a
microkernel-based operating system.
} QNX: A real-time microkernel operating
system used in embedded systems, automotive
infotainment systems, and more.
} L4: A family of microkernels designed for high
performance and security, used in various
research and commercial systems.
29
Challenges and Considerations
} Performance Overhead: Message passing can
introduce overhead compared to direct function
calls in monolithic kernels.
} Complexity: Developing and maintaining user space
servers can be challenging, potentially offsetting
some of the benefits.
} Design Choices: Microkernel architectures require
careful consideration of which components
should reside in the microkernel and which
should be implemented as user space servers.
30
Microkernel System Structure
messages messages
microkernel
hardware
31
Conclusion
} Microkernel architecture offers a different approach to
operating system design, emphasizing modularity,
reliability, portability, and security. Understanding this
architecture is crucial for gaining insights into modern
operating system design principles.
32
Modules
} Many modern operating systems implement
loadable kernel modules
} Uses object-oriented approach
} Each core component is separate
} Each talks to the others over known interfaces
} Each is loadable as needed within the kernel
34
Hybrid Systems
} Most modern operating systems are actually
not one pure model
} Hybrid combines multiple approaches to address
performance, security, usability needs
} Linux and Solaris kernels are in kernel address space,
so they are monolithic, but also modular for
dynamic loading of functionality
} Apple Mac OS X combines a layered approach with a
kernel consisting of Mach microkernel and Berkeley
Software Distribution (BSD) Unix parts, plus I/O kit
and dynamically loadable modules
35
Mac OS X Structure
graphical user interface
Aqua
kernel environment
BSD
Mach
36
iOS
} Based on Mac OS X
} Cocoa Touch Objective-C API for
developing apps
} Media services layer for graphics, audio, Cocoa Touch
37
Android
} Open-Source OS Developed by Open
Handset Alliance (mostly Google)
38
Android
} Runtime environment includes core set of
libraries and Dalvik/ART(2015) virtual
machine
39
Android Architecture
Applications
Application Framework
surface media
Dalvik
manager framework
virtual machine
webkit libc
Linux kernel
40
Operating Systems Structure
41
Operating System and Hardware
} An OS is partly dedicated to a specific
hardware architecture
42
Protected Instructions
} In modern systems some instructions are
typically restricted to the OS (protected or
privileged instructions)
43
Protected Instructions
} Typically, users are not allowed to
} Directly access I/O (disk, printer,. . . )
} Directly manage memory
} Execute CPU halt instructions
44
Dual Mode Operation
} The implementation of protected instructions
requires some type of hardware mechanism
45
Dual Mode Operation
} The mode is indicated by a status bit (mode bit)
in a protected processor register
} OS programs & protected instructions executed in
kernel mode
} user programs executed in user mode
} Examples of protection in older and newer
systems:
} MS-DOS (based on Intel 8088): no protection modes
} Windows 2000/XP, OS/2, Linux (based on Intel x86
systems): protection modes
46
Crossing Protection Boundries
} User-mode programs cannot execute
privileged instructions, but they still need
kernel-mode services (I/O operations, memory
management, etc)
47
Crossing Protection Boundries
} A system call causes a trap, which jumps to
the trap handler in the kernel
48
Crossing Protection Boundries
} After this the hardware must
} Implement caller’s parameters verification (e.g.
memory pointers should only be allowed within
user’s section)
} Return to user-mode when trap system call
finished
49
Exceptions
} Exception (hardware-initiated interrupt):
basically the same as a trap
50
Exceptions
} Exceptions also transfer control to a handler
within the OS
} system status can be saved on exceptions (memory
dump), so that faulty processes can be later
debugged
52
Memory Protection
} A memory protection mechanism must
protect
} user programs from each other
} OS (kernel) from user programs
53
mory protection mechanism must protect
Base and
user programs Limit
from each other Registers
OS (kernel) from user programs
} Base and limit registers are loaded by the OS
lest scheme is to use base and limit registers
before starting the execution of any program
these registers are loaded by the OS before starting the
in ofuser
execution mode in user mode
any program
0
Kernel
256000
Program 1 base register for program 2
300040 300040
Program 2
420940 120900
Program 3 limit register for program 2
} base
base ≤ address≤<address < base
base + limit; + limit;
otherwise otherwise
exception raised
exception raised
54
Memory Protection
} Currently memory protection is more
complex than this
55
I/O Control
} All I/O instructions are privileged
} This is because a program could disrupt the
whole system by issuing illegal I/O instructions
56
I/O Control
} Interrupts are the basis for asynchronous I/O
} I/O devices have small processors that allow them to run
autonomously (i.e. asynchronously with respect to the
CPU)
} I/O devices send interrupt signals when done with an
operation; CPU switches to address corresponding to
interrupt
} an interrupt vector table contains the list of kernel routine
addresses that handle different events
57
CPU Protection
} Apart from protecting memory and I/O, we
must ensure that the OS always maintains
control
59
Thank you!
60