Lecture 5 The Linux System Operating System Concepts

  • Slides: 84
Download presentation
Lecture 5 : The Linux System Operating System Concepts Essentials – 8 th Edition

Lecture 5 : The Linux System Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Chapter 2: The Linux System n Linux History n Design Principles n Kernel Modules

Chapter 2: The Linux System n Linux History n Design Principles n Kernel Modules n Process Management n Scheduling n Memory Management n File Systems n Input and Output n Interprocess Communication n Network Structure n Security Operating System Concepts Essentials– 8 th Edition 15. 2 Silberschatz, Galvin and Gagne © 2011

Objectives n To explore the history of the UNIX operating system from which Linux

Objectives n To explore the history of the UNIX operating system from which Linux is derived and the principles which Linux is designed upon n To examine the Linux process model and illustrate how Linux schedules processes and provides interprocess communication n To look at memory management in Linux n To explore how Linux implements file systems and manages I/O devices Operating System Concepts Essentials– 8 th Edition 15. 3 Silberschatz, Galvin and Gagne © 2011

History Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne ©

History Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

History n Linux is a modern, free operating system based on UNIX standards n

History n Linux is a modern, free operating system based on UNIX standards n First developed as a small but self-contained kernel in 1991 by Linus Torvalds, with the major design goal of UNIX compatibility n Its history has been one of collaboration by many users from all around the world, corresponding almost exclusively over the Internet n It has been designed to run efficiently and reliably on common PC hardware, but also runs on a variety of other platforms n 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 Operating System Concepts Essentials– 8 th Edition 15. 5 Silberschatz, Galvin and Gagne © 2011

History n The Linux kernel is an entirely original piece of software developed from

History n The Linux kernel is an entirely original piece of software developed from scratch by the Linux community. n The Linux system, as we know it today, includes a multitude of components, some written from scratch, others borrowed from other development projects. n Linux distribution includes all the standard components of the Linux system, plus a set of administrative tools to simplify the initial installation and subsequent upgrading of Linux and to manage installation and removal of other packages on the system. n Many, varying Linux Distributions including the kernel, applications, and management tools. Operating System Concepts Essentials– 8 th Edition 15. 6 Silberschatz, Galvin and Gagne © 2011

The Linux Kernel n Version 0. 01 (May 1991) had no networking, ran only

The Linux Kernel n 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 n Linux 1. 0 (March 1994) included these new features: l Support for UNIX’s standard TCP/IP networking protocols l BSD-compatible socket interface for networking programming l Device-driver support for running IP over an Ethernet l Enhanced file system l Extra hardware support n Version 1. 2 (March 1995) was the final PC-only Linux kernel. Operating System Concepts Essentials– 8 th Edition 15. 7 Silberschatz, Galvin and Gagne © 2011

Linux 2. 0 n n n Released in June 1996, 2. 0 added two

Linux 2. 0 n n n Released in June 1996, 2. 0 added two major new capabilities: l Support for multiple architectures, including a fully 64 -bit native Alpha port l Support for multiprocessor architectures Other new features included: l Improved memory-management code l Improved TCP/IP performance l Standardized configuration interface Available for Motorola 68000 -series processors, Sun Sparc systems, and for PC and Power. Mac systems Operating System Concepts Essentials– 8 th Edition 15. 8 Silberschatz, Galvin and Gagne © 2011

The Linux System n Linux uses many tools developed as part of Berkeley’s BSD

The Linux System n Linux uses many tools developed as part of Berkeley’s BSD operating system, ex: Free Software Foundation's GNU project n The min system libraries were started by the GNU project, with improvements provided by the Linux community n Linux networking-administration tools were derived from 4. 3 BSD code; recent BSD derivatives such as Free BSD have borrowed code from Linux in return n The Linux system is maintained by a loose network of developers collaborating over the Internet, with a small number of public sites acting as de facto standard repositories. Operating System Concepts Essentials– 8 th Edition 15. 9 Silberschatz, Galvin and Gagne © 2011

Linux Distributions n Standard, precompiled sets of packages, or distributions, include the basic Linux

