history n linux is a modern, free operating system based on unix standards. n first developed as a...

88
History History Linux is a modern, free operating system Linux is a modern, free operating system based on UNIX standards. based on UNIX standards. First developed as a small, but self- First developed as a small, but self- contained, kernel in 1991 by Linus contained, kernel in 1991 by Linus Torvalds, with the major design goal of Torvalds, with the major design goal of UNIX compatibility. UNIX compatibility. Its history has been one of collaboration Its history has been one of collaboration by many users from all around the world, by many users from all around the world, corresponding almost exclusively over the corresponding almost exclusively over the Internet. Internet.

Post on 22-Dec-2015

217 views

Category:

Documents


2 download

TRANSCRIPT

HistoryHistory Linux is a modern, free operating system Linux is a modern, free operating system

based on UNIX standards.based on UNIX standards. First developed as a small, but self-contained, First developed as a small, but self-contained,

kernel in 1991 by Linus Torvalds, with the kernel in 1991 by Linus Torvalds, with the major design goal of UNIX compatibility.major design goal of UNIX compatibility.

Its history has been one of collaboration by Its history has been one of collaboration by many users from all around the world, many users from all around the world, corresponding almost exclusively over the corresponding almost exclusively over the Internet.Internet.

History History (cont)(cont)

It has been designed to run efficiently It has been designed to run efficiently and reliably on common PC hardware, and reliably on common PC hardware, but also runs on a variety of other but also runs on a variety of other platforms.platforms.

The core Linux operating system kernel The core Linux operating system kernel is entirely original, but it can run much is entirely original, but it can run much existing free UNIX software, resulting existing free UNIX software, resulting in an entire UNIX compatible operating in an entire UNIX compatible operating system free from proprietary code.system free from proprietary code.

The Linux KernelThe Linux Kernel

Version 0.01 (May 1991) had no Version 0.01 (May 1991) had no networking, ran only on 80386 networking, ran only on 80386 compatible Intel processors and on PC compatible Intel processors and on PC hardware, had extremely limited hardware, had extremely limited device drive support, and supported device drive support, and supported only the Minix file system.only the Minix file system.

Kernel Kernel (cont)(cont)

Linux 1.0 (March 1994) included these new Linux 1.0 (March 1994) included these new features:features:– Support for UNIX’s standard TCP/IP networking Support for UNIX’s standard TCP/IP networking

protocols.protocols.– BSD compatible socket interface for networking BSD compatible socket interface for networking

programming.programming.– Device driver support for running IP over an Device driver support for running IP over an

Ethernet.Ethernet.– Enhanced file system.Enhanced file system.– Support for a range of SCSI controllers for Support for a range of SCSI controllers for

high-performance disk access.high-performance disk access.– Extra hardware support.Extra hardware support.

Kernel Kernel (cont)(cont)

Version 1.2 (March 1995) was the Version 1.2 (March 1995) was the final PC-only Linux kernel.final PC-only Linux kernel.

Linux 2.0Linux 2.0 Released in June 1996, 2.0 added two major new Released in June 1996, 2.0 added two major new

capabilities:capabilities:– Support for multiple architectures, including a fully 64-Support for multiple architectures, including a fully 64-

bit native Alpha port.bit native Alpha port.– Support for multiprocessor architectures.Support for multiprocessor architectures.

Other new features included:Other new features included:– Improved memory-management code.Improved memory-management code.– Improved TCP/IP performance.Improved TCP/IP performance.– Support for internal kernel threads, for handling Support for internal kernel threads, for handling

dependencies between loadable modules, and for dependencies between loadable modules, and for automatic loading of modules on demand.automatic loading of modules on demand.

– Standardized configuration interface.Standardized configuration interface.

Linux 2.0 Linux 2.0 (cont)(cont)

Available for Motorola 68000-series Available for Motorola 68000-series processors, Sun Sparc systems, PC, processors, Sun Sparc systems, PC, and PowerMac systems.and PowerMac systems.

The Linux SystemThe Linux System

Linux uses many tools developed as Linux uses many tools developed as part of Berkeley’s BSD operating part of Berkeley’s BSD operating system, MIT’s X Window System, and system, MIT’s X Window System, and the Free Software Foundation's GNU the Free Software Foundation's GNU project.project.

The main system libraries were The main system libraries were started by the GNU project, with started by the GNU project, with improvements provided by the Linux improvements provided by the Linux community.community.

The Linux System The Linux System (cont)(cont)

Linux networking administration tools Linux networking administration tools were derived from 4.3BSD code; recent were derived from 4.3BSD code; recent BSD derivatives such as Free BSD have BSD derivatives such as Free BSD have borrowed code from Linux in return.borrowed code from Linux in return.

The Linux system is maintained by a The Linux system is maintained by a loose network of developers loose network of developers collaborating over the Internet, with a collaborating over the Internet, with a small number of public ftp sites acting small number of public ftp sites acting as de facto standard repositories.as de facto standard repositories.

Linux DistributionsLinux Distributions Standard, precompiled sets of packages, Standard, precompiled sets of packages,

