source

01 Fundamentals

Operating System Fundamentals

What is an Operating System?

An operating system is a layer of systems software that:

Computing System Components

The computing system consists of:

  1. Central Processing Unit (CPU)
  2. Physical Memory
  3. Network interfaces (Ethernet/WiFi Card)
  4. GPU
  5. Storage Device (Disk, Flash drives)

In addition, a computing system can have higher level applications (programs).

Functions of an Operating System

  1. Hide hardware complexity: Provides a higher level abstraction
  2. Manage underlying hardware resources: Allocates memory for applications, schedules them for execution on the CPU, controls access to various network devices
  3. Provides isolation and protection: When applications are running concurrently, the OS ensures they can do what they need to without hurting one another

Examples of Operating Systems

Desktop operating systems:

Embedded operating systems:


OS Elements

An operating system provides a number of high level abstractions, as well as mechanisms to operate on these abstractions.

Abstractions

Corresponding Mechanisms

Operating systems may also integrate specific policies that determine exactly how the mechanisms will be used to manage the underlying hardware.

Example: A policy could determine the maximum number of sockets that a process has access to

Memory Management Example

The main abstraction is memory page, which corresponds to some addressable region of memory of some fixed size.

The operating system integrates mechanisms to operate on the page:

The page may be moved to different spaces of memory later using a policy (e.g., LRU).


OS Design Principles

  1. Separation of mechanism and policy: Incorporate flexible mechanisms that can support a number of policies
  2. Optimize for the common case:
    • Where will the OS be used?
    • What will the user want to execute on that machine?
    • What are the workload requirements?

OS Protection Boundary

Computer systems distinguish between at least two modes of execution:

The OS must have direct access to hardware, so it must operate in kernel mode.

Hardware access can only be utilized in kernel mode from the OS directly.

User/Kernel Transitions

Applications usually operate in user-mode. When privileged instructions are encountered during a non-privileged execution, the application will be trapped. This means the application’s execution will be interrupted, and control will be handed back to the OS.

The OS can:

  1. Decide whether to grant the access or potentially terminate the process
  2. Expose an interface of system calls, which the application can invoke to allow privileged access of hardware resources
  3. Support signals, which is a way for the OS to send notifications to the application

System Call Flow

Running a Process

Making a System Call

  1. The process asks the OS for help via a system call
    • This is basically: “Hey OS, can you do this privileged thing for me?”
  2. Control switches from user mode → kernel mode
  3. The OS executes the requested operation (maybe accessing hardware)
  4. Once finished, the OS passes control (and results/data) back to the process (kernel mode → user mode)

Cost of Context Switching

Passing Arguments to System Calls

When making a system call, the process may need to pass arguments (e.g., file name, buffer, size).

This can be done in two ways:

  1. Directly: arguments copied into registers/stack and passed into the kernel
  2. Indirectly: pass a pointer to where the data is stored in memory, and the OS reads from there

Synchronous vs. Asynchronous Mode

Synchronous mode:

Asynchronous mode:


Crossing the OS Boundary

User/Kernel transitions are common and useful throughout the course of application execution.

The hardware supports user/kernel transitions:

Cost of transitions:


OS Services

An operating system provides applications with access to the underlying hardware. The OS exposes certain services:

Services Directly Linked to Hardware

Higher Level Services


OS Architectures

Monolithic OS

Everything is included in one large kernel.

Pros:

Cons:

Modular OS

A type of operating system that has a basic set of services and APIs. Anything not included can be added as a module. It can dynamically install new modules in the operating system.

Pros:

Cons:

Microkernel

Only requires the most basic operating system components. Everything else will run outside of the operating system at user-level.

This setup requires lots of interprocess communication, as the traditional operating system components run within application processes.

The microkernel often supports IPC as a core abstraction

Pros:

Cons:


Linux and Mac OS Architecture

Linux

Kernel consists of several logical components:

Mac OS X