Linux Distributions n 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 n Early Linux distributions l n Red Hat and Debian are popular distributions, the first comes from a commercial Linux support company and the second from the free-software Linux community. The RPM Package file format permits compatibility among the various Linux distributions Operating System Concepts Essentials– 8 th Edition 15. 10 Silberschatz, Galvin and Gagne © 2011

Linux Licensing n The Linux kernel is distributed under the GNU General Public License

Linux Licensing n The Linux kernel is distributed under the GNU General Public License (GPL), the terms of which are set out by the Free Software Foundation n copyrights in Linux code are still held by the code’s various authors. n Linux is free software, however, in the sense that people can copy it, modify it, use it in any manner they want, and give away their own copies, without any restrictions. Operating System Concepts Essentials– 8 th Edition 15. 11 Silberschatz, Galvin and Gagne © 2011

Design Principles Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne

Design Principles Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Design Principles n Linux is a multiuser, multitasking system with a full set of

Design Principles n Linux is a multiuser, multitasking system with a full set of UNIX-compatible tools n Its file system adheres to traditional UNIX semantics, and it fully implements the standard UNIX networking model n Main design goals are speed, efficiency, and standardization n Linux is designed to be compliant with the relevant POSIX documents; at least two Linux distributions have achieved official POSIX certification n The Linux programming interface adheres to the SVR 4 UNIX semantics, rather than to BSD behavior Operating System Concepts Essentials– 8 th Edition 15. 13 Silberschatz, Galvin and Gagne © 2011

Components of a Linux System Operating System Concepts Essentials– 8 th Edition 15. 14

Components of a Linux System Operating System Concepts Essentials– 8 th Edition 15. 14 Silberschatz, Galvin and Gagne © 2011

Components of a Linux System (Cont. ) n The Linux system is composed of

Components of a Linux System (Cont. ) n The Linux system is composed of three main bodies of code, in line with most traditional UNIX implementations: 1. Kernel. The kernel is responsible for maintaining all the important abstractions of the operating system, including such things as virtual memory and processes. l Kernel code executes in kernel mode with full access to all the physical resources of the computer l All kernel code and data structures are kept in the same single address space. Why? 4 This single address space contains not only the core scheduling and virtual memory code but all kernel code, including all device drivers, file systems, and networking code. Operating System Concepts Essentials– 8 th Edition 15. 15 Silberschatz, Galvin and Gagne © 2011

Components of a Linux System (Cont. ) 2. System libraries. The system libraries define

Components of a Linux System (Cont. ) 2. System libraries. The system libraries define a standard set of functions through which applications can interact with the kernel. 3. System utilities. The system utilities are programs that perform individual, specialized management tasks. Some system utilities may be invoked just once to initialize and configure some aspect of the system; others—known as daemons in UNIX terminology—may run permanently, handling such tasks as responding to incoming network connections, accepting logon requests from terminals, and updating log files. Operating System Concepts Essentials– 8 th Edition 15. 16 Silberschatz, Galvin and Gagne © 2011

Kernel Modules Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne

Kernel Modules Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Kernel Modules n Sections of kernel code that can be compiled, loaded, and unloaded

Kernel Modules n Sections of kernel code that can be compiled, loaded, and unloaded independent of the rest of the kernel. n A kernel module may typically implement a device driver, a file system, or a networking protocol. n The module interface allows third parties to write and distribute, on their own terms, device drivers or file systems that could not be distributed under the GPL. n Kernel modules allow a Linux system to be set up with a standard, minimal kernel, without any extra device drivers built in. Operating System Concepts Essentials– 8 th Edition 15. 18 Silberschatz, Galvin and Gagne © 2011

Kernel Modules n Three components to Linux module support: l module management l driver

Kernel Modules n Three components to Linux module support: l module management l driver registration l conflict resolution Operating System Concepts Essentials– 8 th Edition 15. 19 Silberschatz, Galvin and Gagne © 2011

Module Management n Supports loading modules into memory and letting them talk to the

Module Management n Supports loading modules into memory and letting them talk to the rest of the kernel n The module requestor manages loading requested, but currently 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 Operating System Concepts Essentials– 8 th Edition 15. 20 Silberschatz, Galvin and Gagne © 2011

Driver Registration n Allows modules to tell the rest of the kernel that a