or or distributionsdistributions, include the basic Linux , include the basic Linux system, system installation and system, system installation and management utilities, and ready to install management utilities, and ready to install packages of common UNIX tools.packages of common UNIX tools.

The first distributions managed these The first distributions managed these packages by simply providing a means of packages by simply providing a means of unpacking all the files into the unpacking all the files into the appropriate places; modern distributions appropriate places; modern distributions include advanced package management.include advanced package management.

Linux Distributions Linux Distributions (cont)(cont)

Early distributions included SLS and Early distributions included SLS and Slackware. Slackware. Red HatRed Hat and and DebianDebian are popular distributions from are popular distributions from commercial and noncommercial commercial and noncommercial sources, respectively.sources, respectively.

The RPM Package file format The RPM Package file format permits compatibility among the permits compatibility among the various Linux distributions.various Linux distributions.

Linux LicensingLinux Licensing

The Linux kernel is distributed under the The Linux kernel is distributed under the GNU General Public License (GPL), the GNU General Public License (GPL), the terms of which are set out by the Free terms of which are set out by the Free Software Foundation.Software Foundation.

Anyone using Linux, or creating their own Anyone using Linux, or creating their own derivative of Linux, may not make the derivative of Linux, may not make the derived product proprietary; software derived product proprietary; software released under the GPL may not be released under the GPL may not be redistributed as a binary only product.redistributed as a binary only product.

Design PrinciplesDesign Principles

Linux is a multiuser, multitasking Linux is a multiuser, multitasking system with a full set of UNIX system with a full set of UNIX compatible tools.compatible tools.

Its file system adheres to traditional Its file system adheres to traditional UNIX semantics, and it fully UNIX semantics, and it fully implements the standard UNIX implements the standard UNIX networking model.networking model.

Main design goals are speed, Main design goals are speed, efficiency, and standardization.efficiency, and standardization.

Design Principles Design Principles (cont)(cont)

Linux is designed to be compliant Linux is designed to be compliant with the relevant POSIX documents; with the relevant POSIX documents; at least two Linux distributions have at least two Linux distributions have achieved official POSIX certification.achieved official POSIX certification.

The Linux programming interface The Linux programming interface adheres to the SVR4 UNIX semantics, adheres to the SVR4 UNIX semantics, rather than to BSD behavior.rather than to BSD behavior.

Components of a Linux Components of a Linux SystemSystem

Components of a Linux Components of a Linux System System (cont)(cont)

Like most UNIX implementations, Linux is Like most UNIX implementations, Linux is composed of three main bodies of code; the composed of three main bodies of code; the most important distinction is between the most important distinction is between the kernel and all other components.kernel and all other components.

The The kernelkernel is responsible for maintaining the is responsible for maintaining the important abstractions of the operating system.important abstractions of the operating system.– Kernel code executes in Kernel code executes in kernel modekernel mode with full access with full access

to all the physical resources of the computer.to all the physical resources of the computer.– All kernel code and data structures are kept in the All kernel code and data structures are kept in the

same single address space.same single address space.

Components of a Linux Components of a Linux System System (cont)(cont)

The The system librariessystem libraries define a standard define a standard set of functions through which set of functions through which applications interact with the kernel, and applications interact with the kernel, and that implement much of the operating that implement much of the operating system functionality that does not need system functionality that does not need the full privileges of kernel code.the full privileges of kernel code.

The The system utilitiessystem utilities perform individual perform individual specialized management tasks.specialized management tasks.

Kernel ModulesKernel Modules Sections of kernel code that can be Sections of kernel code that can be

compiled, loaded, and unloaded compiled, loaded, and unloaded independent of the rest of the kernel.independent of the rest of the kernel.

A kernel module may typically implement a A kernel module may typically implement a device driver, a file system, or a device driver, a file system, or a networking protocol.networking protocol.

The module interface allows third parties to The module interface allows third parties to write and distribute, on their own terms, write and distribute, on their own terms, device drivers or file systems that could device drivers or file systems that could not be distributed under the GPL.not be distributed under the GPL.

Kernel Modules Kernel Modules (cont)(cont)

Kernel modules allow a Linux system Kernel modules allow a Linux system to be set up with a standard, minimal to be set up with a standard, minimal kernel, without any extra device kernel, without any extra device drivers built in.drivers built in.

Three components to Linux module Three components to Linux module support:support:– Module management Module management – Driver registrationDriver registration– Conflict resolutionConflict resolution

Module ManagementModule Management

Supports loading modules into Supports loading modules into memory and letting them talk to the memory and letting them talk to the rest of the kernel.rest of the kernel.

Module loading is split into two Module loading is split into two separate sections:separate sections:– Managing sections of module code in Managing sections of module code in

kernel memory.kernel memory.– Handling symbols that modules are Handling symbols that modules are

allowed to reference.allowed to reference.

Module Management Module Management (cont)(cont)

The module requestor manages The module requestor manages loading requested, but currently loading requested, but currently unloaded, modules; it also unloaded, modules; it also regularly queries the kernel to see regularly queries the kernel to see whether a dynamically loaded whether a dynamically loaded module is still in use, and will module is still in use, and will unload it when it is no longer unload it when it is no longer actively needed.actively needed.

