OPERATING SYSTEMS
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
ObjectivesTo provide a grand tour of the major
operating systems componentsTo provide coverage of basic computer
system organization
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
What is an Operating System?
A program that acts as an intermediary between a user of a computer and the computer hardware.
Operating system goals:Use the computer hardware in an efficient
manner.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Computer System StructureComputer system can be divided into
four componentsHardware Operating systemApplication programs Users
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System DefinitionOS is a resource allocatorOS is a control program
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Computer Startupbootstrap program is loaded at power-up or
rebootTypically stored in ROM or EPROM, generally
known as firmwareInitializates all aspects of systemLoads operating system kernel and starts
execution
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Computer System Organization
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Migration of Integer A from Disk to Register
Multitasking environments must be careful to use most recent value, no matter where it is stored in the storage hierarchy
Multiprocessor environment must provide cache coherency in hardware such that all CPUs have the most recent value in their cache
Distributed environment situation even more complexSeveral copies of a datum can existVarious solutions covered in Chapter 17
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Structure Multiprogramming needed for efficiency
Single user cannot keep CPU and I/O devices busy at all times Multiprogramming organizes jobs (code and data) so CPU
always has one to execute A subset of total jobs in system is kept in memory One job selected and run via job scheduling When it has to wait (for I/O for example), OS switches to
another job Timesharing (multitasking) is logical extension in which CPU
switches jobs so frequently that users can interact with each job while it is running, creating interactive computing Response time should be < 1 second Each user has at least one program executing in memory
process If several jobs ready to run at the same time CPU
scheduling If processes don’t fit in memory, swapping moves them in and
out to run Virtual memory allows execution of processes not completely
in memory
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating-System OperationsInterrupt driven by hardwareSoftware error or request creates exception or trap
Division by zero, request for operating system serviceOther process problems include infinite loop,
processes modifying each other or the operating system
Dual-mode operation allows OS to protect itself and other system componentsUser mode and kernel mode Mode bit provided by hardware
Provides ability to distinguish when system is running user code or kernel code
Some instructions designated as privileged, only executable in kernel mode
System call changes mode to kernel, return from call resets it to user
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Transition from User to Kernel ModeTimer to prevent infinite loop / process
hogging resourcesSet interrupt after specific periodOperating system decrements counterWhen counter zero generate an interruptSet up before scheduling process to regain
control or terminate program that exceeds allotted time
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process ManagementA process is a program in execution. It is a unit of work within
the system. Program is a passive entity, process is an active entity.
Process needs resources to accomplish its taskCPU, memory, I/O, files Initialization data
Process termination requires reclaim of any reusable resourcesSingle-threaded process has one program counter specifying
location of next instruction to executeProcess executes instructions sequentially, one at a time,
until completionMulti-threaded process has one program counter per threadTypically system has many processes, some user, some
operating system running concurrently on one or more CPUsConcurrency by multiplexing the CPUs among the processes
/ threads
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process Management ActivitiesThe operating system is responsible for the following
activities in connection with process management:Creating and deleting both user and system
processesSuspending and resuming processesProviding mechanisms for process synchronizationProviding mechanisms for process communicationProviding mechanisms for deadlock handling
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Memory ManagementAll data in memory before and after processingAll instructions in memory in order to executeMemory management determines what is in memory
whenOptimizing CPU utilization and computer response to
usersMemory management activities
Keeping track of which parts of memory are currently being used and by whom
Deciding which processes (or parts thereof) and data to move into and out of memory
Allocating and deallocating memory space as needed
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Memory ManagementSingle Contiguous Memory AllocationFixed Partition Memory AllocationVariable Partition Memory AllocationRelocatable Partition Memory AllocationSimple Paged Allocation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Storage ManagementOS provides uniform, logical view of information
storageAbstracts physical properties to logical storage unit -
fileEach medium is controlled by device (i.e., disk drive,
tape drive) Varying properties include access speed, capacity, data-
transfer rate, access method (sequential or random)File-System management
Files usually organized into directoriesAccess control on most systems to determine who can
access whatOS activities include
Creating and deleting files and directories Primitives to manipulate files and dirs Mapping files onto secondary storage Backup files onto stable (non-volatile) storage media
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Protection and SecurityProtection – any mechanism for controlling access of
processes or users to resources defined by the OSSecurity – defense of the system against internal and
external attacksHuge range, including denial-of-service, worms, viruses,
identity theft, theft of serviceSystems generally first distinguish among users, to
determine who can do whatUser identities (user IDs, security IDs) include name
and associated number, one per userUser ID then associated with all files, processes of that
user to determine access controlGroup identifier (group ID) allows set of users to be
defined and controls managed, then also associated with each process, file
Privilege escalation allows user to change to effective ID with more rights
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Computing Environments Traditional computer
Blurring over time Office environment
PCs connected to a network, terminals attached to mainframe or minicomputers providing batch and timesharing
Now portals allowing networked and remote systems access to same resources
Home networks Used to be single system, then modems Now firewalled, networked
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Client-Server Computing Dumb terminals supplanted by smart PCs Many systems now servers, responding to requests generated by
clients Compute-server provides an interface to client to request
services (i.e. database) File-server provides interface for clients to store and retrieve
files
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Peer-to-Peer ComputingAnother model of distributed systemP2P does not distinguish clients and servers
Instead all nodes are considered peersMay each act as client, server or bothNode must join P2P network
Registers its service with central lookup service on network, or
Broadcast request for service and respond to requests for service via discovery protocol
Examples include Napster and Gnutella
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Several jobs are kept in main memory at the same time, and the CPU is multiplexed among them.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
OS Features Needed for Multiprogramming
I/O routine supplied by the system.Memory management – the system
must allocate the memory to several jobs.
CPU scheduling – the system must choose among several jobs ready to run.
Allocation of devices.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Distributed SystemsDistribute the computation among several
physical processors.Loosely coupled system – each processor has
its own local memory; processors communicate with one another through various communications lines, such as high-speed buses or telephone lines.
Advantages of distributed systems.Resources Sharing Computation speed up – load sharing ReliabilityCommunications
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Time-Sharing Systems–Interactive Computing
The CPU is multiplexed among several jobs that are kept in memory and on disk (the CPU is allocated to a job only if the job is in memory).
A job swapped in and out of memory to the disk.
On-line communication between the user and the system is provided; when the operating system finishes the execution of one command, it seeks the next “control statement” from the user’s keyboard.
On-line system must be available for users to access data and code.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Real-Time SystemsOften used as a control device in a
dedicated application such as controlling scientific experiments, medical imaging systems, industrial control systems, and some display systems.
Well-defined fixed-time constraints.Real-Time systems may be either hard
or soft real-time.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Real-Time Systems (Cont.)Hard real-time:
Secondary storage limited or absent, data stored in short term memory, or read-only memory (ROM)
Conflicts with time-sharing systems, not supported by general-purpose operating systems.
Soft real-timeLimited utility in industrial control of roboticsUseful in applications (multimedia, virtual
reality) requiring advanced operating-system features.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
ProcessesProcess ConceptProcess SchedulingOperations on ProcessesCooperating ProcessesInterprocess CommunicationCommunication in Client-Server
Systems
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process ConceptAn operating system executes a variety of
programs:Batch system – jobsTime-shared systems – user programs or
tasksProcess – a program in execution; process execution must progress in
sequential fashion.A process includes:
program counter stackdata section
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process StateAs a process executes, it changes state
new: The process is being created.running: Instructions are being executed.waiting: The process is waiting for some
event to occur.ready: The process is waiting to be assigned
to a process.terminated: The process has finished
execution.
Process Creation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process Termination
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process Termination
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
ProcessesNot-running
ready to executeBlocked
waiting for I/ODispatcher cannot just select the process that
has been in the queue the longest because it may be blocked
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
A Five-State ModelRunningReadyBlockedNewExit
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Suspended ProcessesProcessor is faster than I/O so all processes
could be waiting for I/OSwap these processes to disk to free up more
memoryBlocked state becomes suspend state when
swapped to diskTwo new states
Blocked/SuspendReadySuspend
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
One Suspend State
Case study -Two Suspend StateOperating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Two Suspend States
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process Control Block (PCB)Information associated with each
process.Process stateProgram counterCPU registersCPU scheduling informationMemory-management informationAccounting informationI/O status information
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process Scheduling QueuesJob queue – set of all processes in the system.Ready queue – set of all processes residing in
main memory, ready and waiting to execute.Device queues – set of processes waiting for an
I/O device.Process migration between the various queues.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Implementation QuestionsHow are links established?Can a link be associated with more than two
processes?How many links can there be between every
pair of communicating processes?What is the capacity of a link?Is the size of a message that the link can
accommodate fixed or variable?Is a link unidirectional or bi-directional?
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Direct CommunicationProcesses must name each other explicitly:
send (P, message) – send a message to process Preceive(Q, message) – receive a message from
process QProperties of communication link
Links are established automatically.A link is associated with exactly one pair of
communicating processes.Between each pair there exists exactly one link.The link may be unidirectional, but is usually bi-
directional.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Indirect CommunicationMessages are directed and received from
mailboxes (also referred to as ports).Each mailbox has a unique id.Processes can communicate only if they
share a mailbox.Properties of communication link
Link established only if processes share a common mailbox
A link may be associated with many processes.
Each pair of processes may share several communication links.
Link may be unidirectional or bi-directional.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Indirect CommunicationOperations
create a new mailboxsend and receive messages through mailboxdestroy a mailbox
Primitives are defined as:send(A, message) – send a message to mailbox Areceive(A, message) – receive a message from mailbox A
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Indirect CommunicationMailbox sharing
P1, P2, and P3 share mailbox A.P1, sends; P2 and P3 receive.Who gets the message?
SolutionsAllow a link to be associated with at most two
processes.Allow only one process at a time to execute a
receive operation.Allow the system to select arbitrarily the receiver.
Sender is notified who the receiver was.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
CPU SchedulingBasic ConceptsScheduling Criteria Scheduling AlgorithmsMultiple-Processor SchedulingReal-Time SchedulingAlgorithm Evaluation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Basic ConceptsMaximum CPU utilization obtained with
multiprogrammingCPU–I/O Burst Cycle – Process execution
consists of a cycle of CPU execution and I/O wait.
CPU burst distribution
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
CPU SchedulerSelects from among the processes in memory that
are ready to execute, and allocates the CPU to one of them.
CPU scheduling decisions may take place when a process:1. Switches from running to waiting state.2. Switches from running to ready state.3. Switches from waiting to ready.4. Terminates.
Scheduling under 1 and 4 is nonpreemptive.All other scheduling is preemptive.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
DispatcherDispatcher module gives control of the CPU
to the process selected by the short-term scheduler; this involves:switching contextswitching to user modejumping to the proper location in the user
program to restart that programDispatch latency – time it takes for the
dispatcher to stop one process and start another running.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Scheduling CriteriaCPU utilization – keep the CPU as busy as
possibleThroughput – # of processes that
complete their execution per time unitTurnaround time – amount of time to
execute a particular processWaiting time – amount of time a process
has been waiting in the ready queueResponse time – amount of time it takes
from when a request was submitted until the first response is produced, not output (for time-sharing environment)
Optimization Criteria
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Optimization CriteriaMax CPU utilizationMax throughputMin turnaround time Min waiting time Min response time
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
First-Come , First-Served (FCFS) SchedulingProcess Burst TimeP1 24 P2 3 P3 3
Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is:
Waiting time for P1 = 0; P2 = 24; P3 = 27Average waiting time: (0 + 24 + 27)/3 = 17
P1 P2 P3
24 27 300
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
FCFS Scheduling (Cont.)Suppose that the processes arrive in the order
P2 , P3 , P1 .The Gantt chart for the schedule is:
Waiting time for P1 = 6; P2 = 0; P3 = 3Average waiting time: (6 + 0 + 3)/3 = 3Much better than previous case.Convoy effect short process behind long process
P1P3P2
63 300
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Shortest-Job-First (SJR) SchedulingAssociate with each process the length of its next
CPU burst. Use these lengths to schedule the process with the shortest time.
Two schemes: nonpreemptive – once CPU given to the process it
cannot be preempted until completes its CPU burst.preemptive – if a new process arrives with CPU burst
length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF).
SJF is optimal – gives minimum average waiting time for a given set of processes.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Process Arrival Time Burst TimeP1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
SJF (non-preemptive)
Average waiting time = (0 + 6 + 3 + 7)/4 - 4
Example of Non-Preemptive SJF
P1 P3 P2
73 160
P4
8 12
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Example of Preemptive SJFProcess Arrival Time Burst Time
P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4
SJF (preemptive)
Average waiting time = (9 + 1 + 0 +2)/4 - 3
P1 P3P2
42 110
P4
5 7
P2 P1
16
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Determining Length of Next CPU BurstCan only estimate the length.Can be done by using the length of previous
CPU bursts, using exponential averaging.
:Define 4.10 , 3.
burst CPU next the for value predicted 2.burst CPU of lenght actual 1.
1n
thn nt
.t nnn 11
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Priority SchedulingA priority number (integer) is associated with each
processThe CPU is allocated to the process with the highest
priority (smallest integer highest priority).Preemptivenonpreemptive
SJF is a priority scheduling where priority is the predicted next CPU burst time.
Problem Starvation – low priority processes may never execute.
Solution Aging – as time progresses increase the priority of the process.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Round Robin (RR)Each process gets a small unit of CPU time (time
quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
Performanceq large FIFOq small q must be large with respect to context
switch, otherwise overhead is too high.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Example of RR with Time Quantum = 20Process Burst Time
P1 53 P2 17 P3 68 P4 24
The Gantt chart is:
Typically, higher average turnaround than SJF, but better response.
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Traditional UNIX SchedulingMultilevel feedback using round robin within
each of the priority queuesIf a running process does not block or
complete within 1 second, it is preemptedPriorities are recomputed once per secondBase priority divides all processes into fixed
bands of priority levels
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Memory ManagementBackgroundSwapping Contiguous Memory AllocationPagingStructure of the Page TableSegmentationExample: The Intel Pentium
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
ObjectivesTo provide a detailed description of
various ways of organizing memory hardware
To discuss various memory-management techniques, including paging and segmentation
To provide a detailed description of the Intel Pentium, which supports both pure segmentation and segmentation with paging
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
BackgroundProgram must be brought (from disk) into
memory and placed within a process for it to be run
Main memory and registers are only storage CPU can access directly
Register access in one CPU clock (or less)Main memory can take many cyclesCache sits between main memory and
CPU registersProtection of memory required to ensure
correct operation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Base and Limit RegistersA pair of base and limit registers define
the logical address space
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Binding of Instructions and Data to MemoryAddress binding of instructions and data to
memory addresses can happen at three different stagesCompile time: If memory location known a
priori, absolute code can be generated; must recompile code if starting location changes
Load time: Must generate relocatable code if memory location is not known at compile time
Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers)
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Logical vs. Physical Address SpaceThe concept of a logical address space that is
bound to a separate physical address space is central to proper memory managementLogical address – generated by the CPU; also
referred to as virtual addressPhysical address – address seen by the
memory unitLogical and physical addresses are the same
in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Memory-Management Unit (MMU)Hardware device that maps virtual to
physical address
In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory
The user program deals with logical addresses; it never sees the real physical addresses
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Dynamic LoadingRoutine is not loaded until it is calledBetter memory-space utilization; unused
routine is never loadedUseful when large amounts of code are
needed to handle infrequently occurring cases
No special support from the operating system is required implemented through program design
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Dynamic LinkingLinking postponed until execution timeSmall piece of code, stub, used to locate
the appropriate memory-resident library routine
Stub replaces itself with the address of the routine, and executes the routine
Operating system needed to check if routine is in processes’ memory address
Dynamic linking is particularly useful for libraries
System also known as shared libraries
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
SwappingA process can be swapped temporarily out of memory to a backing
store, and then brought back into memory for continued execution
Backing store – fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images
Roll out, roll in – swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed
Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped
Modified versions of swapping are found on many systems (i.e., UNIX, Linux, and Windows)
System maintains a ready queue of ready-to-run processes which have memory images on disk
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Schematic View of Swapping
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Contiguous Allocation (Cont.)Multiple-partition allocation
Hole – block of available memory; holes of various size are scattered throughout memory
When a process arrives, it is allocated memory from a hole large enough to accommodate it
Operating system maintains information about:a) allocated partitions b) free partitions (hole)
OS
process 5
process 8
process 2
OS
process 5
process 2
OS
process 5
process 2
OS
process 5
process 9
process 2
process 9
process 10
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Dynamic Storage-Allocation ProblemFirst-fit: Allocate the first hole that is big
enoughBest-fit: Allocate the smallest hole that is big
enough; must search entire list, unless ordered by size Produces the smallest leftover hole
Worst-fit: Allocate the largest hole; must also search entire list Produces the largest leftover hole
How to satisfy a request of size n from a list of free holes
First-fit and best-fit better than worst-fit in terms of speed and storage utilization
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
PagingLogical address space of a process can be
noncontiguous; process is allocated physical memory whenever the latter is available
Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8,192 bytes)
Divide logical memory into blocks of same size called pages
Keep track of all free framesTo run a program of size n pages, need to find n
free frames and load programSet up a page table to translate logical to
physical addresses Internal fragmentation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Address Translation Scheme Address generated by CPU is divided into:
Page number (p) – used as an index into a page table which contains base address of each page in physical memory
Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit
For given logical address space 2m and page size 2n
page number page offset
p d
m - n n
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
32-byte memory and 4-byte pagesOperating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Before allocation After allocation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Implementation of Page TablePage table is kept in main memoryPage-table base register (PTBR) points to
the page tablePage-table length register (PRLR) indicates
size of the page table In this scheme every data/instruction access
requires two memory accesses. One for the page table and one for the data/instruction.
The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs)
Some TLBs store address-space identifiers (ASIDs) in each TLB entry – uniquely identifies each process to provide address-space protection for that process
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Associative MemoryAssociative memory – parallel search
Address translation (p, d)If p is in associative register, get frame # outOtherwise get frame # from page table in
memory
Page # Frame #
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Effective Access TimeAssociative Lookup = time unitAssume memory cycle time is 1 microsecondHit ratio – percentage of times that a page
number is found in the associative registers; ratio related to number of associative registers
Hit ratio = Effective Access Time (EAT)
EAT = (1 + ) + (2 + )(1 – )= 2 + –
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
CASE STUDY-UNIX and Solaris Memory Management
UNIX and Solaris Memory ManagementPage Replacement
Refinement of the clock policy
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Memory ProtectionMemory protection implemented by
associating protection bit with each frame
Valid-invalid bit attached to each entry in the page table:“valid” indicates that the associated
page is in the process’ logical address space, and is thus a legal page
“invalid” indicates that the page is not in the process’ logical address space
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Shared PagesShared code
One copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems).
Shared code must appear in same location in the logical address space of all processes
Private code and data Each process keeps a separate copy of the
code and dataThe pages for the private code and data can
appear anywhere in the logical address space
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
SegmentationMemory-management scheme that supports
user view of memory A program is a collection of segments. A
segment is a logical unit such as:main program,procedure, function,method,object,local variables, global variables,common block,stack,symbol table, arrays
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
1
3
2
4
1
4
2
3
user space physical memory space
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Segmentation Architecture Logical address consists of a two tuple:
<segment-number, offset>,Segment table – maps two-dimensional
physical addresses; each table entry has:base – contains the starting physical address
where the segments reside in memorylimit – specifies the length of the segment
Segment-table base register (STBR) points to the segment table’s location in memory
Segment-table length register (STLR) indicates number of segments used by a program; segment number s is legal if s < STLR
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Segmentation Architecture (Cont.)Protection
With each entry in segment table associate: validation bit = 0 illegal segment read/write/execute privileges
Protection bits associated with segments; code sharing occurs at segment level
Since segments vary in length, memory allocation is a dynamic storage-allocation problem
A segmentation example is shown in the following diagram
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Example: The Intel PentiumSupports both segmentation and
segmentation with pagingCPU generates logical address
Given to segmentation unit Which produces linear addresses
Linear address given to paging unit Which generates physical address in main memory Paging units form equivalent of MMU
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
BackgroundVirtual memory – separation of user logical
memory from physical memory.Only part of the program needs to be in memory for
execution.Logical address space can therefore be much larger
than physical address space.Allows address spaces to be shared by several
processes.Allows for more efficient process creation.
Virtual memory can be implemented via:Demand paging Demand segmentation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
BackgroundVirtual memory – separation of user logical
memory from physical memory.Only part of the program needs to be in memory for
execution.Logical address space can therefore be much larger
than physical address space.Allows address spaces to be shared by several
processes.Allows for more efficient process creation.
Virtual memory can be implemented via:Demand paging Demand segmentation
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Demand PagingBring a page into memory only when it is
neededLess I/O neededLess memory needed Faster responseMore users
Page is needed reference to itinvalid reference abortnot-in-memory bring to memory
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Performance of Demand PagingPage Fault Rate 0 p 1.0
if p = 0 no page faults if p = 1, every reference is a fault
Effective Access Time (EAT)EAT = (1 – p) x memory access+ p (page fault overhead+ [swap page out ]+ swap page in+ restart overhead)
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Copy-on-WriteCopy-on-Write (COW) allows both parent and child
processes to initially share the same pages in memory
If either process modifies a shared page, only then is the page copied
COW allows more efficient process creation as only modified pages are copied
Free pages are allocated from a pool of zeroed-out pages
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Page ReplacementPrevent over-allocation of memory by modifying
page-fault service routine to include page replacement
Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk
Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Basic Page Replacement1. Find the location of the desired page on disk
2. Find a free frame:- If there is a free frame, use it- If there is no free frame, use a page
replacement algorithm to select a victim frame
3. Read the desired page into the (newly) free frame. Update the page and frame tables.
4. Restart the process
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
NTFS(New Technology File SystemFeatures of NTFS
Security and access controlSize of the files/The number of FilesRecovery/ReliabilityLong file names
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
NTFS(New Technology File SystemOverview of the partition structureLimitations of NTFS
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Device ManagementI/O ChannelsI/O devices and the CPU can execute concurrently.Each device controller is in charge of a particular
device type.Each device controller has a local buffer.CPU moves data from/to main memory to/from
local buffersI/O is from the device to local buffer of controller.Device controller informs CPU that it has finished
its operation by causing an interrupt.Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Common Functions of Interrupts
Interrupt transfers control to the interrupt service routine generally, through the interrupt vector .
Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.
A trap is a software-generated interrupt caused either by an error or a user request.
An operating system is interrupt driven.Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Interrupt HandlingThe operating system preserves the state of
the CPU by storing registers and the program counter.
Determines which type of interrupt has occurred:pollingvectored interrupt system
Separate segments of code determine what action should be taken for each type of interrupt
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
I/O StructureAfter I/O starts, control returns to user
program only upon I/O completion.Wait instruction idles the CPU until the next
interruptWait loop (contention for memory access).At most one I/O request is outstanding at a
time, no simultaneous I/O processing.After I/O starts, control returns to user
program without waiting for I/O completion.System call – request to the operating system
to allow user to wait for I/O completion.Device-status table contains entry for each I/O
device indicating its type, address, and state.Operating system indexes into I/O device table
to determine device status and to modify table entry to include interrupt.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Synchronous Asynchronous
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Device ManagementUser Program
Run-time Library
Operating System
I/O Manager
Device Driver
Interface Hardware
e.g. printf(“hello”)
Identify device,check permissions
language I/O interface
System Call interface:… write stream of chars
Hardware interface:…write character… put bits on screen… write disk block
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Device SpeedsDevice Transfer Rate
(bytes per second)CPU Instructions per
byte transferred (*)
Keyboard 10
56K modem
Ethernet(Cable modem?
ADSL?)Disk Drive(CD ROM?) Screen(Printer?)
6.8 K
10 million
~15 thousand
1 M +(~63K)
10 M(few M)
100 (~1500)
~10(tens)
~210s M
(*) assume 100 MIPS.CPU speed: instructions/second (cf with clock speed: MHz) E.g.: Pentium 1GHz: up to 3000 MIPS, but, ...
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
I/O HardwareVariety of devices (WO, RO, RW)Communicate with the machine via a
connection point: port (e.g., serial port)
Devices within a computer are connected via a bus.
Controller: electronics that can operate a port, a bus, or a device.SCSI bus controller - host adapter circuit
board: processes SCSI protocol messages
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
An Input/Output interfaceMemory
CPU
Input Buffer
Output Buffer
Control
Status input ready
output ready
Bus
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Synchronising CPU and I/OPolling:
CPU loops waiting for I/O readysimple, reliableslow if many quiescent deviceswastes CPU timenot good for time-critical systems
Interrupts:CPU initiates I/O actionCPU does other stuffI/O interface signals ready by interrupting
CPUneeds hardware support
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Interrupt Actions (Bacon, figs 3.4, 3.5)
ProgramInterruptServiceRoutine
MemoryISR
Program VectorTable
CPU
PC
PSR
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Interrupt PrioritiesSome events:
routineurgent
should interrupt routine eventscritical
should interrupt urgent and routine events
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Priorities in action
Program Low PriorityISR
Medium Priority
ISR HighPriority
ISR
Program
High PriorityISR
Low PriorityISR
Issues:• how should we hold PC/PSR/etc?• low priority interrupts during
high priority ISR’s
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Assigning Interrupt PrioritiesHigh Priorities
What type of devices?
Lower PrioritiesWhat type of devices?
File System ManagementMS-DOS File SystemFile –Organization in MS-DOSData Access in MS-DOSnVolume Structure of the Disk in MS-DOSMS-DOS Booting ProcessUNIX File System
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
The UNIX Filesystem· The UNIX filesystem and directory
structure. · File and directory handling commands. · How to make symbolic and hard links. · How wildcard filename expansion works. · What argument quoting is and when it
should be used.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
The UNIX FilesystemUNIX filesystem belongs to one of four types:
Ordinary filesDirectoriesDevicesLinks
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Typical UNIX Directory Structure
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Specifying multiple filenames'?' matches any single character in that
position in the filename. '*' matches zero or more characters in the
filename('[' and ']') will match any filename that has
one of those characters in that position. A list of comma separated strings enclosed in
curly braces ("{" and "}") will be expanded as a Cartesian product with the surrounding characters.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
QuotesTry insert a '\' in front of the special
character. Use double quotes (") around arguments to
prevent most expansions. Use single forward quotes (') around
arguments to prevent all expansions.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Directory and File Handling Commands $ pwd
/usr/bin implies that /usr/bin is the current working directory.
ls (list directory) $ ls
bin dev home mnt share usr var boot etc lib proc sbin tmp vol
$ ls –a$ ls -a -l
(or, equivalently,) $ ls -al
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
File Premissions
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Basic Commands in UNIX$ man ls $ info ls $ cd path$ cd $ cd – $ mkdir directory $ rmdir directory $ cp source-file(s) destination $ cp -rd source-directories destination-directory
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Basic Commands in UNIX$ mv source destination$ rm target-file(s) $ rm -rf / home/will $ cat target-file(s) $ more target-file(s)
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Direct Memory Access StructureUsed for high-speed I/O devices able to
transmit information at close to memory speeds.
Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention.
Only one interrupt is generated per block, rather than the one interrupt per byte.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Storage StructureMain memory – only large storage media that the
CPU can access directly(RAM)-DRAM:LOAD &SORE.
Secondary storage – extension of main memory that provides large nonvolatile storage capacity.
Magnetic disks – rigid metal or glass platters covered with magnetic recording material Disk surface is logically divided into tracks, which
are subdivided into sectors.The disk controller determines the logical
interaction between the device and the computer. Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
PARTS OF MAGNETIC DISKSPINDLETRACKSECTORCYLINDERPLATTERARM
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Storage HierarchyStorage systems organized in hierarchy.
SpeedCostVolatility
Caching – copying information into faster storage system; main memory can be viewed as a last cache for secondary storage.
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A
Dept
CachingImportant principle, performed at many levels in a
computer (in hardware, operating system, software)Information in use copied from slower to faster
storage temporarilyFaster storage (cache) checked first to determine if
information is thereIf it is, information used directly from the cache (fast)If not, data copied to cache and used there
Cache smaller than storage being cachedCache management important design problemCache size and replacement policy
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Performance of Various Levels of Storage
Movement between levels of storage hierarchy can be explicit or implicit
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
Subject of Comparison NTFS FAT16 FAT32Operating system compatibility
A computer running Windows Vista, Windows Server 2003, Windows 2000, or Windows XP can access files on an NTFS partition. A computer running Windows NT 4.0 with Service Pack 4 or later can access files on the partition, but some NTFS features, such as Disk Quotas, are not available. Other operating systems allow no access.
File access is available to computers running Microsoft® MS-DOS®, all versions of Windows, Windows NT, Windows XP, Windows Vista, and OS/2.
File access is available only to computers running Microsoft® Windows 95 OSR2, Windows 98, Windows Me, Windows 2000, Windows XP, and Windows Vista.
Volume size Recommended minimum volume size is approximately 10 MB.Recommended practical maximum for volumes is 2 terabytes. Much larger sizes are possible.Cannot be used on floppy disks.
Volumes up to 4 GB.Cannot be used on floppy disks.
Volumes from 512 MB to 2 terabytes. In Windows Vista, you can format a FAT32 volume only up to 32 GB.Cannot be used on floppy disks.
File size Maximum file size 16 terabytes minus 64 KB (244 minus 64 KB)
Maximum file size 4 GB Maximum file size 4 GB
Files per volume 4,294,967,295 (232 minus 1 files)
65,536 (216 files) Approximately 4,177,920
Operating System Infosys-Campus Connect M.LAVANYA M.C.A Dept
FAT FAT32 (vFAT) NTFS
Systems DOS, Windows9x, all NTs Windows98, NT5 NT4, NT5
Maximal volume size 2 GBytes near by unlimited near by unlimited
Maximal files count around 65000 near by unlimited near by unlimited
File nameLong names (up to 255 chars), system character set.
Long names (up to 255 chars), system character set.
Long names (up to 255 chars), unicode character set.
File attributes Basic set Basic set All that programmers want
Security No noyes (capability of physical encryption, starting from NT5.0)
Compression no no yes
Fault tolerance middle low fully (automatic)
Economy minimalimproved (small clusters)
maximal
Performance high for small files countas for FAT, but also additional penalty for big volumes
very effective for all volumes