Driver Registration n Allows modules to tell the rest of the kernel that a new driver has become available n 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 Operating System Concepts Essentials– 8 th Edition 15. 21 Silberschatz, Galvin and Gagne © 2011

Driver Registration n Registration tables include the following items: l Device drivers. These drivers

Driver Registration n Registration tables include the following items: l Device drivers. These drivers include character devices (such as printers, terminals, and mice), block devices (including all disk drives), and network interface devices. l File systems. The file system may be anything that implements Linux’s virtual-filesystem calling routines. It might implement a format for storing files on a disk, but it might equally well be a network file system, such as NFS, or a virtual file system whose contents are generated on demand, such as Linux’s Operating System Concepts Essentials– 8 th Edition 15. 22 /proc file system. Silberschatz, Galvin and Gagne © 2011

Driver Registration n Registration tables include the following items: l Network protocols. A module

Driver Registration n Registration tables include the following items: l Network protocols. A module may implement an entire networking protocol, such as IPX, or simply a new set of packet-filtering rules for a network firewall. l Binary format. This format specifies a way of recognizing, and loading, a new type of executable file. Operating System Concepts Essentials– 8 th Edition 15. 23 Silberschatz, Galvin and Gagne © 2011

Conflict Resolution n A mechanism that allows different device drivers to reserve hardware resources

Conflict Resolution n A mechanism that allows different device drivers to reserve hardware resources and to protect those resources from accidental use by another driver. n The conflict resolution module aims to: l Prevent modules from clashing over access to hardware resources l Prevent autoprobes from interfering with existing device drivers l Resolve conflicts with multiple drivers trying to access the same hardware Operating System Concepts Essentials– 8 th Edition 15. 24 Silberschatz, Galvin and Gagne © 2011

Process Management Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne

Process Management Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Process Management n The basic principle of UNIX process management is to separate two

Process Management n The basic principle of UNIX process management is to separate two operations: the creation of a process and the running of a new program. l The fork system call creates a new process l A new program is run after a call to execve n 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 n Under Linux, process properties fall into three groups: l The process’s identity l Environment l Context Operating System Concepts Essentials– 8 th Edition 15. 26 Silberschatz, Galvin and Gagne © 2011

Process Identity n Process ID (PID). The unique identifier for the process; used to

Process Identity n 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. n 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. n 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. l Used primarily by emulation libraries to request that system calls be compatible with certain specific flavors of UNIX Operating System Concepts Essentials– 8 th Edition 15. 27 Silberschatz, Galvin and Gagne © 2011

Process Environment n The process’s environment is inherited from its parent, and is composed

Process Environment n The process’s environment is inherited from its parent, and is composed of two nullterminated vectors: l The argument vector lists the command-line arguments used to invoke the running program; conventionally starts with the name of the program itself. l The environment vector is a list of “NAME=VALUE” pairs that associates named environment variables with arbitrary textual values. Operating System Concepts Essentials– 8 th Edition 15. 28 Silberschatz, Galvin and Gagne © 2011

Process Context n The (constantly changing) state of a running program at any point

Process Context n The (constantly changing) state of a running program at any point in time. n Process context includes the following parts: l 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. l 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. l The file table is an array of pointers to kernel file structures. l When making file I/O system calls, processes refer to files by their index into this table. Operating System Concepts Essentials– 8 th Edition 15. 29 Silberschatz, Galvin and Gagne © 2011

Process Context (Cont. ) l Whereas the file table lists the existing open files,

Process Context (Cont. ) l Whereas the file table lists the existing open files, the file-system context applies to requests to open new files. 4 The current root and default directories to be used for new file searches are stored here. l The signal-handler table defines the routine in the process’s address space to be called when specific signals arrive. l The virtual-memory context of a process describes the full contents of the its private address space. Operating System Concepts Essentials– 8 th Edition 15. 30 Silberschatz, Galvin and Gagne © 2011

Processes and Threads n Linux uses the same internal representation for processes and threads;

Processes and Threads n 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. n A distinction is only made when a new thread is created by the clone system call. n l fork creates a new process with its own entirely new process context l clone creates a new process 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. Operating System Concepts Essentials– 8 th Edition 15. 31 Silberschatz, Galvin and Gagne © 2011