Driver RegistrationDriver Registration

Allows modules to tell the rest of Allows modules to tell the rest of the kernel that a new driver has the kernel that a new driver has become available.become available.

The kernel maintains dynamic The kernel maintains dynamic tables of all known drivers, and tables of all known drivers, and provides a set of routines to allow provides a set of routines to allow drivers to be added to or removed drivers to be added to or removed from these tables at any time.from these tables at any time.

Driver Registration Driver Registration (cont)(cont)

Registration tables include the Registration tables include the following items: following items: – Device driversDevice drivers– File systems File systems – Network protocolsNetwork protocols– Binary formatBinary format

Conflict ResolutionConflict Resolution A mechanism that allows different device A mechanism that allows different device

drivers to reserve hardware resources and to drivers to reserve hardware resources and to protect those resources from accidental use by protect those resources from accidental use by another driver.another driver.

The conflict resolution module aims to:The conflict resolution module aims to:– Prevent modules from clashing over access to Prevent modules from clashing over access to

hardware resources.hardware resources.– Prevent Prevent autoprobes autoprobes from interfering with existing from interfering with existing

device drivers.device drivers.– Resolve conflicts with multiple drivers trying to Resolve conflicts with multiple drivers trying to

access the same hardware.access the same hardware.

Process ManagementProcess Management

UNIX process management UNIX process management separates the creation of processes separates the creation of processes and the running of a new program and the running of a new program into two distinct operations.into two distinct operations.– The The forkfork system call creates a new system call creates a new

process.process.– A new program is run after a call to A new program is run after a call to

execveexecve..

Process Management Process Management (cont)(cont)

Under UNIX, a process encompasses Under UNIX, a process encompasses all the information that the all the information that the operating system must maintain to operating system must maintain to track the context of a single track the context of a single execution of a single program.execution of a single program.

Under Linux, process properties fall Under Linux, process properties fall into three groups: the process’s into three groups: the process’s identity, environment, and context.identity, environment, and context.

Process IdentityProcess Identity

Process IDProcess ID (PID). The unique identifier for (PID). The unique identifier for the process; used to specify processes to the process; used to specify processes to the operating system when an application the operating system when an application makes a system call to signal, modify, or makes a system call to signal, modify, or wait for another process.wait for another process.

CredentialsCredentials. Each process must have an . Each process must have an associated user ID and one or more group associated user ID and one or more group IDs that determine the process’s rights to IDs that determine the process’s rights to access system resources and files.access system resources and files.

Process Identity Process Identity (cont)(cont)

PersonalityPersonality. Not traditionally found on . Not traditionally found on UNIX systems, but under Linux each UNIX systems, but under Linux each process has an associated personality process has an associated personality identifier that can slightly modify the identifier that can slightly modify the semantics of certain system calls.semantics of certain system calls.Used primarily by emulation libraries to Used primarily by emulation libraries to request that system calls be compatible request that system calls be compatible with certain specific flavors of UNIX.with certain specific flavors of UNIX.

Process EnvironmentProcess Environment The process’s environment is inherited from The process’s environment is inherited from

its parent, and is composed of two null-its parent, and is composed of two null-terminated vectors:terminated vectors:– The argument vector lists the command line The argument vector lists the command line

arguments used to invoke the running program; arguments used to invoke the running program; conventionally starts with the name of the conventionally starts with the name of the program itselfprogram itself

– The environment vector is a list of The environment vector is a list of “NAME=VALUE”“NAME=VALUE” pairs that associates named environment pairs that associates named environment variables with arbitrary textual values.variables with arbitrary textual values.

Process Environment Process Environment (cont)(cont)

Passing environment variables among Passing environment variables among processes and inheriting variables by a processes and inheriting variables by a process’s children are flexible means of process’s children are flexible means of passing information to components of the passing information to components of the user mode system software.user mode system software.

The environment variable mechanism The environment variable mechanism provides a customization of the operating provides a customization of the operating system that can be set on a per-process system that can be set on a per-process basis, rather than being configured for the basis, rather than being configured for the system as a whole.system as a whole.

Process ContextProcess Context

The (constantly changing) state of The (constantly changing) state of a running program at any point in a running program at any point in time.time.

The The scheduling contextscheduling context is the is the most important part of the process most important part of the process context; it is the information that context; it is the information that the scheduler needs to suspend the scheduler needs to suspend and restart the process.and restart the process.

Process Context Process Context (cont)(cont)

The kernel maintains The kernel maintains accountingaccounting information about the resources currently information about the resources currently being consumed by each process, and the being consumed by each process, and the total resources consumed by the process total resources consumed by the process in its lifetime so far.in its lifetime so far.

The The file tablefile table is an array of pointers to is an array of pointers to kernel file structures. When making file kernel file structures. When making file I/O system calls, processes refer to files I/O system calls, processes refer to files by their index into this table.by their index into this table.

Process Context Process Context (cont)(cont)

Whereas the file table lists the existing open Whereas the file table lists the existing open files, the files, the file system contextfile system context applies to applies to requests to open new files. The current root requests to open new files. The current root and default directories to be used for new file and default directories to be used for new file searches are stored here.searches are stored here.

