Upload
john-cutajar
View
2.182
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
OPERATING SYSTEMIntermediate Level
© Cutajar & Cutajar 2009
MODULE 5
Operating Systems 2
WHAT IS AN OPERATING SYSTEM
An OPERATING SYSTEM (OS) is set of programs that manage all the hardware resources of a computer system, thus isolating the user from the complexities of direct use of the computer hardware.
The operating system manages resources such as:
input (keyboard, mouse, ),
processing (CPU, … ),
storage (main memory, hard discs, floppy discs, … )
output ( monitor, printer, … ).
It controls the way in which these resources are put to work.
Operating Systems 3
ROLE OF THE OPERATING SYSTEM
Hardware
User
User Interface
OS Function Call Interface
Operating Systems 4
COMPUTER SYSTEM HIERARCHY
The computer system hierarchy :
Computer Hardware
User 1 User 2 User n
Operating System
Compiler database word
System processor
System and application programs
Operating Systems 5
LOADING AN OPERATING SYSTEM
The operating system is usually held on disk and has to be loaded into main memory once the computer is switched on before any other program can be run. Exception: In very compact systems, the OS may be held in ROM.
The process of loading the operating system is called BOOTING the system.
The BOOTSTRAP LOADER is an initial small program that executes itself once the system is powered on. This loader is held in ROM. It tells the computer where to look for the operating system and gives instructions to load at least part of it into memory.
Once part of the OS has been loaded, more instructions can be executed to load the rest of the OS kernel (nucleus).
The operating system then waits for some event to occur.
Operating Systems 6
OBJECTIVES OF AN OPERATING SYSTEM
1. To make it possible for the resources of the computer to be used efficiently.
Efficient resource utilisation is made especially difficult by the fact that some devices of a computer work much more quickly than others. Part of the task of the operating system is to ensure that fast devices such as processors, are not held up by slower peripheral devices. Thus the operating system is responsible for allocating and controlling use of all resources of a computer system.
2. To conceal the difficulties of dealing directly with the hardware of the computer.
To simplify the use of the hardware of a computer, the OS creates a VIRTUAL MACHINE i.e. it takes care of the hardware difficulties presented by the different component devices of the computer system and provides the user with a simplified computer environment. Thus a computer user need only know about (and how to operate) the „virtual machine‟.
Operating Systems 7
DESIRABLE FEATURES OF OPERATING SYSTEMS
Efficiency An OS must carry out its tasks promptly. Time spent on operating system
functions is productive time wasted.
Reliability Failure in an OS can render the host computer useless. An OS program
should do what it has to do correctly. Ideally the OS should be error free and able to handle all contingencies - robustness.
Maintainability Clearly written, well-structured (operating system) programs are essential
for any later modifications. This is a very complex set of programs to develop; it is costly to produce (hence well-structuring and modularity encourage the reusability of code). Also remember that maintenance is the most costly part of any software existence cycle, hence having features which enhance maintainability help keep maintenance costs down.
Small Size Space used to hold the OS whether in main memory or on backing store is
wasted as far as productive computing is concerned.
Operating Systems 8
TYPES OF OPERATING SYSTEMS
Operational mode is the form of operational organisation which determines the way in which the computer system is being used. This is determined by the operating system which is currently controlling the computer.
Batch
Online
Multiprogramming (multitasking)
Time-sharing (multi-access)
Single-user
Real-time
o Hard real-time (process control)
o Soft real-time (transaction processing)
Operating Systems 9
BATCH
A number of programs are batched together and run as a group. Although the programs are run one at a time, input and output from various programs can overlap to some extent.
Programs are usually queued up for batch processing and the operating system starts the next program in the queue as soon as sufficient computing resources are available for it. Some application area examples are payroll, processing of utility bills and master file updating process.
The main characteristic of batch processing is the lack of interaction between the user and the job while the job is executing.
Note that the above set up with the interleaving of batch jobs is better known as multiprogrammed batched system as against the simpler batch type where jobs are run one after the other. Multiprogrammed batch systems were facilitated by technological development. This set-up ensures better utilisation of the resources, the CPU in particular.
Operating Systems 10
MULTIPROGRAMMING (MULTITASKING)
At any one time, a number of programs are on the computer at various stages of completion. (Remember multi-programmed batch systems!).
Resources are allocated to programs according to the requirements of the programs and in order to maximise the usage of the resources of the computer.
Having multiple jobs running concurrently on the same system implies more demanding operating system functions such as process scheduling, memory management and system security and protection.
It also implies better utilisation of computer resources.
CPU idle
CPU idle
UNI
MULTI
time
Operating Systems 11
TIME-SHARING (MULTI-ACCESS)
Time-sharing systems are a logical extension of multiprogramming systems. The operating system allows many users to use the computer at apparently the same time.
Each job on the computer is given a quantum of processing time. The CPU switches from one job to another so quickly that each user is given the impression that s/he has her own computer, whereas actually one computer is being shared by several users.
Time-sharing systems make possible the interactive use of multi-programmed computer systems. In this environment, the user gives instructions to the computer and immediately receives a response.
Most operating systems provide both batch processing and time-sharing (although their basic design is either one or the other).
Operating Systems 12
REAL-TIME SYSTEM
A real-time system is used when there are rigid time requirements on the operation of a processor or the flow of data such as systems that control scientific experiments, medical imaging systems, industrial control systems, some display systems, home-appliance controllers, weapon systems.
They can be classified in:
Hard real-time (Real-time process control)
Soft real-time (Real-time transaction processing)
time
deadline
BOOM!
HARD
SOFT
Operating Systems 13
REAL-TIME PROCESS CONTROL
Real-time process control systems require that all delays are bounded, from the retrieval of stored data to the time that it takes the operating system to finish any request made of it.
Such time constraints dictate the facilities that are available in hard real-time systems - secondary storage is either missing or very limited, virtual memory is non-existent, advanced OS features separating user from hardware are absent.
Hard real-time systems cannot be mixed with the operation of time-sharing systems (and any general purpose operating system) because of conflicting features.
Operating Systems 14
REAL-TIME ONLINE TRANSACTION PROCESSING
Online Transaction Processing (OLTP) systems are less restrictive. A critical real-time task gets priority over other tasks and retains that priority until it completes. This type of real-time system may be mixed with other types of systems. (Application areas include interactive database applications, multimedia presentations, virtual reality, )
Operating Systems 15
PARALLEL (MULTIPROCESSOR) SYSTEM
Computer systems having more than one processor enjoy increased throughput (more work is done in a shorter period of time), increased reliability (failure of one processor will not halt the system - the ability to continue providing service proportional to the level of surviving hardware is called graceful degradation – systems designed for graceful degradation are called fault tolerant)
Processors share the computer bus, the clock, memory and peripheral devices and are referred to as tightly coupled systems.
Operating Systems 16
DISTRIBUTED SYSTEM
In this environment, computation is distributed among several processors. In contrast to tightly coupled systems, processors do not share memory or a clock; each processor has its own local memory. Processors communicate with one another through various communication lines (high speed buses, telephone line).
Hence they are usually referred to as loosely coupled systems. Processors in a distributed system may vary in size and function – small microprocessors, workstations, minicomputers, and large general-purpose computer systems.
Reasons for building distributed systems may include: Resource sharing: a user may use resources residing at another site,
Computation speedup: partitioning a computation across a number of sites or moving a computation to another more lightly loaded site (load sharing),
Reliability: if one site fails other sites can continue operating given that the system has sufficient inbuilt redundancy (in both hardware and data),
Communication: Processes at different sites have the possibility of exchanging information; besides users may initiate file transfers or communicate with each other via email.
Note that a distributed system implies a Network system. A network OS is one that supports the interconnection of computers that communicate with each other and are connected together according to a predefined topology.
Operating Systems 17
COMPUTER OPERATION TERMINOLOGY
On-line operation: this is processing carried out on devices under the control of the central processor, while the user remains in communication with the computer.
Example: OS sending a command to a printer to change its present printing font.
Off-line operation: this is processing carried out by devices not under the immediate control of the central processing.
Example: pressing the printer Line Feed button while the printer is off-line.
Remote Access: It is a form of access where the computer terminal is physically separated from the central computer installation.
Example: work from home through a modem using Telnet.
Operating Systems 18
FUNCTIONS OF AN OPERATING SYSTEM
Main functions of an operating system include:
Process Management : allowing processes to co-exist in the system, allocating job priorities, scheduling processor time
Memory Management: allocating main memory space to each process, protecting processes from one another, enabling different processes to share the same memory.
Input/output control: Channelling data to and from peripherals of the computer
File Management: allocating space on secondary storage media, keep track of data stored on secondary storage, control file access rights and privileges
Error handling and protection: The detection and reporting of errors and minimising their effect. Also it involves protection against errors and against deliberate abuse of the system.
Operating Systems 19
STRUCTURE OF OPERATING SYSTEM
ACCOUNTING
PROTECTION
RESOURCE ALLOCATION
BACKING STORE MANAGEMENT
I/O CONTROL
MEMORY MANAGEMENT
NUCLEUS
HARDWARE
The program structure of an operating system is presented as a number of modules:
Operating Systems 20
NUCLEUS (KERNEL)
This is the lowest level of an OS. It has direct interaction with the hardware. It provides a number of services to the other modules:
Handling of interrupts
An interrupt is a signal generated by a source such as some input or output device or a system software routine, which causes a break in the execution of the current routine. Control passes to another routine in such a way that afterwards the original routine may be resumed.
o Examples of interrupts are information transfer requests, errors
Co-ordinates the way in which different processes can exist together.
The OS provides the mechanism for switching the processor from one job to another. The OS shares the processor time amongst the different tasks in the system in a way so as to maximise processor utilisation
Allocation of work to the processor
In many cases more than one job exists in the system at the same time. The OS provides the mechanism for switching from one job to another
Operating Systems 21
MEMORY MANAGEMENT
The main memory of most computers is too small to handle all programs and data all at one time. This part of the OS allocates main memory, normally RAM, to programs or parts of programs that need it most. Everything else is kept on backing store.
Virtual memory is a technique used by this layer of the OS. Virtual memory is when the computer appears to have more main memory than it physically has.
Caching is a technique used to enhance system performance. Some very fast memory called Cache memory, usually static RAM, is reserved to store sections of the executing routines in order to take advantage of the short access time hence reducing the fetch-execute cycle time.
Operating Systems 22
I/O CONTROL
I/O devices have different characteristics and run at different speeds. The OS makes these problems transparent to the user. From a user‟s point of view all devices have the same characteristics and are instructed in the same way. Thus I/O is DEVICE DEPENDANT from a user‟s point of view.
The OS deals with the physical aspects (e.g. Blocks on disk) of the data transfer leaving the programmer free to concentrate on the logical aspects of the data structure transferred.
A very useful output technique (usually used for printing) is SPOOLING. Data to be output is held on a spool queue on backing store until the output device is ready for it.
Output removed
from queue
UserProgram Output
Queue
Printer(Output)
Output added to queue
Operating Systems 23
BACKING STORE MANAGEMENT
The OS has the responsibility of how programs and data are stored in secondary memory and ensure that this is being done efficiently.
Data and programs in backing store are kept in FILES. The OS must take care of the creation, deletion and updating of these files.
Some files are shared; others are private. The OS has the responsibility of ensuring that users respect these ACCESS PRIVELEGES.
Note that this layer of the OS co-operates with memory management during data transfer to/from backing store.
Operating Systems 24
RESOURCE ALLOCATION AND SCHEDULING
Resources (say, processor, shared files, discs, printers) are usually shared by a number of users. The demand for resources is usually greater than their availability. Thus some policy must be adopted as to which user is to be serviced – resource allocation.
A FIRST IN FIRST OUT (FIFO) policy is simplest but this could easily result in DEADLOCK. Deadlock is when two or more programs prevent each other from continuing because each claims a resource that is possessed by another. Various policies are enforced to prevent deadlock or to recover from it once it occurs.
Scheduling is mainly concerned with enforcing a policy whereby the processor is used efficiently. Its task is to allocate processor time to programs. The scheduling algorithm may be as simple as a round-robin which deals with each user equally in turn, or as complex as a scheme of priorities distinguishing between users and between tasks.
Operating Systems 25
PROTECTION
The OS should protect the system against errors and system malfunction and system abuse.
The OS should detect and diagnose errors in application programs as soon as possible and limit their effects.
The OS should also protect the software from system malfunction. This is achieved by a periodic dump of certain files into a suitable backup medium. Also power failure is immediately recognised and essential contents of CPU are saved on disk before the power has fallen to a level where the system has to be shut down. This would only take a few milliseconds.
Protection against abuse is more difficult to deal with. Protection mechanisms designed to prevent unauthorised activities from succeeding are not always completely foolproof.
Operating Systems 26
ACCOUNTING
An operating system must keep record of the changes incurred by each user program such as processor time, use of backing store, and printer paper.
Information is passed to the accounting module from the scheduler, to establish how much processor time a program has used.
Most multi-user OS‟s take note of the number of times a user logs on to/off from a system. Some OS s keep track of all actions of a user, by logging all his commands to a file.
Operating Systems 27
COMMUNICATION WITH THE OPERATING SYSTEM
Human communication with the operating system may be of two types:
User mode of operation - between computer and user
Users communicate with the OS in order to run application programs (execute programs) and manage their data files (perform housekeeping tasks).
Supervisor mode of operation -between computer and operator
In supervisor mode, the computer system operator is in ultimate control of the system and may override many functions of the OS such as switching processor between processes, accessing registers used by memory protection hardware, reorganising scheduling and resource allocation.
Operating Systems 28
TYPES OF USER INTERFACE
Different types of user interface used by different operating systems.
User interfaces may be: Command line interface
(CLI)
Job-Control Language
Graphical User Interface (GUI)
C:\> dir *.exe
GUI
CLI
Operating Systems 29
COMMAND LINE INTERFACE (CLI)
An interactive terminal allows the system to prompt and the user to type a command to initiate program execution or housekeeping tasks
e.g. C:\tp\user1>copy myprog1.pas a:
The user interface module contains a command-line interface (CLI) which performs the actual task of identifying and executing the command.
Operating Systems 30
GRAPHICAL USER INTERFACE (GUI)
Using a GUI, the user is presented with pictorial representations (ICONS) of the different tasks. The user uses the GUI in conjunction with a mouse. Hence initialising a task involves clicking the mouse on the required task icon.
The environment is said to be of the WIMP (Window, Icon, Mouse, Pointer) type.
The main advantages of GUI are:
ease of use
user oriented.
The main disadvantages of GUI are:
excessive use of main and secondary storage
slower in executing commands because of much required interpretation
(require a powerful processor and better graphics display)
Operating Systems 31
JOB-CONTROL LANGUAGE
In this type of environment, the user has no direct interaction with the computer system. The user prepares a series of instructions off-line using a JCL to describe to the system the requirements of his/her task.
When the user‟s job is eventually executed, the execution is guided by the JCL-prepared description. The results are then made available at a later time via some off-line medium say line printer paper.
A job control language is more complex and powerful than a command language. As from the example above, it is used to write the job description i.e. all job control information.
$JOB 123$PRIORITY 2$COBOL$INPUT PROG1 (DISK 1)$LIST LP$IF ERROR THEN END$RUN$MEMORY 250K$TIME 5$FILES „PAYFILE‟$IF ERROR THEN DUMP$END
E.g. JCL program to compile and execute a COBOL program :
Operating Systems 32
MULTI-PROCESSING
A program is a sequential set of commands which are executed in order by a processor.
The execution of a program on a processor is called a process. Thus if the same program is run twice on the same processor, it will be one program but two different processes.
When a machine can have more then one process running at the same time, the system is called a multiprocessing system.
A system can have more than one processor, but the number of processes running on a machine is generally greater then the number of processors.
Operating Systems 33
APPLICATION EXAMPLE
Consider an application program running on a system with one processor, one disk and one printer. Part of the program‟s task involves reading some data from disk, performing some computation on the data, saving the results and printing the result.
Request datafrom disk
Saves resultsto disk
PerformsComputation
PrintsResults
ProgramEnds
OS Routine
Program
Printer
Disk
t
Operating Systems 34
CONCURRENCY
With reference to the example (on previous slide), a lot of time is wasted when neither the OS nor the program are executing and the processor is free to perform other tasks.
This time can be fruitfully used thanks to concurrency where several activities can exist in parallel.
Concurrency raises problems of: Switching from one activity to another.
Protecting one activity from the effects of another.
Synchronizing activities which are mutually dependent.
Control over shared resources.
Communication between two activities.
Operating Systems 35
CPU SHARING IN CONCURRENT SYSTEMS
Here several processes share the same CPU and other common resources.
Process P1
Process P2
Process P3
Process 1 is said to be preempted
Process 3 is said to be dispatchedContext Switching
Processortime
Operating Systems 36
PROCESS STATES
A process can be in one of three states: RUNNING (or EXECUTING),
RUNNABLE (or READY),
UNRUNNABLE (or BLOCKED)
READY EXECUTING
BLOCKED
dispatched
preempted
WAITresource busy
SIGNALresource free
Activation Termination
Suspended Suspended
Operating Systems 37
SCHEDULING
Scheduling involves the timing of when to introduce new processes into the system ( Activation ) and the order in which processes should run or be stopped ( dispatching and preemption ).
Executionon CPU
P3 P2 P1...
Activation dispatching
preemption
TerminationReady Queue
P1 P2 P3 P4
Scheduler
Operating Systems 38
TYPES OF SCHEDULING
There are various types of scheduling :
Preemptive: The running process can be interrupted at any time to assign the processor to another process
Non-Preemptive: A process, once started, can continue running until its end.
Static: scheduling is decided on fixed parameters before the scheduling of a process occurs.
Dynamic: Scheduling decisions are based on dynamic parameters and can be changed during program execution.
Real Time: There are other scheduling techniques used for real time operating systems in which the most important factor effecting the scheduling is the time constraint.
Operating Systems 39
CRITICAL REGIONS
When a process tries to access a shared resource, which must be used in mutual exclusion, the process is said to execute a critical region (CR).
For example suppose that Process P1 and Process P2 need to use the same (shared) memory location at some time during their execution.
If a process tries to access a resource which is already occupied by some other preempted process, the scheduler blocks that process and sends some other process in execution until the shared resource is free. Thus a process stopped on a shared resource is said to be blocked.
P1 P2
CR
CR
Operating Systems 40
SEMAPHORES
A hardware or software flag. In multitasking systems, a semaphore is a variable with a value that indicates the status of a common resource. It's used to lock the resource that is being used.
A process needing the resource checks the semaphore to determine the resource's status and then decides how to proceed.
For implementation reasons the lock (WAIT) and unlock (SIGNAL) must be atomic.
There are various types of semaphores –binary, readers/writers … etc.
Operating Systems 41
MUTUAL EXCLUSION
Non-shareable resources, whether peripherals, files, or data in memory, can be protected from simultaneous access by several processes by preventing the processes from concurrently executing the pieces of program through which access is made.
Exclusion can be achieved by the simple expedient of enclosing each critical section by wait and signal operations on a single semaphore whose initial value is 1. Thus each critical section is programmed as
where mutex is the name of a semaphore.
wait (mutex);
critical section
signal(mutex);
Operating Systems 42
PROCESS STATE CONTROL
Thus a process moves in one of the indicated directions:
Partially completed processes (preempted)
New Processes C.P.U.
Job queue
Process dispatched
Semaphore Queues
wait
signal
READY
RunningRunnable
Blocked
Termination
(Activation)
Operating Systems 43
PROCESSOR SCHEDULING ALGORITHMS
Given a set of processes ( or tasks ) = { P1, P2, P3 …Pn}, a scheduling algorithm involves a plan for assigning the CPU to each process. Among the most popular scheduling algorithms which exist are:
First Come First Served (FCFS)
Shortest Job First (SJF)
Priority Scheduling
Round Robin (RR)
Multilevel Scheduling
Operating Systems 44
FIRST COME FIRST SERVED
Simplest algorithm implemented by keeping a simple FIFO queue, with new processes inserted at the tail of the queue.
Characteristics of this algorithm:
Non Preemptive.
Used mainly for batch non-interactive processes.
Not used in modern operating system since it offers no real concurrent processing.
TerminationCPU
Activation Dispatch
FCFS Queue
P1P2P3
Operating Systems 45
EXAMPLE FCFS
Suppose we have 3 processes to be scheduled
Process P1
Process P3
Processortime
Process Activation time Execution time
P1 3 4
P2 0 5
P3 2 2
Process P2
1 2 3 4 5 6 7 8 9 10 110
Operating Systems 46
ROUND ROBIN
This is particularly suitable for timesharing systems
Each process is allowed execution for a certain quantum of time Q,
Q must be accurately chosen, in such a way that it is not too small to be close to the process commutation time, and not to large to leave processes not dispatched for a long time.
TerminationCPUActivation Dispatch
P2P1P3
Preemptive after a time quantum Q
Operating Systems 47
ROUND-ROBIN
Suppose we have 3 processes to be scheduled
Process P1
Process P3
Processortime
Process Activation time Execution time
P1 2 4
P2 0 5
P3 4 2
Process P2
1 2 3 4 5 6 7 8 9 10 110
Operating Systems 48
PRIORITY SCHEDULING
Each process is assigned a priority and the process with the highest priority is dispatched first. Processes with the same priority are dispatched on a FCFS bases.
One problem in this type of scheduling is starvation, i.e. a process with a low priority can wait to be dispatched for an indefinite long time, due to higher priority processes.
One method to avoid starvation is by using aging in which the priority of a process is increased dynamically while waiting in the queue.
TerminationCPUActivation
P1P5P6
ActivationP2P4P7
P3P8P9
Activation
HigherPriority
FCFS Queues
Operating Systems 49
EXAMPLE PRIORITY SCHEDULING (NON-PREEMTIVE)
Suppose we have 3 processes to be scheduled
Process P1
Process P3
Processortime
Process Priority Activation time Execution time
P1 1 (highest) 2 4
P2 2 0 5
P3 3 (lowest) 4 2
Process P2
1 2 3 4 5 6 7 8 9 10 110
Operating Systems 50
EXAMPLE PRIORITY SCHEDULING (PREEMTIVE)
Suppose we have 3 processes to be scheduled
Process P1
Process P3
Processortime
Process Priority Activation time Execution time
P1 1 (highest) 2 4
P2 2 0 5
P3 3 (lowest) 4 2
Process P2
1 2 3 4 5 6 7 8 9 10 110
Operating Systems 51
RELOCATION
The translator does not know where the program will be placed in memory when it is executed
Furthermore, a process may be swapped in and out of memory, so it will occupy different physical locations at different times.
Consequently, the translator cannot assign physical addresses to the instructions and data - it must assign logical (or virtual) addresses.
On the other hand, once programs are loaded, the processor and OS must be able to reference the actual physical addresses at which the code and data are stored.
Relocation is the process of converting a logical address to a physical address. Its purpose is to let a program be executed from different areas of main memory at different times.
Operating Systems 52
ADDRESS TYPES
A physical address or absolute address refers to a physical location in main memory.
A logical address is a reference to a memory location independent of the physical structure or organization of memory.
Compilers produce code in which all memory references are expressed as logical addresses.
A relative address is a kind of logical address in which the address is expressed relative to some known point in the program. Usually, the first location is address zero and all other addresses are offsets from this address.
PROCESS07000
00000
03000a
r
b
Operating Systems 53
ADDRESS TRANSLATION
Programs are loaded in main memory with all memory references in relative form
Physical addresses are calculated “on the fly” as the instructions are executed. This process is called address translation, or address mapping.
For adequate performance, the translation from relative to physical address must by done by hardware.
ADDRESSTRANSLATION
LOGICALADDRESS
PHYSICALADDRESS
Operating Systems 54
BASE-LIMIT REGISTER TECHNIQUE
When a process is dispatched, a baseregister (in the CPU) is loaded with the physical start address of the process and a bound register is loaded with the process‟s ending physical address.
When a relative address is encountered, add it to the contents of the base register to get the actual physical address.
The physical address is then compared to the bound register to make sure the process isn‟t referencing a location outside its own address space.
The hardware mechanism provides translation and protection.
PROCESS 1
09000
03000
r
bound
PROCESS 2
base
Operating Systems 55
STRENGTHS AND WEAKNESSES OF BASE-LIMIT REGISTER TECHNIQUE
The base-and-limit register approach supports dynamic relocation, as well as protection and translation, since each time the process is dispatched the registers can be loaded with the appropriate values.
However, it works only if the process image is loaded into consecutive memory locations.
Bound
Base
Operating Systems 56
NON-CONTIGUOUS STORAGE
Relaxing the assumption that process address space will be stored contiguously will let the memory management system utilize memory better.
If portions of processes can be loaded in separate areas of memory, compaction will not be necessary.
Operating Systems 57
PHYSICAL ORGANIZATION
Primary memory is fast and expensive.
Secondary memory is slower and cheaper.
Consequently, computer systems usually have small amounts of main memory and large amounts of disk storage.
The OS must be responsible for moving information between the two levels.
This is a vital part of memory management.
DISKMAIN
MEMORY
SWAP OUT
SWAP IN
Operating Systems 58
PAGING
Paging assumes that memory is divided into fixed-size chunks, called page frames.
Process address space is divided into chunks called pages.
Pages are the same size as frames, so a page can fit into any free space of memory.
Each address is composed of 2 parts, a page number and an offset. Page numbers are concatenated with offset to form the complete address.
The term virtual ( paged ) memory is used to describe this system.
Operating Systems 59
EXAMPLE OF PROCESS LOADING
Processes A, B, and C are loaded into memory in order, and assuming that the memory is originally empty.
Operating Systems 60
EXAMPLE … CONTINUED
Now, when B finishes or is swapped out a new process (D) can be loaded.
D needs 5 pages; it would not fit into either of the available free chunks, but with paging, we can accommodate it.
Operating Systems 61
VIRTUAL AND REAL ADDRESSES
The actual address in memory ( the actual bit pattern going in the memory chip ) is called the real address and the program address (the one specified by the program) is called the virtual address
A hardware mechanism is used to translate the virtual page number to a real page number.
This mechanism operates only on the pages in main memory.
If the required page is not in main memory a software program must be executed to:
o Find the required page in secondary memory,
o Transfer this page into the main memory,
o Provide space in main memory by choosing the best out block.
Operating Systems 62
PAGED ADDRESS TRANSLATION
(Notice that only thepage# field changes)
Operating Systems 63
PAGE SIZE CONSIDERATIONS
Page size is typically 512 words.
If a smaller page is chosen
o Time taken to transfer pages from main to secondary storage is shorter
o A large selection of pages resides in main memory
o However it necessitates a large page table.
For Larger pages:
o Time taken is longer.
o A small page table is needed
o The unused space at the end of each page is likely to increase (This is known as internal fragmentation )
The number of words per page chosen is a compromise.
Operating Systems 64
PAGING & ADDRESS TRANSLATION REMARKS
Address translation is transparent to the user.
The OS is responsible for finding enough free frames for a process and for creating and initializing the page table.
Protection is provided by the page table. If the referenced page isn‟t part of the process address space, there won‟t be a PT entry.
Operating Systems 65
FILES
Disk (and tape) provide permanent storage, as opposed to the volatile storage in main memory.
Files are an abstract data type, used to structure data stored on a disk. Virtually all applications use files for input and output data
In addition, files hold source code, executables, documents, ….
Operating Systems 66
THE FILE MANAGEMENT SYSTEM
The file management system provides support to help users and applications create, delete, and use files.
Objectives:
Provide capability to create and access files.
Protect validity of data, as much as possible.
Optimize performance: throughput and response time.
Interact with multiple users and devices.
Provide device independent interface.
Operating Systems 67
FILE SYSTEM ARCHITECTURE
File systems extend/expand the layers in the I/O stack
At the bottom are the device drivers
The top level provides the access methods, or the interface between user and file system.
Intermediate levels:
o maintain directory,
o map logical file operations into physical addresses,
o allocate disk storage,
o provide access control,
o manage physical I/O.
Operating Systems 68
FILE MANAGEMENT FUNCTIONS
User issues command (read, open, etc.) and the file system must:
Use a directory which describes the location of all files plus their attributes
On a shared system enforce user access controls
Translate user commands into lower level commands, based on access method
Users access files on a byte or record basis; I/O is done on a block basis
Operating Systems 69
FILE BLOCKING FUNCTIONS
Blocking includes
Allocation of files to free blocks on disk
Management of free storage lists
scheduling block I/O requests
Thus files must be divided into blocks
Blocks are the unit of storage both on disk and in main-memory buffers
Operating Systems 70
FILE DIRECTORIES
Directories provide a mapping between file names and the actual files.
They contain lists of files and their attributes. name
location (address)
ownership
Directories are just special files, owned by the OS.
The structure of the directory must support at least the following set of operations:
search (to locate a file)
create
delete
list (all or part of the directory)
When a file is opened, directory information is usually copied from disk into a main memory open-file table.
Operating Systems 71
DIRECTORY STRUCTURE
Single-level: a list of all files slow to search
requires names to be unique across the entire system
useful only when there are few files
Two-level directory level two: personal directory for each user
level one: master directory for entire system
names unique only within the user directory
Tree-structured directory One-level and two-level directories don‟t give the user any way to structure
files.
Tree structured directories allow multiple hierarchical subdirectories in each user directory (see Windows and UNIX)
File names are unique only within a subdirectory
Pathnames are used to locate files; as in any tree structure, search is fairly efficient
Operating Systems 72
FILE SHARING
Most file systems allow users to share files, if the owner of the file agrees
File sharing introduces two issues:
determining access rights: who, besides the owner, can modify, execute, delete, etc.
managing simultaneous access: what if more than one user is trying to access a file at the same time?
Operating Systems 73
ACCESS CONTROL
Most common access rights are
read: user can read and use the file, but can‟t change it
write: user can modify, delete or add to the file
execute:user can load and run the program, cannot change or copy it
Other access rights include:
None
Knowledge
Append
Change protections
Delete
Access can be granted to different classes of users:
individuals
groups (a set of users, such as class members)
all (includes everybody with access to the system - e.g., public files)
Operating Systems 74
ACCESS CONTROLS – PRIVILEGES
A File Management System helps prevent loss, corruption and unauthorized access to files.
The operating system is used to identify and authenticate users and their processes.
The file access is authenticated through id‟s and passwords.
Example:
UNIX defines three access control types:
o Read
o Write
o Execute
Operating Systems 75
FILE SYSTEM RELIABILITY
For efficiency, many file system structures (or parts of the structures) are cached in memory.
directory info, disk allocation table, etc.
If the file system updates one of these tables but does not save the change to disk, the most current information will be lost in a crash.
Fault Tolerance
Describes methods of securing file content against hardware failure.
File backup, recovery, and transaction logging are forms or protection against disk failure.
Operating Systems 76
FILE BACKUP
Storing files/directories to different storage device for safekeeping purposes
Protects against data loss, device failure, sabotage, etc.
Can be automatic or manual
Types of File Backup
Full Backup:
o the FMS copies all files and directories for an entire storage volume.
Incremental Backup:
o only files that have been modified are archived.
Differential Backup:
o only the changed portions of the files are archived.
Operating Systems 77
TRANSACTION LOGGING
A form of automated file backup.
A transaction is any single change to file contents or attributes.
All changes are logged (when, by whom, etc.).
Transaction logging provides a high degree of protection against data loss due to program or hardware failure.
Lost updates can be recovered from log files.
Imposes performance penalty (every change requires two writes - one to file, the other to the log).
Operating Systems 78
FILE RECOVERY
The file management system maintains backup logs to aid in locating backup copies of lost or damages files.
The recovery utility reconstructs as much of the directory and storage allocation data structures as possible and makes a consistency check.
Operating Systems 79
MIRRORING
A fault tolerance technique in which all disk write operations are made simultaneously or concurrently to two different storage devices.
Disk mirroring provides a high degree of protection against data loss with no performance penalty if implemented in hardware.