Processes and Threads n When clone() is invoked, it is passed a set of

Processes and Threads n When clone() is invoked, it is passed a set of flags that determine how much sharing is to take place between the parent and child tasks. Some of these flags are: Operating System Concepts Essentials– 8 th Edition 15. 32 Silberschatz, Galvin and Gagne © 2011

Scheduling Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne ©

Scheduling Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Scheduling n Scheduling is the job of allocating CPU time to different tasks within

Scheduling n Scheduling is the job of allocating CPU time to different tasks within an operating system. n 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. n Running kernel tasks encompasses both tasks that are requested by a running process and tasks that execute internally on behalf of a device driver. n As of 2. 5, new scheduling algorithm – preemptive, priority-based l Real-time range l nice value Operating System Concepts Essentials– 8 th Edition 15. 34 Silberschatz, Galvin and Gagne © 2011

Relationship Between Priorities and Time-slice Length Operating System Concepts Essentials– 8 th Edition 15.

Relationship Between Priorities and Time-slice Length Operating System Concepts Essentials– 8 th Edition 15. 35 Silberschatz, Galvin and Gagne © 2011

Relationship Between Priorities and Time-slice Length § The Linux scheduler is a preemptive, priority-based

Relationship Between Priorities and Time-slice Length § The Linux scheduler is a preemptive, priority-based algorithm with two separate priority ranges: § § a real-time range from 0 to 99 § a nice value ranging from 100 to 140. These two ranges map into a global priority scheme in which numerically lower values indicate higher priorities. § the Linux scheduler assigns higher-priority tasks longer time quanta and lower-priority tasks shorter time quanta. Operating System Concepts Essentials– 8 th Edition 15. 36 Silberschatz, Galvin and Gagne © 2011

List of Tasks Indexed by Priority Operating System Concepts Essentials– 8 th Edition 15.

List of Tasks Indexed by Priority Operating System Concepts Essentials– 8 th Edition 15. 37 Silberschatz, Galvin and Gagne © 2011

List of Tasks Indexed by Priority n Each processor maintains its own run queue

List of Tasks Indexed by Priority n Each processor maintains its own run queue and schedules itself independently. n Each run queue contains two priority arrays—active and expired. n The active array contains all tasks with time remaining in their time slices, and the expired array contains all expired tasks. n Each of these priority arrays includes a list of tasks indexed according to priority. n The scheduler chooses the task with the highest priority from the active array for execution on the CPU. n On multiprocessor machines, this means that each processor is scheduling the highestpriority task from its own run queue structure. n When all tasks have exhausted their time slices (that is, the active array is empty), n the two priority arrays are exchanged as the expired array becomes the active array and vice versa. Operating System Concepts Essentials– 8 th Edition 15. 38 Silberschatz, Galvin and Gagne © 2011

List of Tasks Indexed by Priority n Linux’s real-time scheduling is simpler still. n

List of Tasks Indexed by Priority n Linux’s real-time scheduling is simpler still. n Linux implements the two real time scheduling classes required by POSIX. 1 b: firstcome, first-served (FCFS) and round-robin. n In both cases, each process has a priority in addition to its scheduling class. n Processes with different priorities can compete with one another to some extent in timesharing scheduling; n in real-time scheduling, however, the scheduler always runs the process with the highest priority. n Among processes of equal priority, it runs the process that has been waiting longest. Operating System Concepts Essentials– 8 th Edition 15. 39 Silberschatz, Galvin and Gagne © 2011

List of Tasks Indexed by Priority n The only difference between FCFS and round-robin

List of Tasks Indexed by Priority n The only difference between FCFS and round-robin scheduling is that l FCFS processes continue to run until they either exit or block, whereas a roundrobin process will be preempted after a while and will be moved to the end of the scheduling queue. n so round-robin processes of equal priority will automatically time-share among themselves. n Unlike routine time-sharing tasks, real-time tasks are assigned static priorities. Operating System Concepts Essentials– 8 th Edition 15. 40 Silberschatz, Galvin and Gagne © 2011

Process Scheduling n Linux uses two process-scheduling algorithms: l l n A time-sharing algorithm