The The signal handler tablesignal handler table defines the routine defines the routine in the process’s address space to be called in the process’s address space to be called when specific signals arrive.when specific signals arrive.

The The virtual memory contextvirtual memory context of a process of a process describes the full contents of the its private describes the full contents of the its private address space.address space.

Processes and ThreadsProcesses and Threads Linux uses the same internal representation for Linux uses the same internal representation for

processes and threads; a thread is simply a processes and threads; a thread is simply a new process that happens to share the same new process that happens to share the same address space as its parent.address space as its parent.

A distinction is only made when a new thread A distinction is only made when a new thread is created by the is created by the cloneclone system call. system call.– forkfork creates a new process with its own, entirely creates a new process with its own, entirely

new, process context.new, process context.– cloneclone creates a new process with its own identity, creates a new process with its own identity,

but that is allowed to share the data structures of but that is allowed to share the data structures of its parent.its parent.

Processes and Threads Processes and Threads (cont)(cont)

Using Using cloneclone gives an application gives an application fine grained control over exactly fine grained control over exactly what is shared between two what is shared between two threads.threads.

SchedulingScheduling The job of allocating CPU time to different The job of allocating CPU time to different

tasks within an operating system.tasks within an operating system. While scheduling is normally thought of as the While scheduling is normally thought of as the

running and interrupting of processes, in running and interrupting of processes, in Linux, scheduling also includes the running of Linux, scheduling also includes the running of the various kernel tasks.the various kernel tasks.

Running kernel tasks encompasses both tasks Running kernel tasks encompasses both tasks that are requested by a running process and that are requested by a running process and tasks that execute internally on behalf of a tasks that execute internally on behalf of a device driver.device driver.

Kernel SynchronizationKernel Synchronization A request for kernel mode execution can occur in A request for kernel mode execution can occur in

two ways:two ways:– A running program may request an operating system A running program may request an operating system

service, either explicitly via a system call, or implicitly, service, either explicitly via a system call, or implicitly, for example, when a page fault occurs.for example, when a page fault occurs.

– A device driver may deliver a hardware interrupt that A device driver may deliver a hardware interrupt that causes the CPU to start executing a kernel defined causes the CPU to start executing a kernel defined handler for that interrupt.handler for that interrupt.

Kernel synchronization requires a framework that Kernel synchronization requires a framework that will allow the kernel’s critical sections to run will allow the kernel’s critical sections to run without interruption by another critical section.without interruption by another critical section.

Kernel Synchronization Kernel Synchronization (cont)(cont)

Linux uses two techniques to protect Linux uses two techniques to protect critical sections:critical sections:– Normal kernel code is nonpreemptibleNormal kernel code is nonpreemptible

When a timer interrupt is received while a process When a timer interrupt is received while a process is executing a kernel system service routine, the is executing a kernel system service routine, the kernel’s kernel’s need_reschedneed_resched flag is set so that the flag is set so that the scheduler will run once the system call has scheduler will run once the system call has completed and control is about to be returned to completed and control is about to be returned to user mode. user mode.

Kernel Synchronization Kernel Synchronization (cont)(cont)

– The second technique applies to The second technique applies to critical sections that occur in interrupt critical sections that occur in interrupt service routines.service routines.

By using the processor’s interrupt control By using the processor’s interrupt control hardware to disable interrupts during a hardware to disable interrupts during a critical section, the kernel guarantees critical section, the kernel guarantees that it can proceed without the risk of that it can proceed without the risk of concurrent access of shared data concurrent access of shared data structures.structures.

Kernel Synchronization Kernel Synchronization (cont)(cont)

To avoid performance penalties, To avoid performance penalties, Linux’s kernel uses a Linux’s kernel uses a synchronization architecture that synchronization architecture that allows long critical sections to run allows long critical sections to run without having interrupts disabled without having interrupts disabled for the critical section’s entire for the critical section’s entire duration.duration.

Kernel Synchronization Kernel Synchronization (cont)(cont)

Interrupt service routines are separated into a Interrupt service routines are separated into a top halftop half and a and a bottom half.bottom half.– The top half is a normal interrupt service routine, and The top half is a normal interrupt service routine, and

runs with recursive interrupts disabled.runs with recursive interrupts disabled.– The bottom half is run, with all interrupts enabled, by The bottom half is run, with all interrupts enabled, by

a miniature scheduler that ensures that bottom a miniature scheduler that ensures that bottom halves never interrupt themselves.halves never interrupt themselves.

– This architecture is completed by a mechanism for This architecture is completed by a mechanism for disabling selected bottom halves while executing disabling selected bottom halves while executing normal, foreground kernel code.normal, foreground kernel code.

Interrupt Protection LevelsInterrupt Protection Levels

Each level may be interrupted by Each level may be interrupted by code running at a higher level, but code running at a higher level, but will never be interrupted by code will never be interrupted by code running at the same or a lower level.running at the same or a lower level.

Interrupt Protection Levels Interrupt Protection Levels (cont)(cont)

User processes can always be User processes can always be preempted by another process preempted by another process when a time sharing scheduling when a time sharing scheduling interrupt occurs.interrupt occurs.

