LECTURE 12:
OPERATING SYSTEM
CASE STUDIES
CASE STUDY 1: LINUX
OPERATING SYSTEM
TOPICS FOR
DISCUSSION
Linux History – Versions, Distributions
Design Principles
Components of Linux System
Process Management
Scheduling
Memory Management
File Systems
3
OBJECTIVES
To explore the history of the UNIX operating system from
which Linux is derived and the principles upon which Linux’s
design is based
To examine the Linux process model and illustrate how Linux
schedules processes and provides interprocess communication
To look at memory management in Linux
To explore how Linux implements file systems and manages
I/O devices
4
HISTORY
Linux is a modern, free operating system based on UNIX standards
First developed as a small but self-contained kernel in 1991 by Linus Torvalds, with the
major design goal of UNIX compatibility, released as open source
Its history has been one of collaboration by many users from all around the world,
corresponding almost exclusively over the Internet
It has been designed to run efficiently and reliably on common PC hardware, but also runs
on a variety of other platforms
The core Linux operating system kernel is entirely original, but it can run much existing
free UNIX software, resulting in an entire UNIX-compatible operating system free from
proprietary code
Linux system has many, varying Linux distributions including the kernel, applications, and
management tools
More popular in the server market for Web and Database Servers and in embedded
devices market than in the desktop market.
5
THE LINUX KERNEL –
VERSIONS (1)…
Version 0.01 (May 1991) had no networking, ran only on 80386-compatible Intel
processors and on PC hardware, had extremely limited device-drive support, and
supported only the Minix file system
Linux 1.0 (March 1994) included these new features:
Support for UNIX’s standard TCP/IP networking protocols
BSD-compatible socket interface for networking programming
Device-driver support for running IP over an Ethernet
Enhanced file system
Support for a range of SCSI controllers for high-performance disk access
Extra hardware support
Version 1.2 (March 1995) was the final PC-only Linux kernel
Kernels with odd version numbers are development kernels, those with even numbers are
production kernels
6
THE LINUX KERNEL –
VERSIONS (2)…
Released in June 1996, 2.0 added two major new capabilities:
Support for multiple architectures, including a fully 64-bit native Alpha port
Support for multiprocessor architectures
Other new features included:
Improved memory-management code
Improved TCP/IP performance
Support for internal kernel threads, for handling dependencies between loadable modules, and
for automatic loading of modules on demand
Standardized configuration interface
Available for Motorola 68000-series processors, Sun Sparc systems, and for PC and PowerMac
systems
2.4 and 2.6 increased SMP support, added journaling file system, preemptive kernel, 64-bit
memory support
3.0 released in 2011, 20th anniversary of Linux, improved virtualization support, new page write-
back facility, improved memory management, new Completely Fair Scheduler
7
THE LINUX KERNEL –
VERSIONS (3)
Version 3.10 of the Linux kernel, released in June 2013, contains 15,803,499
lines of code,
Version 4.1, released in June 2015, has grown to over 19.5 million lines of code
contributed
Developer by almost
Linus Torvalds 14,000
and thousands of programmers.
collaborators
Written in C and assembly
OS family Unix-like
Initial release0.01 (17 September 1991; 24
years ago)
Latest release 4.7.4 (15 September 2016)
Latest previe 4.8-rc6 (11 September 2016)
w
Available in English
Kernel type Monolithic
License GNU General Public License,
version 2 plus various optional
proprietary binary blobs
Official kernel.org
website 8
Reference: https://en.wikipedia.org/wiki/Linux_kernel
THE LINUX SYSTEM
Linux uses many tools developed as part of Berkeley’s BSD operating system,
MIT’s X Window System, and the Free Software Foundation's GNU project
The main system libraries were started by the GNU project, with improvements
provided by the Linux community
Linux networking-administration tools were derived from 4.3BSD code; recent
BSD derivatives such as Free BSD have borrowed code from Linux in return
The Linux system is maintained by a loose network of developers collaborating
over the Internet, with a small number of public ftp sites acting as de facto
standard repositories
File System Hierarchy Standard document maintained by the Linux
community to ensure compatibility across the various system components
Specifies overall layout of a standard Linux file system, determines under
which directory names configuration files, libraries, system binaries, and run-
time data files should be stored 9
LINUX DISTRIBUTIONS (1)…
Standard, precompiled sets of packages, or distributions, include the basic
Linux system, system installation and management utilities, and ready-to-
install packages of common UNIX tools
The first distributions managed these packages by simply providing a means
of unpacking all the files into the appropriate places; modern distributions
include advanced package management
Early distributions included Softlanding Linux System (SLS) (1992) and
Slackware (1993)
Red Hat and Debian are popular distributions from commercial and noncommercial
sources, respectively, others include Canonical and SuSE
The RPM Package file format permits compatibility among the various Linux
distributions
10
LINUX DISTRIBUTIONS (2)…
Reference:
Shmuel Csaba Otto Traian, CC BY-SA 3.0, 11
https://commons.wikimedia.org/w/index.php?curid=28506087
LINUX DISTRIBUTIONS (3)
roWatch Page Hit Ranking Statistics – Various Linux Distributions
Reference:
12
http://distrowatch.com/dwres.php?resource=popularity
LINUX LICENSING
The Linux kernel is distributed under the GNU General Public
License (GPL), the terms of which are set out by the Free Software
Foundation
Anyone using Linux, or creating their own derivative of Linux, may
not make the derived product proprietary; software released under
the GPL may not be redistributed as a binary-only product
Can sell distributions, but must offer the source code too
13
DESIGN PRINCIPLES
Linux is a multiuser, multitasking system with a full set of UNIX-
compatible tools
Its file system adheres to traditional UNIX semantics, and it fully
implements the standard UNIX networking model
Main design goals are speed, efficiency, and standardization
Linux is designed to be compliant with the relevant POSIX
documents;
Also supports Pthreads and a subset of POSIX real-time process
control
The Linux programming interface adheres to the SVR4 UNIX
semantics, rather than to BSD behavior
14
COMPONENTS OF A LINUX
SYSTEM
15
PROCESS MANAGEMENT
UNIX process management separates the creation of processes and
the running of a new program into two distinct operations.
The fork() system call creates a new process
A new program is run after a call to exec()
Under UNIX, a process encompasses all the information that the
operating system must maintain to track the context of a single
execution of a single program
Under Linux, process properties fall into three groups: the
process’s identity, environment, and context
16
PROCESS IDENTITY
Process ID (PID) - The unique identifier for the process; used to
specify processes to the operating system when an application makes
a system call to signal, modify, or wait for another process
Credentials - Each process must have an associated user ID and
one or more group IDs that determine the process’s rights to access
system resources and files
Personality - Not traditionally found on UNIX systems, but under
Linux each process has an associated personality identifier that can
slightly modify the semantics of certain system calls
Namespace – Specific view of file system hierarchy
17
PROCESS ENVIRONMENT
The process’s environment is inherited from its parent, and is
composed of two null-terminated vectors: argument vector and
environment vector.
Passing environment variables among processes and inheriting
variables by a process’s children are flexible means of passing
information to components of the user-mode system software.
18
PROCESS CONTEXT – PARTS
(1)…
The (constantly changing) state of a running program at any point
in time
The scheduling context is the most important part of the
process context; it is the information that the scheduler needs to
suspend and restart the process
The kernel maintains accounting information about the
resources currently being consumed by each process, and the
total resources consumed by the process in its lifetime so far
The file table is an array of pointers to kernel file structures
When making file I/O system calls, processes refer to files by
their index into this table, the file descriptor (fd) 19
PROCESS CONTEXT – PARTS
(2)
Whereas the file table lists the existing open files, the
file-system context applies to requests to open new files
The current root and default directories to be used for new file
searches are stored here
The signal-handler table defines the routine in the
process’s address space to be called when specific signals
arrive
The virtual-memory context of a process describes the
full contents of the its private address space
20
PROCESSES AND THREADS
Linux uses the same internal representation for processes and threads; a
thread is simply a new process that happens to share the same address
space as its parent
Both are called tasks by Linux
A distinction is only made when a new thread is created by the clone()
system call
fork() creates a new task with its own entirely new task context
clone() creates a new task with its own identity, but that is allowed to
share the data structures of its parent
Using clone() gives an application fine-grained control over exactly what
is shared between two threads
21
CPU SCHEDULING
The job of allocating CPU time to different tasks
within an operating system
As of 2.5, new scheduling algorithm –
preemptive, priority-based, known as O(1)
Real-time range
nice value
Had challenges with interactive performance
2.6 introduced Completely Fair Scheduler
(CFS)
22
COMPLETELY FAIR SCHEDULER (CFS)
(1)…
Eliminates traditional, common idea of time slice
Instead, all tasks allocated portion of processor’s time
CFS calculates how long a process should run as a
function of total number of tasks
N runnable tasks means each gets 1/N of processor’s
time
Then weights each task with its nice value
Smaller nice value -> higher weight (higher priority)
23
COMPLETELY FAIR SCHEDULER (CFS) (2)
Then each task run with for time proportional to task’s
weight divided by total weight of all runnable tasks
Configurable variable target latency is desired interval
during which each task should run at least once
Consider simple case of 2 runnable tasks with equal weight
and target latency of 10ms – each then runs for 5ms
If 10 runnable tasks, each runs for 1ms
Minimum granularity ensures each run has reasonable
amount of time (which actually violates fairness idea)
24
KERNEL SYNCHRONIZATION
(1)…
A request for kernel-mode execution can occur in two ways:
A running program may request an operating system service, either
explicitly via a system call, or implicitly, for example, when a page fault
occurs
A device driver may deliver a hardware interrupt that causes the CPU to
start executing a kernel-defined handler for that interrupt
Kernel synchronization requires a framework that will allow the kernel’s
critical sections to run without interruption by another critical section
25
KERNEL SYNCHRONIZATION
(2)
•Linux uses two techniques to protect critical sections:
1. Normal kernel code is non-preemptible (until 2.6)
2. The second technique applies to critical sections that occur in
an interrupt service routines
– By using the processor’s interrupt control hardware to disable
interrupts during a critical section, the kernel guarantees that it
can proceed without the risk of concurrent access of shared
data structures
• Provides spin locks, semaphores, and reader-writer versions of
both
• Behavior modified if on single processor or multi processors:
26
MEMORY MANAGEMENT
- PAGING
•Linux can run both on 32 bit and 64 bit machines.
• Therefore having just two level paging is not enough.
• Linux adapted a three level paging that can be used both in 32bit and
64bit machines.
•A linear address in Linux is broken into 4 parts:
• P1: global directory
• P2: middle directory
• P3: page table
• P4: offset
•Number of bits in each part depends on the architecture
LINEAR ADDRESS IN LINUX
Broken into four parts:
•In a 64-bit machine (very large address space), we use all 4
parts
•In a 32-bit Intel machine, that uses two-level paging, we
ignore the middle directory (its size is 0) and use 3 parts.
28
THREE-LEVEL PAGING IN
LINUX
SLAB ALLOCATOR IN LINUX
30
VIRTUAL MEMORY (1)…
The VM system maintains the address space visible to each process:
It creates pages of virtual memory on demand and manages the
loading of those pages from disk or their swapping back out to disk as
required.
The VM manager maintains two separate views of a process’s address
space:
A logical view describing instructions concerning the layout of the address
space
The address space consists of a set of non-overlapping regions, each representing a
continuous, page-aligned subset of the address space
A physical view of each address space which is stored in the hardware page
tables for the process
31
VIRTUAL MEMORY (2)
Virtual memory regions are characterized by:
The backing store, which describes from where the pages for a region come;
regions are usually backed by a file or by nothing (demand-zero memory)
The region’s reaction to writes (page sharing or copy-on-write
The kernel creates a new virtual address space
1. When a process runs a new program with the exec() system call
2. Upon creation of a new process by the fork() system call
32
FILE SYSTEMS
•To the user, Linux’s file system appears as a hierarchical directory tree obeying
UNIX semantics
•Internally, the kernel hides implementation details and manages the multiple
different file systems via an abstraction layer, that is, the virtual file system
(VFS)
•The Linux VFS is designed around object-oriented principles and is composed of
four components:
• A set of definitions that define what a file object is allowed to look like
• The inode object structure represent an individual file
• The file object represents an open file
• The superblock object represents an entire file system
• A dentry object represents an individual directory entry
33
THE LINUX EXT3 FILE SYSTEM
•ext3 is standard on disk file system for Linux
• Uses a mechanism similar to that of BSD Fast File System
(FFS) for locating data blocks belonging to a specific file
• Supersedes older extfs, ext2 file systems
• Work underway on ext4 adding features like extents
34
CASE STUDY 2:
WINDOWS OPERATING
SYSTEM
TOPICS FOR DISCUSSION
History
Design Principles
System Components
Processes and Threads
CPU scheduling
Process Synchronization
Virtual Memory Management
File system
36
OBJECTIVES
To explore the principles upon which Windows is designed and the
specific components involved in the system
37
EXAMPLE: WINDOWS 7
32-bit preemptive multitasking operating system for Intel microprocessors
Key goals for the system:
portability
security
POSIX compliance
multiprocessor support
extensibility
international support
compatibility with MS-DOS and MS-Windows applications.
Uses a micro-kernel architecture
Available in six client versions, Starter, Home Basic, Home Premium, Professional,
Enterprise and Ultimate. With the exception of Starter edition (32-bit only) all are available
in both 32-bit and 64-bit.
Available in three server versions (all 64-bit only), Standard, Enterprise and Datacenter38
HISTORY
In 1988, Microsoft decided to develop a “new technology” (NT)
portable operating system that supported both the OS/2 and POSIX
APIs
Originally, NT was supposed to use the OS/2 API as its native
environment but during development NT was changed to use the
Win32 API, reflecting the popularity of Windows 3.0.
39
DESIGN PRINCIPLES –
EXAMPLE WINDOWS 7 (1)…
Extensibility — layered architecture
Executive, which runs in protected mode, provides the basic system services
On top of the executive, several server subsystems operate in user mode
Modular structure allows additional environmental subsystems to be added
without affecting the executive
Portability — Windows 7 can be moved from one hardware architecture to
another with relatively few changes
Written in C and C++
Processor-specific portions are written in assembly language for a given
processor architecture (small amount of such code).
Platform-dependent code is isolated in a dynamic link library (DLL) called the
“hardware abstraction layer” (HAL)
40
DESIGN PRINCIPLES –
EXAMPLE WINDOWS 7 (2)
•Reliability — Windows 7 uses hardware protection for virtual memory, and
software protection mechanisms for operating system resources
•Compatibility — applications that follow the IEEE 1003.1 (POSIX) standard
can be complied to run on 7 without changing the source code
•Performance — Windows 7 subsystems can communicate with one another
via high-performance message passing
• Preemption of low priority threads enables the system to respond quickly to external
events
• Designed for symmetrical multiprocessing
•International support — supports different locales via the national language
support (NLS) API
41
ARCHITECTURE - EXAMPLE-
WINDOWS 7
Layered system of module
Protected mode — hardware abstraction layer (HAL), kernel,
executive
User mode — collection of subsystems
Environmental subsystems emulate different operating systems
Protection subsystems provide security functions
42
SYSTEM COMPONENTS —
KERNEL
Foundation for the executive and the subsystems
Never paged out of memory; execution is never preempted
Four main responsibilities:
thread scheduling
interrupt and exception handling
low-level processor synchronization
recovery after a power failure
Kernel is object-oriented, uses two sets of objects
dispatcher objects control dispatching and synchronization (events, mutants,
mutexes, semaphores, threads and timers)
control objects (asynchronous procedure calls, interrupts, power notify, power
status, process and profile objects)
43
KERNEL — PROCESS AND
THREADS
The process has a virtual memory address space, information (such as a base
priority), and an affinity for one or more processors.
Threads are the unit of execution scheduled by the kernel’s dispatcher.
Each thread has its own state, including a priority, processor affinity, and
accounting information.
A thread can be one of six states: ready, standby, running, waiting, transition,
and terminated.
44
THREADS : EXAMPLE:
WINDOWS XP (1)…
THREADS : EXAMPLE:
WINDOWS XP (2)
Implements the one-to-one mapping, kernel-level
Each thread contains
A thread id
Register set
Separate user and kernel stacks
Private data storage area
The register set, stacks, and private storage area are known as the
context of the threads
The primary data structures of a thread include:
ETHREAD (executive thread block)
KTHREAD (kernel thread block)
TEB (thread environment block)
SCHEDULING – EXAMPLE
WINDOWS XP
Windows schedules threads using a priority-based, preemptive scheduling
algorithm.
The dispatcher uses a 32-level priority scheme to determine the order of thread
execution. Higher number indicates a higher priority.
Two priority classes that a thread can be assigned
Variable class: contains threads having priorities from 1 to 15
Real-time class: contains threads with priorities from 16 to 31.
Dispatcher uses a queue for each scheduling priority and traverses the set of
queues from highest to lowest until it finds a thread that is ready to run
If no ready thread is found, the dispatcher will execute a special thread called
the idle thread.
Circumstances where the thread can leave the CPU:
Pre-empted by a higher-priority thread
Terminates
Time-quantum ends
Calls a blocking system call such as for I/O
47
PRIORITIES – EXAMPLE
WINDOWS XP
SYNCHRONIZATION –
EXAMPLE WINDOWS XP
Uses interrupt masks to protect access to global resources on
uniprocessor systems
Uses spinlocks on multiprocessor systems
Also provides dispatcher objects which may act as either mutexes
and semaphores
Dispatcher objects may also provide events
An event acts much like a condition variable
VIRTUAL MEMORY
MANAGEMENT – EXAMPLE
WINDOWS XP
Implements virtual memory using demand paging with clustering.
Method for handling page faults:
Clustering handles page faults by bringing in not only the faulting page but
also several pages following the faulting page.
When a process is first created, it is assigned a working-set minimum and
maximum.
Working-set minimum is the minimum number of pages that the process is
guaranteed to have in memory.
If sufficient memory is available, a process may be assigned as many pages
as its working-set maximum.
When the amount of free memory falls below the threshold, the virtual
memory manager uses a method known as automatic working-set trimming to
restore the value above the threshold.
FILE SYSTEM – EXAMPLE
WINDOWS 7
The fundamental structure of the Windows 7 file system (NTFS) is a volume
Created by the Windows 7 disk administrator utility
Based on a logical disk partition
May occupy a portions of a disk, an entire disk, or span across several
disks
All metadata, such as information about the volume, is stored in a regular
file
NTFS uses clusters as the underlying unit of disk allocation
A cluster is a number of disk sectors that is a power of two
Because the cluster size is smaller than for the 16-bit FAT file system, the
amount of internal fragmentation is reduced
51
References
SLIDES ARE ADAPTED FROM
ABRAHAM SILBERSCHATZ, PETER
BAER GALVIN, GREG GAGNE,
“OPERATING SYSTEM
CONCEPTS”, 9/E, JOHN WILEY &
SONS.
ANDREW S. TANENBAUM,
“MODERN OPERATING SYSTEMS”,
4 TH
EDITION, PEARSON.