Process Scheduling n Linux uses two process-scheduling algorithms: l l n 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 process’s scheduling class defines which algorithm to apply. Operating System Concepts Essentials– 8 th Edition 15. 41 Silberschatz, Galvin and Gagne © 2011

Process Scheduling (Cont. ) n Linux implements the FIFO and round-robin real-time scheduling classes;

Process Scheduling (Cont. ) n Linux implements the FIFO and round-robin real-time scheduling classes; in both cases, each process has a priority in addition to its scheduling class. l The scheduler runs the process with the highest priority; for equal-priority processes, it runs the process waiting the longest. l FIFO processes continue to run until they either exit or block. l A round-robin process will be preempted after a while and moved to the end of the scheduling queue, so that round-robin processes of equal priority automatically time-share between themselves. Operating System Concepts Essentials– 8 th Edition 15. 42 Silberschatz, Galvin and Gagne © 2011

Kernel Synchronization n n A request for kernel-mode execution can occur in two ways:

Kernel Synchronization n n A request for kernel-mode execution can occur in two ways: l A running program may request an operating system service, either explicitly via a system call, or implicitly, for example, when a page fault occurs l 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. Operating System Concepts Essentials– 8 th Edition 15. 43 Silberschatz, Galvin and Gagne © 2011

Kernel Synchronization (Cont. ) n Linux uses two techniques to protect critical sections: 1.

Kernel Synchronization (Cont. ) n Linux uses two techniques to protect critical sections: 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 kernel’s 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 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 Operating System Concepts Essentials– 8 th Edition 15. 44 Silberschatz, Galvin and Gagne © 2011

Kernel Synchronization (Cont. ) n To avoid performance penalties, Linux’s kernel uses a synchronization

Kernel Synchronization (Cont. ) n To avoid performance penalties, Linux’s kernel uses a synchronization architecture that allows long critical sections to run without having interrupts disabled for the critical section’s entire duration n Interrupt service routines are separated into a top half and a bottom half. l The top half is a normal interrupt service routine, and runs with recursive interrupts disabled l The bottom half is run, with all interrupts enabled, by a miniature scheduler that ensures that bottom halves never interrupt themselves l This architecture is completed by a mechanism for disabling selected bottom halves while executing normal, foreground kernel code Operating System Concepts Essentials– 8 th Edition 15. 45 Silberschatz, Galvin and Gagne © 2011

Interrupt Protection Levels n Each level may be interrupted by code running at a

Interrupt Protection Levels n Each level may be interrupted by code running at a higher level, but will never be interrupted by code running at the same or a lower level. n User processes can always be preempted by another process when a time-sharing scheduling interrupt occurs. Operating System Concepts Essentials– 8 th Edition 15. 46 Silberschatz, Galvin and Gagne © 2011

Symmetric Multiprocessing n Linux 2. 0 was the first Linux kernel to support SMP

Symmetric Multiprocessing n Linux 2. 0 was the first Linux kernel to support SMP hardware; separate processes or threads can execute in parallel on separate processors. n To preserve the kernel’s nonpreemptible synchronization requirements, SMP imposes the restriction, via a single kernel spinlock, that only one processor at a time may execute kernel-mode code. Operating System Concepts Essentials– 8 th Edition 15. 47 Silberschatz, Galvin and Gagne © 2011

Memory Management Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne

Memory Management Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Memory Management n Linux’s physical memory-management system has two components: 1. Deals with allocating

Memory Management n Linux’s physical memory-management system has two components: 1. Deals with allocating and freeing pages, groups of pages, and small blocks of memory. 2. Handling virtual memory, memory mapped into the address space of running processes. Operating System Concepts Essentials– 8 th Edition 15. 49 Silberschatz, Galvin and Gagne © 2011

Memory Management n Memory is a continuous set of bits referenced by specific addresses

Memory Management n Memory is a continuous set of bits referenced by specific addresses Operating System Concepts Essentials– 8 th Edition 15. 50 Silberschatz, Galvin and Gagne © 2011

Partition Memory Management n Partitions Main memory is divided into a particular number of

Partition Memory Management n Partitions Main memory is divided into a particular number of partitions n Programs are loaded into available partitions Operating System Concepts Essentials– 8 th Edition 15. 51 10 -51 Silberschatz, Galvin and Gagne © 2011