Process SchedulingProcess Scheduling Linux uses two process scheduling Linux uses two process scheduling

algorithms:algorithms:– A time sharing algorithm for fair preemptive A time sharing algorithm for fair preemptive

scheduling between multiple processesscheduling between multiple processes– A real time algorithm for tasks where A real time algorithm for tasks where

absolute priorities are more important than absolute priorities are more important than fairnessfairness

A process’s scheduling class defines A process’s scheduling class defines which algorithm to apply.which algorithm to apply.

Process Scheduling Process Scheduling (cont)(cont)

For time sharing processes, Linux uses a For time sharing processes, Linux uses a prioritized, credit based algorithm.prioritized, credit based algorithm.– The crediting ruleThe crediting rule

factors in both the process’s history and its factors in both the process’s history and its priority.priority.

– This crediting system automatically This crediting system automatically prioritizes interactive or I/O bound processes.prioritizes interactive or I/O bound processes.

priority2

credits : credits

Process Scheduling Process Scheduling (cont)(cont)

Linux implements the FIFO and round robin real time Linux implements the FIFO and round robin real time scheduling classes; in both cases, each process has scheduling classes; in both cases, each process has a priority in addition to its scheduling class.a priority in addition to its scheduling class.– The scheduler runs the process with the highest priority; The scheduler runs the process with the highest priority;

for equal priority processes, it runs the longest waiting for equal priority processes, it runs the longest waiting one.one.

– FIFO processes continue to run until they either exit or FIFO processes continue to run until they either exit or block.block.

– A round robin process will be preempted after a while and A round robin process will be preempted after a while and moved to the end of the scheduling queue, so that round moved to the end of the scheduling queue, so that round robing processes of equal priority automatically time robing processes of equal priority automatically time share between themselves.share between themselves.

Symmetric Symmetric MultiprocessingMultiprocessing

Linux 2.0 was the first Linux kernel to Linux 2.0 was the first Linux kernel to support SMP hardware; separate support SMP hardware; separate processes or threads can execute in processes or threads can execute in parallel on separate processors.parallel on separate processors.

To preserve the kernel’s nonpreemptible To preserve the kernel’s nonpreemptible synchronization requirements, SMP synchronization requirements, SMP imposes the restriction, via a single kernel imposes the restriction, via a single kernel spinlock, that only one processor at a time spinlock, that only one processor at a time may execute kernel mode code.may execute kernel mode code.

Memory ManagementMemory Management

Linux’s physical memory Linux’s physical memory management system deals with management system deals with allocating and freeing pages, groups allocating and freeing pages, groups of pages, and small blocks of of pages, and small blocks of memory.memory.

It has additional mechanisms for It has additional mechanisms for handling virtual memory, memory handling virtual memory, memory mapped into the address space of mapped into the address space of running processes.running processes.

Managing Physical Managing Physical MemoryMemory

The page allocator allocates and frees all The page allocator allocates and frees all physical pages; it can allocate ranges of physical pages; it can allocate ranges of physically contiguous pages on request.physically contiguous pages on request.

The allocator uses a The allocator uses a buddy-heapbuddy-heap algorithm to algorithm to keep track of available physical pages.keep track of available physical pages.– Each allocatable memory region is paired with an Each allocatable memory region is paired with an

adjacent partner.adjacent partner.– Whenever two allocated partner regions are both Whenever two allocated partner regions are both

freed up, they are combined to form a larger freed up, they are combined to form a larger region.region.

Managing Physical Managing Physical Memory Memory (cont)(cont)

– If a small memory request cannot be If a small memory request cannot be satisfied by allocating an existing small free satisfied by allocating an existing small free region, then a larger free region will be region, then a larger free region will be subdivided into two partners to satisfy the subdivided into two partners to satisfy the request.request.

Memory allocations in the Linux kernel Memory allocations in the Linux kernel occur either statically (drivers reserve a occur either statically (drivers reserve a contiguous area of memory during contiguous area of memory during system boot time) or dynamically (via system boot time) or dynamically (via the page allocator).the page allocator).

Splitting of Memory in a Splitting of Memory in a Buddy HeapBuddy Heap

Virtual MemoryVirtual Memory

The VM system maintains the The VM system maintains the address space visible to each address space visible to each process. It creates pages of virtual process. It creates pages of virtual memory on demand, and manages memory on demand, and manages the loading of those pages from the loading of those pages from disk or their swapping back out to disk or their swapping back out to disk as required.disk as required.

Virtual Memory Virtual Memory (cont)(cont)

The VM manager maintains two separate The VM manager maintains two separate views of a process’s address space:views of a process’s address space:– A logical view describing instructions concerning A logical view describing instructions concerning

the layout of the address space.the layout of the address space.The address space consists of a set of The address space consists of a set of nonoverlapping regions, each representing a nonoverlapping regions, each representing a continuous, page aligned subset of the address continuous, page aligned subset of the address space.space.

– A physical view of each address space which is A physical view of each address space which is stored in the hardware page tables for the process.stored in the hardware page tables for the process.

Virtual Memory Virtual Memory (cont)(cont)

