Chapter 21: The Linux System: Silberschatz, Galvin and Gagne ©2009 Operating System Concepts - 8 Edition
Chapter 21: The Linux System: Silberschatz, Galvin and Gagne ©2009 Operating System Concepts - 8 Edition
Chapter 21: The Linux System: Silberschatz, Galvin and Gagne ©2009 Operating System Concepts - 8 Edition
21.2
Objectives
To explore the history of the UNIX operating system from which Linux is
21.3
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
much existing free UNIX software, resulting in an entire UNIXcompatible operating system free from proprietary code
Many, varying Linux Distributions including the kernel, applications, and management tools
21.4
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:
z z z z z z
Support for UNIXs 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
21.5
Linux 2.0
Support for multiple architectures, including a fully 64-bit native Alpha port Support for multiprocessor architectures 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
21.6
operating system, MITs X Window System, and the Free Software Foundation's GNU project
The min system libraries were started by the GNU project, with
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
21.7
Linux Distributions
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 SLS and Slackware
z
Red Hat and Debian are popular distributions from commercial and noncommercial sources, respectively
21.8
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
21.9
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
documents; at least two Linux distributions have achieved official POSIX certification
The Linux programming interface adheres to the SVR4 UNIX
21.10
21.11
bodies of code; the most important distinction between the kernel and all other components
The kernel is responsible for maintaining the important abstractions
Kernel code executes in kernel mode with full access to all the physical resources of the computer All kernel code and data structures are kept in the same single address space
21.12
which applications interact with the kernel, and which implement much of the operating-system functionality that does not need the full privileges of kernel code
The system utilities perform individual specialized management
tasks
21.13
Kernel Modules
Sections of kernel code that can be compiled, loaded, and
on their own terms, device drivers or file systems that could not be distributed under the GPL
Kernel modules allow a Linux system to be set up with a
21.14
Module Management
Supports loading modules into memory and letting them talk to the
Managing sections of module code in kernel memory Handling symbols that modules are allowed to reference
unloaded, modules; it also regularly queries the kernel to see whether a dynamically loaded module is still in use, and will unload it when it is no longer actively needed
21.15
Driver Registration
Allows modules to tell the rest of the kernel that a new driver has
become available
The kernel maintains dynamic tables of all known drivers, and
provides a set of routines to allow drivers to be added to or removed from these tables at any time
Registration tables include the following items:
z z z z
21.16
Conflict Resolution
A mechanism that allows different device drivers to reserve
hardware resources and to protect those resources from accidental use by another driver
The conflict resolution module aims to:
z
Prevent modules from clashing over access to hardware resources Prevent autoprobes from interfering with existing device drivers Resolve conflicts with multiple drivers trying to access the same hardware
z z
21.17
Process Management
UNIX process management separates the creation of processes
The fork system call creates a new process A new program is run after a call to execve
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
21.18
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 processs 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
z
Used primarily by emulation libraries to request that system calls be compatible with certain specific flavors of UNIX
21.19
Process Environment
The processs environment is inherited from its parent, and is
The argument vector lists the command-line arguments used to invoke the running program; conventionally starts with the name of the program itself The environment vector is a list of NAME=VALUE pairs that associates named environment variables with arbitrary textual values
variables by a processs children are flexible means of passing information to components of the user-mode system software
The environment-variable mechanism provides a customization of the
operating system that can be set on a per-process basis, rather than being configured for the system as a whole
21.20
Process Context
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
z
When making file I/O system calls, processes refer to files by their index into this table
21.21
The current root and default directories to be used for new file searches are stored here
21.22
thread is simply a new process that happens to share the same address space as its parent
A distinction is only made when a new thread is created by the clone
system call
z z
fork creates a new process with its own entirely new process context clone creates a new process with its own identity, but that is allowed to share the data structures of its parent
21.23
Scheduling
The job of allocating CPU time to different tasks within an operating system While scheduling is normally thought of as the running and interrupting of
processes, in Linux, scheduling also includes the running of the various kernel tasks
Running kernel tasks encompasses both tasks that are requested by a
running process and tasks that execute internally on behalf of a device driver
As of 2.5, new scheduling algorithm preemptive, priority-based
z z
21.24
21.25
21.26
Kernel Synchronization
A request for kernel-mode execution can occur in two ways:
z
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
21.27
1. Normal kernel code is nonpreemptible (until 2.4) when a time interrupt is received while a process is executing a kernel system service routine, the kernels need_resched flag is set so that the scheduler will run once the system call has completed and control is about to be returned to user mode 2. The second technique applies to critical sections that occur in an interrupt service routines By using the processors 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
21.28
architecture that allows long critical sections to run without having interrupts disabled for the critical sections entire duration
Interrupt service routines are separated into a top half and a bottom half.
z
The top half is a normal interrupt service routine, and runs with recursive interrupts disabled The bottom half is run, with all interrupts enabled, by a miniature scheduler that ensures that bottom halves never interrupt themselves This architecture is completed by a mechanism for disabling selected bottom halves while executing normal, foreground kernel code
21.29
level, but will never be interrupted by code running at the same or a lower level
User processes can always be preempted by another process
21.30
Process Scheduling
Linux uses two process-scheduling algorithms:
z
A time-sharing algorithm for fair preemptive scheduling between multiple processes A real-time algorithm for tasks where absolute priorities are more important than fairness
A processs scheduling class defines which algorithm to apply For time-sharing processes, Linux uses a prioritized, credit based
algorithm
z
21.31
both cases, each process has a priority in addition to its scheduling class
z
The scheduler runs the process with the highest priority; for equalpriority processes, it runs the process waiting the longest FIFO processes continue to run until they either exit or block A round-robin process will be preempted after a while and moved to the end of the scheduling queue, so that round-robing processes of equal priority automatically time-share between themselves
z z
21.32
Symmetric Multiprocessing
Linux 2.0 was the first Linux kernel to support SMP hardware; separate
SMP imposes the restriction, via a single kernel spinlock, that only one processor at a time may execute kernel-mode code
21.33
Memory Management
Linuxs physical memory-management system deals with allocating and
21.34
21.35
21.36
physical pages
z z z
Each allocatable memory region is paired with an adjacent partner Whenever two allocated partner regions are both freed up they are combined to form a larger region If a small memory request cannot be satisfied by allocating an existing small free region, then a larger free region will be subdivided into two partners to satisfy the request
reserve a contiguous area of memory during system boot time) or dynamically (via the page allocator)
Also uses slab allocator for kernel memory
21.37
21.07
21.38
Virtual Memory
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 processs address
space:
z
A logical view describing instructions concerning the layout of the address space
The
address space consists of a set of nonoverlapping 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
21.39
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 regions reaction to writes (page sharing or copy-on-write)
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
21.40
virtual-address space; the program-loading routines populate the address space with virtual-memory regions
Creating a new process with fork involves creating a complete copy of the
The kernel copies the parent processs VMA descriptors, then creates a new set of page tables for the child The parents page tables are copied directly into the childs, with the reference count of each page covered being incremented After the fork, the parent and child share the same physical pages of memory in their address spaces
21.41
The pageout-policy algorithm decides which pages to write out to disk, and when The paging mechanism actually carries out the transfer, and pages data back into physical memory as needed
21.42
virtual address space of every process for its own internal use
This kernel virtual-memory area contains two regions:
z
A static area that contains page table references to every available physical page of memory in the system, so that there is a simple translation from physical to virtual addresses when running kernel code The reminder of the reserved section is not reserved for any specific purpose; its page-table entries can be modified to point to any other areas of memory
21.43
function the opportunity to try loading the given file when an exec system call is made
The registration of multiple loader routines allows Linux to support both the
Only when a program tries to access a given page will a page fault result in that page being loaded into physical memory
aligned sections
z
The ELF loader works by reading the header and mapping the sections of the file into separate regions of virtual memory
21.44
21.45
must contain copies of exactly the same common system library functions
Dynamic linking is more efficient in terms of both physical memory and disk-
space usage because it loads the system libraries into memory only once
21.46
File Systems
To the user, Linuxs file system appears as a hierarchical directory tree
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
A set of definitions that define what a file object is allowed to look like
The
files
the z
21.47
allocation policies
z
In ffs, the disk is allocated to files in blocks of 8Kb, with blocks being subdivided into fragments of 1Kb to store small files or partially filled blocks at the end of a file Ext2fs does not use fragments; it performs its allocations in smaller units
The
default block size on ext2fs is 1Kb, although 2Kb and 4Kb blocks are also supported
Ext2fs uses allocation policies designed to place logically adjacent blocks of a file into physically adjacent blocks on disk, so that it can submit an I/O request for several disk blocks as a single operation
21.48
21.49
must then define a unique and persistent inode number for each directory and files it contains
z
It uses this inode number to identify just what operation is required when a user tries to read from a particular file inode or perform a lookup in a particular directory inode When data is read from one of these files, proc collects the appropriate information, formats it into text form and places it into the requesting processs read buffer
21.50
caches:
z
Data is cached in the page cache, which is unified with the virtual memory system Metadata is cached in the buffer cache, a separate cache indexed by the physical disk block block devices allow random access to completely independent, fixed size blocks of data character devices include most other devices; they dont need to support the functionality of regular files network devices are interfaced via the kernels networking subsystem
21.51
21.52
Block Devices
Provide the main interface to all disk devices in a system The block buffer cache serves two main purposes:
z z
it acts as a pool of buffers for active I/O it serves as a cache for completed I/O
The request manager manages the reading and writing of buffer contents to
21.53
Character Devices
A device driver which does not offer random access to fixed blocks of data A character device driver must register a set of functions which implement
drivers which implement terminal devices, for which the kernel maintains a standard interface
21.54
Interprocess Communication
Like UNIX, Linux informs processes that an event has occurred via signals There is a limited number of signals, and they cannot carry information:
are running in kernel mode, rather, communication within the kernel is accomplished via scheduling states and wait.queue structures
21.55
channel to its parent, data written to one end of the pipe can be read a the other
Shared memory offers an extremely fast way of communicating; any data
written by one process to a shared memory region can be read immediately by any other process that has mapped that region into its address space
To obtain synchronization, however, shared memory must be used in
21.56
regions in the same way as a file can act as backing store for a memorymapped memory region
Shared-memory mappings direct page faults to map in pages from a
21.57
Network Structure
Networking is a key area of functionality for Linux.
z
It supports the standard Internet protocols for UNIX to UNIX communications It also implements protocols native to nonUNIX operating systems, in particular, protocols used on PC networks, such as Appletalk and IPX
software:
z z z
21.58
It implements routing between different hosts anywhere on the network On top of the routing protocol are built the UDP, TCP and ICMP protocols
21.59
Security
The pluggable authentication modules (PAM) system is available under
Linux
PAM is based on a shared library that can be used by any system
specifies which access modesread, write, or executeare to be granted to processes with owner, group, or world access
21.60
Security (Cont)
Linux augments the standard UNIX setuid mechanism in two ways:
z
It implements the POSIX specifications saved user-id mechanism, which allows a process to repeatedly drop and reacquire its effective uid It has added a process characteristic that grants just a subset of the rights of the effective uid
access to a single file to some server process without granting it any other privileges
21.61
End of Chapter 21