Paged Memory Management n Paged memory technique: Processes are divided into fixed-size pages and

Paged Memory Management n Paged memory technique: Processes are divided into fixed-size pages and stored in memory frames l Frame: A piece of main memory that holds a process page l Page: A piece of a process that is stored into a memory frame l Page-map table (PMT): A table used by the operating system to keep track of page/frame relationships Operating System Concepts Essentials– 8 th Edition 15. 52 Silberschatz, Galvin and Gagne © 2011

Paged Memory Management n To produce a physical address, you first look up the

Paged Memory Management n To produce a physical address, you first look up the page in the PMT to find the frame number in which it is stored n Then multiply the frame number by the frame size and add the offset to get the physical address Operating System Concepts Essentials– 8 th Edition 15. 53 Silberschatz, Galvin and Gagne © 2011

Paged Memory Management n n Demand paging An important extension of paged memory management

Paged Memory Management n n Demand paging An important extension of paged memory management l Not all parts of a program actually have to be in memory at the same time l In demand paging, the pages are brought into memory on demand Page swap The act of bringing in a page from secondary memory, which often causes another page to be written back to secondary memory Operating System Concepts Essentials– 8 th Edition 15. 54 10 -54 Silberschatz, Galvin and Gagne © 2011

Page Frame Management n Page frames are 4 KB in Linux. n The kernel

Page Frame Management n Page frames are 4 KB in Linux. n The kernel must keep track of the current status of each frame. l Are page frames allocated or free? l If allocated, do they contain process or kernel pages? l Linux maintains an array of page frame descriptors (one for each frame) of type struct page. Operating System Concepts Essentials– 8 th Edition 15. 55 Silberschatz, Galvin and Gagne © 2011

Page Frame Descriptors n Each descriptor has several fields, including: l count - equals

Page Frame Descriptors n Each descriptor has several fields, including: l count - equals 0 if frame is free, >0 otherwise. l flags - an array of 32 bits for frame status. 4 Example flag values: – PG_locked - page cannot be swapped out. – PG_reserved - page frame reserved for kernel code or unusable. Operating System Concepts Essentials– 8 th Edition 15. 56 Silberschatz, Galvin and Gagne © 2011

Managing Physical Memory n The page allocator allocates and frees all physical pages; it

Managing Physical Memory n The page allocator allocates and frees all physical pages; it can allocate ranges of physicallycontiguous pages on request. n The allocator uses a buddy-heap algorithm to keep track of available physical pages l Each allocatable memory region is paired with an adjacent partner l l n 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. Memory allocations in the Linux kernel occur either statically (drivers reserve a contiguous area of memory during system boot time) or dynamically (via the page allocator). Operating System Concepts Essentials– 8 th Edition 15. 57 Silberschatz, Galvin and Gagne © 2011

Splitting of Memory in a Buddy Heap Operating System Concepts Essentials– 8 th Edition

Splitting of Memory in a Buddy Heap Operating System Concepts Essentials– 8 th Edition 15. 58 Silberschatz, Galvin and Gagne © 2011

Paged Memory Management n The demand paging approach gives rise to the idea of

Paged Memory Management n The demand paging approach gives rise to the idea of virtual memory, the illusion that there are no restrictions on the size of a program. n Too much page swapping, however, is called thrashing and can seriously degrade system performance. Operating System Concepts Essentials– 8 th Edition 15. 59 10 -59 Silberschatz, Galvin and Gagne © 2011

Virtual Memory n The VM system maintains the address space visible to each process:

Virtual Memory n The VM system maintains the address space visible to each process: l 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. Operating System Concepts Essentials– 8 th Edition 15. 60 Silberschatz, Galvin and Gagne © 2011

Virtual Memory (Cont. ) n The kernel creates a new virtual address space 1.

Virtual Memory (Cont. ) n 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 Operating System Concepts Essentials– 8 th Edition 15. 61 Silberschatz, Galvin and Gagne © 2011

Virtual Memory (Cont. ) n On executing a new program, the process is given