Virtual memory regions are characterized by:Virtual memory regions are characterized by:– The backing store, that describes from where the The backing store, that describes from where the

pages for a region come; regions are usually backed pages for a region come; regions are usually backed by a file or by nothing (by a file or by nothing (demand zerodemand zero memory) memory)

– The region’s reaction to writes (page sharing or The region’s reaction to writes (page sharing or copy-on-write).copy-on-write).

The kernel creates a new virtual address space:The kernel creates a new virtual address space:– When a process runs a new program with the When a process runs a new program with the execexec

system call.system call.– Upon creation of a new process by the Upon creation of a new process by the forkfork system system

call.call.

Virtual Memory Virtual Memory (cont)(cont)

On executing a new program, the On executing a new program, the process is given a new, completely process is given a new, completely empty virtual address space; the empty virtual address space; the program loading routines populate program loading routines populate the address space with virtual the address space with virtual memory regions.memory regions.

Virtual Memory Virtual Memory (cont)(cont)

Creating a new process with Creating a new process with forkfork involves involves creating a complete copy of the existing creating a complete copy of the existing process’s virtual address space.process’s virtual address space.– The kernel copies the parent process’s VMA The kernel copies the parent process’s VMA

descriptors, then creates a new set of page tables descriptors, then creates a new set of page tables for the child.for the child.

– The parent’s page tables are copied directly into The parent’s page tables are copied directly into the child’s, with the reference count of each page the child’s, with the reference count of each page covered being incremented.covered being incremented.

– After the fork, the parent and child share the same After the fork, the parent and child share the same physical pages of memory in their address spaces.physical pages of memory in their address spaces.

Virtual Memory Virtual Memory (cont)(cont)

The VM paging system relocates pages of The VM paging system relocates pages of memory from physical memory out to disk memory from physical memory out to disk when the memory is needed for something when the memory is needed for something else.else.

The VM paging system can be divided into two The VM paging system can be divided into two sections:sections:– The pageout-policy algorithm decides which pages The pageout-policy algorithm decides which pages

to write out to disk, and when.to write out to disk, and when.– The paging mechanism actually carries out the The paging mechanism actually carries out the

transfer, and pages data back into physical memory transfer, and pages data back into physical memory as needed.as needed.

Virtual Memory Virtual Memory (cont)(cont)

The Linux kernel reserves a The Linux kernel reserves a constant, architecture dependent constant, architecture dependent region of the virtual address space region of the virtual address space of every process for its own of every process for its own internal use.internal use.

Virtual Memory Virtual Memory (cont)(cont)

This kernel virtual memory area contains This kernel virtual memory area contains two regions:two regions:– A static area that contains page table A static area that contains page table

references to every available physical page of references to every available physical page of memory in the system, so that there is a memory in the system, so that there is a simple translation from physical to virtual simple translation from physical to virtual addresses when running kernel code.addresses when running kernel code.

– The remainder of the reserved section is not The remainder of the reserved section is not reserved for any specific purpose; its page reserved for any specific purpose; its page table entries can be modified to point to any table entries can be modified to point to any other areas of memory.other areas of memory.

Executing and Loading Executing and Loading User ProgramsUser Programs

Linux maintains a table of functions Linux maintains a table of functions for loading programs; it gives each for loading programs; it gives each function the opportunity to try function the opportunity to try loading the given file when an loading the given file when an execexec system call is made.system call is made.

The registration of multiple loader The registration of multiple loader routines allows Linux to support both routines allows Linux to support both the ELF and a.out binary formats.the ELF and a.out binary formats.

Executing and Loading Executing and Loading User Programs User Programs (cont)(cont)

Initially, binary file pages are mapped into Initially, binary file pages are mapped into virtual memory; only when a program tries virtual memory; only when a program tries to access a given page will a page fault to access a given page will a page fault result in that page being loaded into result in that page being loaded into physical memory.physical memory.

An ELF format binary file consists of a An ELF format binary file consists of a header followed by several page aligned header followed by several page aligned sections; the ELF loader works by reading sections; the ELF loader works by reading the header and mapping the sections of the the header and mapping the sections of the file into separate regions of virtual memory.file into separate regions of virtual memory.

Memory Layout for ELF Memory Layout for ELF ProgramsPrograms

Static and Dynamic Static and Dynamic LinkingLinking

A program whose necessary library A program whose necessary library functions are embedded directly in the functions are embedded directly in the program’s executable binary file is program’s executable binary file is staticallystatically linked to its libraries. linked to its libraries.

The main disadvantage of static linkage The main disadvantage of static linkage is that every program generated must is that every program generated must contain copies of exactly the same contain copies of exactly the same common system library functions.common system library functions.

Static and Dynamic Static and Dynamic Linking Linking (cont)(cont)

DynamicDynamic linking is more efficient in linking is more efficient in terms of both physical memory terms of both physical memory and disk space usage because it and disk space usage because it loads the system libraries into loads the system libraries into memory only once.memory only once.

File SystemsFile Systems

To the user, Linux’s file system To the user, Linux’s file system appears as a hierarchical directory appears as a hierarchical directory tree obeying UNIX semantics.tree obeying UNIX semantics.