Virtual Memory (Cont. ) n On executing a new program, the process is given a new, completely empty virtual-address space; the program-loading routines populate the address space with virtual-memory regions. n Creating a new process with fork involves creating a complete copy of the existing process’s virtual address space. l The kernel copies the parent process’s VMA descriptors, then creates a new set of page tables for the child. l The parent’s page tables are copied directly into the child’s, with the reference count of each page covered being incremented. l After the fork, the parent and child share the same physical pages of memory in their address spaces. Operating System Concepts Essentials– 8 th Edition 15. 62 Silberschatz, Galvin and Gagne © 2011

Virtual Memory (Cont. ) n The VM paging system relocates pages of memory from

Virtual Memory (Cont. ) n The VM paging system relocates pages of memory from physical memory out to disk when the memory is needed for something else. n The VM paging system can be divided into two sections: l The pageout-policy algorithm decides which pages to write out to disk, and when l The paging mechanism actually carries out the transfer, and pages data back into physical memory as needed Operating System Concepts Essentials– 8 th Edition 15. 63 Silberschatz, Galvin and Gagne © 2011

Virtual Memory (Cont) n This kernel virtual-memory area contains two regions: l A static

Virtual Memory (Cont) n This kernel virtual-memory area contains two regions: l 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. l 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. Operating System Concepts Essentials– 8 th Edition 15. 64 Silberschatz, Galvin and Gagne © 2011

File Systems Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne

File Systems Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

File Systems n File systems: Systems that controls how the computer stores files on

File Systems n File systems: Systems that controls how the computer stores files on disk and how it retrieves them. n Linux retains UNIX’s standard file-system model. n In UNIX, a file does not have to be an object stored on disk or fetched over a network from a remote file server. n Rather, UNIX files can be anything capable of handling the input or output of a stream of data. n Device drivers can appear as files, and interprocesscommunication channels or network connections also look like files to the user. Operating System Concepts Essentials– 8 th Edition 15. 66 Silberschatz, Galvin and Gagne © 2011

The Linux Ext 2 fs File System n The standard on-disk file system used

The Linux Ext 2 fs File System n The standard on-disk file system used by Linux is called second extended file system (ext 2 fs). n Ext 2 fs uses a mechanism for locating data blocks belonging to a specific file. l Ext 2 fs does not use fragments; it performs its allocations in smaller units 4 l The default block size on ext 2 fs is 1 Kb, although 2 Kb and 4 Kb blocks are also supported Ext 2 fs 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 Operating System Concepts Essentials– 8 th Edition 15. 67 Silberschatz, Galvin and Gagne © 2011

The Linux Ext 2 fs File System n The ext 2 fs allocation policy

The Linux Ext 2 fs File System n The ext 2 fs allocation policy comes in two parts. l An ext 2 fs file system is partitioned into multiple block groups. ext 2 fs uses the concept of cylinder groups, where each group corresponds to a single cylinder of a physical disk. l However, modern disk-drive technology packs sectors onto the disk at different densities, and thus with different cylinder sizes, depending on how far the disk head is from the center of the disk. Therefore, fixed-sized cylinder groups do not necessarily correspond to the disk’s geometry Operating System Concepts Essentials– 8 th Edition 15. 68 Silberschatz, Galvin and Gagne © 2011

Ext 2 fs Block-Allocation Policies Operating System Concepts Essentials– 8 th Edition 15. 69

Ext 2 fs Block-Allocation Policies Operating System Concepts Essentials– 8 th Edition 15. 69 Silberschatz, Galvin and Gagne © 2011

Input and Output Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and

Input and Output Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Input and Output n Linux splits all devices into three classes: l Block devices

Input and Output n Linux splits all devices into three classes: l Block devices l Character devices l Network devices Operating System Concepts Essentials– 8 th Edition 15. 71 Silberschatz, Galvin and Gagne © 2011

Input and Output n Block device: l is one with which the driver communicates

Input and Output n Block device: l is one with which the driver communicates by sending fixed-sized blocks of data. l may be accessed randomly. l Example: hard disk and floppy disk, CD-ROMs, flash memory and USB cameras. Operating System Concepts Essentials– 8 th Edition 15. 72 Silberschatz, Galvin and Gagne © 2011

Input and Output n Character device: l is one with which the driver communicates