Internally, the kernel hides Internally, the kernel hides implementation details and implementation details and manages the multiple different file manages the multiple different file systems via an abstraction layer, systems via an abstraction layer, that is, the that is, the virtual file system (VFS)virtual file system (VFS)..

File Systems File Systems (cont)(cont)

The Linux VFS is designed around object The Linux VFS is designed around object oriented principles and is composed of two oriented principles and is composed of two components:components:– A set of definitions that define what a file object A set of definitions that define what a file object

is allowed to look like.is allowed to look like. The The inode objectinode object and the and the file objectfile object structures structures

represent individual files.represent individual files. The The file systemfile system objectobject represents an entire file represents an entire file

system.system.

– A layer of software to manipulate those objects.A layer of software to manipulate those objects.

The Linux Ext2fs File The Linux Ext2fs File SystemSystem

Est2fs uses a mechanism similar to that of BSD Est2fs uses a mechanism similar to that of BSD Fast File System (ffs) for locating data blocks Fast File System (ffs) for locating data blocks belonging to a specific file.belonging to a specific file.

The main differences between ext2fs and ffs The main differences between ext2fs and ffs concern their disk allocation policies.concern their disk allocation policies.– In ffs, the disk is allocated to files in blocks of 8Kb, with In ffs, the disk is allocated to files in blocks of 8Kb, with

blocks being subdivided into fragments of 1Kb to store blocks being subdivided into fragments of 1Kb to store small files or partially filled blocks at the end of a file.small files or partially filled blocks at the end of a file.

– Ext2fs does not use fragments; it performs its Ext2fs does not use fragments; it performs its allocations in smaller units. The default block size on allocations in smaller units. The default block size on ext2fs is 1Kb, although 2Kb and 4Kb blocks are also ext2fs is 1Kb, although 2Kb and 4Kb blocks are also supported.supported.

Ext2fs File System Ext2fs File System (cont)(cont)

Ext2fs uses allocation policies Ext2fs uses allocation policies designed to place logically designed to place logically adjacent blocks of a file into adjacent blocks of a file into physically adjacent blocks on disk, physically adjacent blocks on disk, so that it can submit an I/O request so that it can submit an I/O request for several disk blocks as a single for several disk blocks as a single operation.operation.

Ext2fs Block-Allocation Ext2fs Block-Allocation PoliciesPolicies

The Linux Proc File SystemThe Linux Proc File System

The The procproc file system does not store data, file system does not store data, rather, its contents are computed on rather, its contents are computed on demand according to user file I/O demand according to user file I/O requests.requests.

procproc must implement a directory must implement a directory structure, and the file contents within; it structure, and the file contents within; it must then define a unique and persistent must then define a unique and persistent inode number for each directory and files inode number for each directory and files it contains.it contains.

Proc File System Proc File System (cont)(cont)

– It uses this inode number to identify It uses this inode number to identify just what operation is required when a just what operation is required when a user tries to read from a particular file user tries to read from a particular file inode or perform a lookup in a inode or perform a lookup in a particular directory inode.particular directory inode.

– When data is read from one of these When data is read from one of these files, files, procproc collects the appropriate collects the appropriate information, formats it into text form, information, formats it into text form, and places it into the requesting and places it into the requesting process’s read buffer.process’s read buffer.

Input and OutputInput and Output

The Linux device oriented file The Linux device oriented file system accesses disk storage system accesses disk storage through two caches:through two caches:– Data is cached in the page cache, that Data is cached in the page cache, that

is unified with the virtual memory is unified with the virtual memory system.system.

– Metadata is cached in the buffer Metadata is cached in the buffer cache, a separate cache indexed by cache, a separate cache indexed by the physical disk block.the physical disk block.

Input and Output Input and Output (cont)(cont)

Linux splits all devices into three classes:Linux splits all devices into three classes:– Block devicesBlock devices allow random access to allow random access to

completely independent, fixed size blocks of completely independent, fixed size blocks of data.data.

– Character devicesCharacter devices include most other include most other devices; they don’t need to support the devices; they don’t need to support the functionality of regular files.functionality of regular files.

– Network devicesNetwork devices are interfaced via the are interfaced via the kernel’s networking subsystem.kernel’s networking subsystem.

Device Driver Block Device Driver Block StructureStructure

Block DevicesBlock Devices

Provide the main interface to all disk Provide the main interface to all disk devices in a system.devices in a system.

The The block bufferblock buffer cache serves two main cache serves two main purposes:purposes:– It acts as a pool of buffers for active I/O.It acts as a pool of buffers for active I/O.– It serves as a cache for completed I/O.It serves as a cache for completed I/O.

The The request managerrequest manager manages the manages the reading and writing of buffer contents to reading and writing of buffer contents to and from a block device driver.and from a block device driver.

Character DevicesCharacter Devices

A device driver that does not offer A device driver that does not offer random access to fixed blocks of random access to fixed blocks of data.data.

A character device driver must A character device driver must register a set of functions that register a set of functions that implement the driver’s various file implement the driver’s various file I/O operations.I/O operations.

Character Devices Character Devices (cont)(cont)