Input and Output n Character device: l is one with which the driver communicates by sending or receiving single characters (Bytes). l only accessed serially. l Example: serial port, parallel port , mice , keyboards and sound cards. Operating System Concepts Essentials– 8 th Edition 15. 73 Silberschatz, Galvin and Gagne © 2011

Input and Output n Network device: l l Are dealt with differently from block

Input and Output n Network device: l l Are dealt with differently from block and character devices. Users cannot directly transfer data to network devices; instead, they must communicate indirectly by opening a connection to the kernel’s networking subsystem. Operating System Concepts Essentials– 8 th Edition 15. 74 Silberschatz, Galvin and Gagne © 2011

Device-Driver Block Structure Operating System Concepts Essentials– 8 th Edition 15. 75 Silberschatz, Galvin

Device-Driver Block Structure Operating System Concepts Essentials– 8 th Edition 15. 75 Silberschatz, Galvin and Gagne © 2011

Interprocess Communication Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne

Interprocess Communication Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Interprocess Communication n The standard Linux mechanism for informing a process that an event

Interprocess Communication n The standard Linux mechanism for informing a process that an event has occurred is the signal. n Signals can be sent from any process to any other process. n There is a limited number of signals, and they cannot carry information: Only the fact that a signal occurred is available to a process. n Whenever a process wants to wait for some event to complete, it places itself on a wait queue associated with that event. n The Linux kernel does not use signals to communicate with processes with are running in kernel mode, rather, communication within the kernel is accomplished via scheduling states and wait. queue structures. Operating System Concepts Essentials– 8 th Edition 15. 77 Silberschatz, Galvin and Gagne © 2011

Passing Data Between Processes n The pipe mechanism allows a child process to inherit

Passing Data Between Processes n The pipe mechanism allows a child process to inherit a communication channel to its parent, data written to one end of the pipe can be read a the other. n 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. n To obtain synchronization, however, shared memory must be used in conjunction with another Interprocess-communication mechanism. Operating System Concepts Essentials– 8 th Edition 15. 78 Silberschatz, Galvin and Gagne © 2011

Network Structure Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne

Network Structure Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Network Structure n n Networking is a key area of functionality for Linux. l

Network Structure n n Networking is a key area of functionality for Linux. l It supports the standard Internet protocols for UNIX to UNIX communications l It also implements protocols native to non. UNIX operating systems, in particular, protocols used on PC networks, such as Appletalk and IPX Internally, networking in the Linux kernel is implemented by three layers of software: l The socket interface l Protocol drivers l Network device drivers Operating System Concepts Essentials– 8 th Edition 15. 80 Silberschatz, Galvin and Gagne © 2011

Network Structure (Cont. ) n The socket interface l n n Receives all network

Network Structure (Cont. ) n The socket interface l n n Receives all network requests and send them to protocol driver. Protocol drivers l Create new packet l Rewrite packet l Reassembly or fragment packet l Remove packet l Decide which socket or device will send the packet Network device drivers l Forward packet to suitable host Operating System Concepts Essentials– 8 th Edition 15. 81 Silberschatz, Galvin and Gagne © 2011

Network Structure (Cont. ) n The most important set of protocols in the Linux

Network Structure (Cont. ) n The most important set of protocols in the Linux networking system is the internet protocol suite l It implements routing between different hosts anywhere on the network Operating System Concepts Essentials– 8 th Edition 15. 82 Silberschatz, Galvin and Gagne © 2011

Security Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne ©

Security Operating System Concepts Essentials – 8 th Edition Silberschatz, Galvin and Gagne © 2011

Security n The security concerns can be classified in two groups: l Authentication: Making

Security n The security concerns can be classified in two groups: l Authentication: Making sure that nobody can access the system without first proving that she has entry rights l Access control: Providing a mechanism for checking whether a user has the right to access a certain object and preventing access to objects as required. n The pluggable authentication modules (PAM) system is available under Linux. n PAM is based on a shared library that can be used by any system component that needs to authenticate users. n Access control under UNIX systems, including Linux, is performed through the use of unique numeric identifiers (uid and gid). Operating System Concepts Essentials– 8 th Edition 15. 84 Silberschatz, Galvin and Gagne © 2011