The kernel performs almost no The kernel performs almost no preprocessing of a file read or write preprocessing of a file read or write request to a character device, but simply request to a character device, but simply passes on the request to the device.passes on the request to the device.

The main exception to this rule is the The main exception to this rule is the special subset of character device drivers special subset of character device drivers that implement terminal devices, for that implement terminal devices, for which the kernel maintains a standard which the kernel maintains a standard interface.interface.

Interprocess Interprocess CommunicationCommunication

Like UNIX, Linux informs processes that an event Like UNIX, Linux informs processes that an event has occurred via signals.has occurred via signals.

There is a limited number of signals, and they There is a limited number of signals, and they cannot carry information – only the fact that a cannot carry information – only the fact that a signal occurred is available to a process.signal occurred is available to a process.

The Linux kernel does not use signals to The Linux kernel does not use signals to communicate with processes that are running in communicate with processes that are running in kernel mode, rather, communication within the kernel mode, rather, communication within the kernel is accomplished via scheduling states and kernel is accomplished via scheduling states and wait.queuewait.queue structures. structures.

Passing Data Between Passing Data Between ProcessesProcesses

The pipe mechanism allows a child process to The pipe mechanism allows a child process to inherit a communication channel to its inherit a communication channel to its parent, data written to one end of the pipe parent, data written to one end of the pipe can be read at the other.can be read at the other.

Shared memory offers an extremely fast way Shared memory offers an extremely fast way of communicating; any data written by one of communicating; any data written by one process to a shared memory region can be process to a shared memory region can be read immediately by any other process that read immediately by any other process that has mapped that region into its address has mapped that region into its address space.space.

Passing Data Between Passing Data Between Processes Processes (cont)(cont)

To obtain synchronization, To obtain synchronization, however, shared memory must be however, shared memory must be used in conjunction with another used in conjunction with another Interprocess communication Interprocess communication mechanism.mechanism.

Shared Memory ObjectShared Memory Object The shared memory object acts as a backing The shared memory object acts as a backing

store for shared memory regions in the same store for shared memory regions in the same way as a file can act as backing store for a way as a file can act as backing store for a memory mapped memory region.memory mapped memory region.

Shared memory mappings direct page faults Shared memory mappings direct page faults to map in pages from a persistent shared to map in pages from a persistent shared memory object.memory object.

Shared memory objects remember their Shared memory objects remember their contents even if no processes are currently contents even if no processes are currently mapping them into virtual memory.mapping them into virtual memory.

Network StructureNetwork Structure

Networking is a key area of Networking is a key area of functionality for Linux.functionality for Linux.– It supports the standard Internet It supports the standard Internet

protocols for UNIX to UNIX protocols for UNIX to UNIX communications.communications.

– It also implements protocols native to It also implements protocols native to nonUNIX operating systems, in nonUNIX operating systems, in particular, protocols used on PC particular, protocols used on PC networks, such as Appletalk and IPX.networks, such as Appletalk and IPX.

Network Structure Network Structure (cont)(cont)

Internally, networking in the Linux Internally, networking in the Linux kernel is implemented by three kernel is implemented by three layers of software:layers of software:– Socket interface.Socket interface.– Protocol drivers.Protocol drivers.– Network device drivers.Network device drivers.

Network Structure Network Structure (cont)(cont)

The most important set of protocols in The most important set of protocols in the Linux networking system is the the Linux networking system is the internet protocol suite.internet protocol suite.– It implements routing between different It implements routing between different

hosts anywhere on the network.hosts anywhere on the network.– On top of the routing protocol are built On top of the routing protocol are built

the UDP, TCP and ICMP protocols.the UDP, TCP and ICMP protocols.

SecuritySecurity The The pluggable authentication modules pluggable authentication modules

(PAM)(PAM) system is available under Linux. system is available under Linux. PAM is based on a shared library that PAM is based on a shared library that

can be used by any system component can be used by any system component that needs to authenticate users.that needs to authenticate users.

Access control under UNIX systems, Access control under UNIX systems, including Linux, is performed through including Linux, is performed through the use of unique numeric identifiers the use of unique numeric identifiers ((uiduid and and gidgid).).

Security Security (cont)(cont)

Access control is performed by Access control is performed by assigning objects a assigning objects a protection protection maskmask, that specifies which access , that specifies which access modes — read, write, or execute — modes — read, write, or execute — are to be granted to processes are to be granted to processes with owner, group, or world with owner, group, or world access.access.

Security Security (cont)(cont)

Linux augments the standard UNIX Linux augments the standard UNIX setuidsetuid mechanism in two ways: mechanism in two ways:– It implements the POSIX specification’s It implements the POSIX specification’s

saved saved user-iduser-id mechanism, that allows mechanism, that allows a process to repeatedly drop and a process to repeatedly drop and reacquire its effective uid.reacquire its effective uid.

– It has added a process characteristic It has added a process characteristic that grants just a subset of the rights that grants just a subset of the rights of the effective uid.of the effective uid.

Security Security (cont)(cont)

Linux provides another mechanism Linux provides another mechanism that allows a client to selectively that allows a client to selectively pass access to a single file to some pass access to a single file to some server process without granting it server process without granting it any other privileges.any other privileges.