Professional Documents
Culture Documents
SRM UNIVERSITY,RAMAPURAM
L
3
T
0
P
0
PURPOSE
Every computer professional should have a basic understanding of how an operating
system controls the computing resources and provide services to the users. This course
provides an introduction to the operating system functions, design and implementation. It
serves as strong foundation for other courses like networks, compiler design, data base
systems.
INSTRUCTIONAL OBJECTIVES
The students learn about:
1. Structure and functions of OS
2.
Process scheduling, Deadlocks
3.
Device management
4.
Memory management
5.
File systems
UNIT 1 INTRODUCTION
9
Computer system overview-basic elements, Instruction execution, Interrupts, memory
hierarchy, I/O communication techniques, operating system overview-objectives and
functions, Evolution of OS Microsoft windows overview.
UNIT 2 PROCESSES
9
Process description and control - process states, process description, process control;
Processes and Threads, Symmetric Multiprocessing and microkernels. Windows Thread
and SMP management. Case studies-UNIX, SOLARIS thread management
UNIT 3 CONCURRENCY AND SCHEDULING
9
Principles of concurrency - mutual exclusion, semaphores, monitors, Readers/Writers
problem; Deadlocks prevention- avoidance detection .Scheduling : Types of
scheduling scheduling algorithms. Case studies- UNIX scheduling.
UNIT 4 MEMORY
9
Memory management requirements, partitioning, paging, and segmentation; Virtual
memory - Hardware and control structures, operating system software, Linux memory
management, case studies- WINDOWS memory management, UNIX and SOLARIS
Memory management
UNIT 5 INPUT/OUTPUT AND FILE SYSTEMS
9
I/O management and disk scheduling I/O devices, organization of I/O functions; OS
design issues, I/O buffering, disk scheduling, Disk cache, File management
organization, directories, file sharing, record blocking, secondary storage management;
case studies-LINUX I/O, UNIX File management.
TOTAL 45
Page 1 of 157
C
3
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Notes for all five units Prepared by Mrs. Antony Vigil A.P[O.G]/SRMU/RMP
UNIT 1
INTRODUCTION
Computer system overview-Basic elements, Instruction execution, Interrupts, Memory
hierarchy, I/O communication techniques, Operating system overview-Objectives and
functions, Evolution of OS Microsoft windows overview.
Page 2 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Kernel the one program running at all times (all else being application
programs).
Hire an operator
User operator
Resident monitor
Page 3 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Basic Elements
Computer =Processor + Memory + I/O modules
Processor: Controls the operation of the computer and performs its data
processing functions. When there is only on processor, it is often
referred to as CPU.
I/O modules: Move data between the computer and its external environments
(e.g., disk drive, network, terminals).
Page 4 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 5 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Instruction Execution
Execute cycle involves data transfer between processor and memory (or an I/O
module), data processing or changing control flow. Most processors use pipeline
instruction execution and allow Direct Memory Access
Categories of instructions:
Processor-memory
o Transfer data between processor and memory
Processor-I/O
o Data transferred to or from a peripheral device
Data processing
o Arithmetic or logic operation on data
Control
o Alter sequence of execution
Page 6 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Interrupts
Interrupt (or exception):
All computers provide a mechanism by which other modules may interrupt the
normal processing of the processor.
Page 7 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 8 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Interrupt Cycle:
During the interrupt cycle, the processor checks to see if any interrupts have
occurred, indicated by the presence of an interrupt signal. If interrupt is pending, the
processor suspends execution of the current program and executes an Interrupt Handling
Routine. IHR determine the nature of interrupt and performs whatever actions are needed.
Page 9 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 10 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Interrupt Processing:
Multiple Interrupts:
Page 11 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 12 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Interrupt handling:
Multiprogramming:
A process must wait after making an I/O request or after a timer interrupt
Page 13 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 14 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Cache Memory:
Processors can execute instructions faster than instructions (and data) can be
fetched from main memory
Page 15 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
I/O module
The I/O module controls the device to perform the requested action
It also buffers data and maintains a status register that the processor can read
No interrupts occur
Page 16 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 17 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
(ii)Interrupt-driven I/O
No needless waiting
Page 18 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
A DMA controller transfers data directly between a device (typically a disk) and
memory.
o The data does not pass through the processor
Page 19 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Convenience
o Makes the computer more convenient to use.
Efficiency
o Allows computer system resources to be used in an efficient manner
Ability to evolve
o Permit effective development, testing, and introduction of new system
functions without interfering with service
Page 20 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Convenience:
Services provided by the operating system:
Program development
o Editors and debuggers
Program execution
System access
o Login and passwords
Accounting
o Collect usage statistics
o Monitor performance
o This information can be used . . .
o To anticipate future enhancements
o For billing purposes
Efficiency:
Page 21 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Ability to evolve:
A major OS should be able to evolve over time in response to . . .
Errors in the OS
OS can direct processor in the use of other system resources and in the timing of
its execution of other program.
In order to do this, processor must cease executing OS and execute other
programs, i.e., OS relinquishes control of processor.
Page 22 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 23 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Monitor must always in main memory and available for execution. That
portion is referred as Resident Memory.
Page 24 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Interrupt Processing
Monitor
Device Drivers
Job Sequencing
Control
Boundary
Language
Interpreter
User Program Area
Page 25 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
/ / JOB
/ / FORT
/ / LOAD
/ / RUN
/ / END
Protection
After an //END card
or an error, the
monitor flushes
cards until the next
//JOB card
Memory protection
o Does not allow the memory area containing the monitor to be altered
by a job
Timer
o Prevents a job from monopolizing the system
Privileged instructions
o Certain machine level instructions can only be executed by the monitor
l E.g. - I/O instructions (a program should not read cards of next
job)
l Note:
instruction
Interrupts
o Allow processor to do something else while waiting for I/O
o Early computer models did not have this capability
The need for memory protection and privileged instructions led to the concept
of processor modes
A bit in the PSW register toggles the processor between user mode and kernel
mode
Page 26 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 27 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 28 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
(iv)Time-sharing systems
Problems:
Page 29 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 30 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Windows organization
Kernel
Executive
Device Drivers
Service Processes
Environment subsystems
User Applications
Improves reliability
o Each service runs on a separate process with its own partition of memory
o Clients cannot not directly access hardware
Page 31 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Server processes may use multiple threads to process requests from multiple
processes simultaneously
Windows Objects:
Encapsulation
Inheritance
Polymorphism
Page 32 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
UNIT 2
PROCESSES
Process description and control - Process states, Process description, Process control,
Processes and Threads, Symmetric Multiprocessing and Microkernels, Windows
Thread and SMP Management. Case studies-UNIX, SOLARIS thread management
A program in execution
Page 33 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Process States
Dispatcher is a small program which switches the processor from one process to
another
Page 34 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 35 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Termination
Normal Completion
Interactive Login
Memory unavailable
Protection error
Operator or OS Intervention
Process Creation
Interactive Logon
Process Termination
Page 36 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 37 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 38 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Suspended Processes:
Processor is faster than I/O so all processes could be waiting for I/O
o Swap these processes to disk to free up more memory and use processor
on more processes
Page 39 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 40 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Comment
Swapping
Other OS Reason
Timing
Process Description
Processes and Resources:
Page 41 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
For the OS is to manage processes and resources, it must have information about
the current status of each process and resource.
Tables are constructed for each entity the operating system manages
OS Control Tables
Memory Tables
Memory tables are used to keep track of both main and secondary memory.
Page 42 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
I/O Tables
Used by the OS to manage the I/O devices and channels of the computer.
File Tables
Process Tables
Process Attributes
We can group the process control block information into three general categories:
o Process identification
o Processor state information
o Process control information
Page 43 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Process Identification
Many of the other tables controlled by the OS may use process identifiers to
cross-reference process tables
Page 44 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 45 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Process Control
Modes of Execution:
Most processors support at least two modes of execution
User mode
o Less-privileged mode
o User programs typically execute in this mode
System mode
o More-privileged mode
o Kernel of the operating system
Process Creation:
Process switch is switch the process state between the status like read, blocked,
suspend. Mode switch is the switch the process privilege between the mode like use
mode, kernel mode. Generally a mode switch is considered less expensive compared to a
process switch.
Process Switching:
Page 46 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Cause
Use
Interrupt
Reaction to an asynchronous
external event
Trap
Supervisor call
exception condition
Explicit request
Page 47 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 48 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 49 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Resource ownership - process includes a virtual address space to hold the process
image
Multithreading:
UNIX supports multiple user processes but only supports one thread per process
Process:
Thread:
Page 50 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 51 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Benefits of Threads
Less time to switch between two threads within the same process
Since threads within the same process share memory and files, they can
communicate with each other without invoking the kernel
Asynchronous processing
Speed of execution
Threads
Suspending a process involves suspending all threads of the process since all
threads share the same address space
Thread States:
o Block
o Unblock
o Finish
Page 52 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 53 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Adobe PageMaker
User-Level Threads
Page 54 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Kernel-Level Threads:
Kernel maintains context information for the process and the threads
Combined Approaches
Example is Solaris
Page 55 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 56 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Typically each processor does self-scheduling form the pool of available process
or threads
SMP Architecture:
Categories of Computer Systems:
Page 57 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Scheduling
Synchronization
Memory management
Microkernels:
Many services traditionally included in the operating system are now external
subsystems
o Device drivers
o File systems
o Virtual memory manager
o Windowing system
o Security services
Page 58 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Extensibility
o Allows the addition of new services
Flexibility
o New features added
o Existing features can be subtracted
Portability
o Changes needed to port the system to a new processor is changed in the
microkernel - not in the other services
Reliability
o Modular design
o Small microkernel can be rigorously tested
Page 59 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Microkernel Design:
Interprocess Communication
Page 60 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Implemented as objects
Page 61 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Ready
Standby
Running
Waiting
Transition
Terminated
Page 62 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Process includes the users address space, stack, and process control block
User-level threads
Kernel threads
Page 63 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Identifier
Priority
Signal mask
Kernel stack
Page 64 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 65 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
State
Scheduling information
Identifiers
Interprocess communication
Links
File system
Address space
Processor-specific context
Running
Interruptable
Uninterruptable
Stopped
Zombie
Page 66 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 67 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
UNIT 3
CONCURRENCY AND SCHEDULING
Concurrency
3 different contexts:
Page 68 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Principles of Concurrency
In single processor multiprogramming system, process is interleaved in time to
yield the appearance of simultaneous execution.
Difficulties of Concurrency:
Process Interaction:
Page 69 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Mutual Exclusion
o Critical sections
Deadlock
Starvation
Mutual Exclusion
Hardware Support:
Interrupt Disabling
o A process runs until it invokes an operating system service or until it
is interrupted
o Disabling interrupts guarantees mutual exclusion
o Processor is limited in its ability to interleave programs
o Multiprocessing
Page 70 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Exchange Instruction
void exchange(int register,int memory)
{
int temp;
temp = memory;
memory = register;
register = temp;
}
Page 71 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Semaphores
Semaphore Primitives:
Page 72 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 73 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 74 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 75 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 76 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Producer/Consumer Problem:
One or more producers are generating data and placing these in a buffer
Only one producer or consumer may access the buffer at any one time
Page 77 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Monitors
Chief characteristics
o Local data variables are accessible only by the monitor
o Process enters monitor by invoking one of its procedures
o Only one process may be executing in the monitor at a time
Page 78 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Synchronization:
Sender and receiver may or may not be blocking (waiting for message)
Addressing:
Direct addressing
o Send primitive includes a specific identifier of the destination process
o Receive primitive could know ahead of time which process a message is
expected
o Receive primitive could use source parameter to return a value when the
receive operation has been performed
Indirect addressing
o Messages are sent to a shared data structure consisting of queues
o Queues are called mailboxes
o One process sends a message to the mailbox and the other process picks
up the message from the mailbox
Page 79 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Message Format:
Page 80 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Readers/Writers Problem
Deadlock
Permanent blocking of a set of processes that either compete for system resources
or communicate with each other
No efficient solution
Page 81 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Reusable Resources:
Used by only one process at a time and not depleted by that use
Processes obtain resources that they later release for reuse by other processes
Processors, I/O channels, main and secondary memory, devices, and data
structures such as files, databases, and semaphores
Deadlock occurs if each process holds one resource and requests the other
Example of Deadlock:
Directed graph that depicts a state of the system of resources and processes
Page 82 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Mutual exclusion
o Only one process may use a resource at a time
Hold-and-wait
o A process may hold allocated resources while awaiting assignment of
others
No preemption
o No resource can be forcibly removed from a process holding it
Circular wait
A closed chain of processes exists, such that each process holds at least one resource
needed by the next process in the chain
Deadlock Prevention
Mutual Exclusion
o Must be supported by the operating system
No Preemption
o Process must release resource and request again
o Operating system may preempt a process to require it releases its
resources
Circular Wait
o Define a linear ordering of resource types
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
Page 83 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Deadlock Avoidance
Deadlock Avoidance:
Deadlock Detection
Page 84 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Lowest priority
Page 85 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Scheduling
Aim of Scheduling:
Response time
Throughput
Processor efficiency
Long-Term Scheduling
Medium-Term Scheduling
Page 86 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Short-Term Scheduling
Page 87 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Scheduling Algorithms
First-Come-First-Serve (FCFS)
Round-Robin
Page 88 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
First-Come-First-Serve (FCFS):
When the current process ceases to execute, the oldest process in the Ready
queue is selected
A short process may have to wait a very long time before it can execute
Round-Robin (RR):
Page 89 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Nonpreemptive policy
If estimated time for process not correct, the operating system may abort it
Page 90 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Multilevel feedback using round robin within each of the priority queues
Base priority divides all processes into fixed bands of priority levels
Bands
Page 91 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page 92 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
UNIT 4
MEMORY
Memory management requirements, Partitioning, Paging, and Segmentation; Virtual
memory - Hardware and control structures, operating system software- Linux memory
management, Case studies- WINDOWS memory management, UNIX and SOLARIS
Memory management
Memory Management:
Relocation
o Programmer does not know where the program will be placed in memory
when it is executed
o While the program is executing, it may be swapped to disk and returned to
main memory at a different location (relocated)
o Memory references must be translated in the code to actual physical
memory address
Protection
o Processes should not be able to reference memory locations in another
process without permission
o Impossible to check absolute addresses at compile time
o Must be checked at rum time
o Memory protection requirement must be satisfied by the processor
(hardware) rather than the operating system (software)
o Operating system cannot anticipate all of the memory references a
program will make
Page 93 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Sharing
o Allow several processes to access the same portion of memory
o Better to allow each process access to the same copy of the program rather
than have their own separate copy
Logical Organization
o Programs are written in modules
o Modules can be written and compiled independently
o Different degrees of protection given to modules (read-only, execute-only)
o Share modules among processes
Physical Organization
o Memory available for a program plus its data may be insufficient
Page 94 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Partitioning
Fixed Partitioning:
Equal-size partitions
o Any process whose size is less than or equal to the partition size can be
loaded into an available partition
o If all partitions are full, the operating system can swap a process out of a
partition
o A program may not fit in a partition. The programmer must design the
program with overlays
o Main memory use is inefficient. Any program, no matter how small,
occupies an entire partition. This is called internal fragmentation.
Page 95 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Equal-size partitions
o Because all partitions are of equal size, it does not matter which partition
is used
Unequal-size partitions
o Can assign each process to the smallest partition within which it will fit
o Queue for each partition
o Processes are assigned in such a way as to minimize wasted memory
within a partition
Page 96 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Dynamic Partitioning
Must use compaction to shift processes so they are contiguous and all free
memory is in one block
Page 97 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Best-fit algorithm
o Chooses the block that is closest in size to the request
o Worst performer overall
o Since smallest block is found for process, the smallest amount of
fragmentation is left
o Memory compaction must be done more often
First-fit algorithm
o Scans memory form the beginning and chooses the first available block
that is large enough
o Fastest
o May have many process loaded in the front end of memory that must be
searched over when trying to find a free block
Next-fit
o Scans memory from the location of the last placement
o More often allocate a block of memory at the end of memory where the
largest block is found
o The largest block of memory is broken up into smaller blocks
o Compaction is required to obtain a large block at the end of memory
Page 98 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Buddy System:
If a request of size s such that 2U-1 < s <= 2U, entire block is allocated
o Otherwise block is split into two equal buddies
o Process continues until smallest block greater than or equal to s is
generated
Page 99 of 157
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Relocation
When program loaded into memory the actual (absolute) memory locations are
determined
Addresses
Logical
o Reference to a memory location independent of the current assignment of
data to memory
o Translation must be made to the physical address
Relative
o Address expressed as a location relative to some known point
Physical
o The absolute address or actual location in main memory
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Paging
Partition memory into small equal fixed-size chunks and divide each process into
the same size chunks
The chunks of a process are called pages and chunks of memory are called frames
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Segmentation
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Virtual Memory
Hardware and Control Structures:
Memory references are dynamically translated into physical addresses at run time
o A process may be swapped in and out of main memory such that it
occupies different regions
A process may be broken up into pieces that do not need to located contiguously
in main memory
All pieces of a process do not need to be loaded in main memory during execution
Execution of a Program:
Operating system brings into main memory a few pieces of the program
Piece of process that contains the logical address is brought into main memory
o Operating system issues a disk I/O Read request
o Another process is dispatched to run while the disk I/O takes place
o An interrupt is issued when disk I/O complete which causes the operating
system to place the affected process in the Ready state
Types of Memory:
Real memory
o Main memory
Virtual memory
o Memory on disk
o Allows for effective multiprogramming and relieves the user of tight
constraints of main memory
Thrashing
The processor spends most of its time swapping pieces rather than executing user
instructions
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Principle of Locality
Only a few pieces of a process will be needed over a short period of time
Possible to make intelligent guesses about which pieces will be needed in the
future
Paging
Each page table entry contains the frame number of the corresponding page in
main memory
Modify bit is needed to indicate if the page has been altered since it was last
loaded into main memory
If no change has been made, the page does not have to be written to the disk when
it needs to be swapped out
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page number
Process identifier
Control bits
Chain pointer
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Each virtual memory reference can cause two physical memory accesses
o One to fetch the page table
o One to fetch the data
To overcome this problem a high-speed cache is set up for page table entries
o Called a Translation Lookaside Buffer (TLB)
If page table entry is present (TLB hit), the frame number is retrieved and the real
address is formed
If page table entry is not found in the TLB (TLB miss), the page number is used
to index the process page table
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Page Size:
Larger page tables means large portion of page tables in virtual memory
Small page size, large number of pages will be found in main memory
As time goes on during execution, the pages in memory will all contain portions
of the process near recent references. Page faults low.
Increased page size causes pages to contain locations further from any recent
reference. Page faults rise.
Segmentation:
Segment Tables:
Another bit is needed to determine if the segment has been modified since it was
loaded in main memory
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Optimal policy
o Selects for replacement that page for which the time to the next reference
is the longest
o Impossible to have perfect knowledge of future events
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Clock Policy
o Additional bit called a use bit
o When a page is first loaded in memory, the use bit is set to 1
o When the page is referenced, the use bit is set to 1
o When it is time to replace a page, the first frame encountered with the use
bit set to 0 is replaced.
o During the search for replacement,each use bit set to 1 is changed to 0
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Cleaning Policy:
Demand cleaning
o A page is written out only when it has been selected for replacement
Precleaning
o Pages are written out in batches
Load Control:
Too few processes, many occasions when all processes will be blocked and much
time will be spent in swapping
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
16KB
8 KB
4 KB
4 KB
Address Translation:
Page directory
Page table
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Linux processes:
Virtual address space composed of areas with same protection, paging properties
(pageable or not, direction of growth)
Each process has a linked list of areas, sorted by virtual address (text, data,
memory-mapped-files,)
The rest: user pages, file system buffers, variable-size device drivers
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CASE STUDIES
UNIX and SOLARIS Memory Management
Paging system:
Page replacement:
o Page frame data table used for page replacement
o Lists are created within table using pointers (e.g., list of free
frames available; when number of frames on this table drops below
a threshold, the kernel will steal a number of pages to compensate)
o Page replacement algorithm in SVR4 is a modified clock policy
algorithm, the two-handed clock algorithm
It uses the reference bit in the page table entry for each
page in memory that is eligible (not locked) to be swapped
out
Requirement
o Kernel generates and destroys frequently small tables and buffers
(e.g, file descriptor blocks) which require dynamic memory
allocation
o These tables and buffers are much smaller than typical machine
page size: paging mechanism would be inefficient
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
awakened periodically to inspect the state of memory - if less than 'th of page
frames are free, then it frees page frames
this strategy performs better than evicting pages when needed (and writing the
modified to disk in a hurry)
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
UNIT 5
INPUT/OUTPUT AND FILE SYSTEMS
I/O management and disk scheduling I/O devices, organization of I/O functions; OS
design issues, I/O Buffering, disk scheduling, Disk cache, File management
Organization, Directories, File sharing, Record blocking, Secondary storage
management; Case studies-LINUX I/O, UNIX File management.
Human readable
o Used to communicate with the user
o Printers
o Video display terminals
o Display
o Keyboard
o Mouse
Machine readable
o Used to communicate with electronic equipment
o Disk and tape drives
o Sensors
o Controllers
o Actuators
Communication
o Used to communicate with remote devices
o Digital line drivers
o Modems
Data rate
o May be differences of several orders of magnitude between the data
transfer rates
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Application
o Disk used to store files requires file management software
o Disk used to store virtual memory pages needs special hardware and
software to support it
o Terminal used by system administrator may have a higher priority
Complexity of control
Unit of transfer
o Data may be transferred as a stream of bytes for a terminal or in larger
blocks for a disk
Data representation
o Encoding schemes
Error conditions
o Devices respond to errors differently
Programmed I/O
o Process is busy-waiting for the operation to complete
Interrupt-driven I/O
o I/O command is issued
o Processor continues executing instructions
o I/O module sends an interrupt when done
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
I/O processor
o I/O module has its own local memory
o Its a computer in its own right
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Efficiency
o Most I/O devices extremely slow compared to main memory
o Use of multiprogramming allows for some processes to be waiting on I/O
while another process executes
o I/O cannot keep up with processor speed
o Swapping is used to bring in additional Ready processes which is an I/O
operation
Generality
o Desirable to handle all I/O devices in a uniform manner
o Hide most of the details of device I/O in lower-level routines so that
processes and upper levels see devices in general terms such as read,
write, open, close, lock, unlock
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
I/O Buffering
Block-oriented
o Information is stored in fixed sized blocks
o Transfers are made a block at a time
o Used for disks and tapes
Stream-oriented
o Transfer information as a stream of bytes
o Used for terminals, printers, communication ports, mouse and other
pointing devices, and most other devices that are not secondary storage
Single Buffer
Block-oriented
o User process can process one block of data while next block is read in
o Swapping can occur since input is taking place in system memory, not
user memory
o Operating system keeps track of assignment of system buffers to user
processes
Stream-oriented
o Used a line at time
o User input from a terminal is one line at a time with carriage return
signaling the end of the line
o Output to the terminal is one line at a time
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Double Buffer
A process can transfer data to or from one buffer while the operating system
empties or fills the other buffer
Circular Buffer
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Disk Scheduling
Disk Performance Parameters
o To read or write, the disk head must be positioned at the desired track and
at the beginning of the desired sector
o Seek time
o Time it takes to position the head at the desired track
o Rotational delay or rotational latency
o Time it takes for the beginning of the sector to reach the head
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Access time
o Sum of seek time and rotational delay
o The time it takes to get in position to read or write
Priority
o Goal is not to optimize disk use but to meet other objectives
o Short batch jobs may have higher priority
o Provide good interactive response time
Last-in, first-out
o Good for transaction processing systems
The device is given to the most recent user so there should be little
arm movement
o Possibility of starvation since a job may never regain the head of the line
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
SCAN
o Arm moves in one direction only, satisfying all outstanding requests until
it reaches the last track in that direction
o Direction is reversed
C-SCAN
o Restricts scanning to one direction only
o When the last track has been visited in one direction, the arm is returned to
the opposite end of the disk and the scan begins again
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
N-step-SCAN
o Segments the disk request queue into subqueues of length N
o Subqueues are processed one at a time, using SCAN
o New requests added to other queue when queue is processed
FSCAN
o Two queues
o One queue is empty for new requests
Disk Cache
The block that has been in the cache the longest with no reference to it is replaced
When a block is referenced or brought into the cache, it is placed on the top of the
stack
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
File Management
File management system consists of system utility programs that run as privileged
applications
Long-term existence
Structure
File Operations:
Create
Delete
Open
Close
Read
Write
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Field
o Basic element of data
o Contains a single value
o Characterized by its length and data type
Record
o Collection of related fields
o Treated as a unit
Example: employee record
File
o Collection of similar records
o Treated as a single entity
o Have file names
o May restrict access
Database
o Collection of related data
o Relationships exist among elements
Typical Operations:
Retrieve All
Retrieve One
Retrieve Next
Retrieve Previous
Insert One
Delete One
Update One
Retrieve Few
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Optimize performance
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Use a directory to describe the location of all files plus their attributes
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
File Organization
Criteria for File Organization:
Ease of update
o File on CD-ROM will not be updated, so this is not a concern
Economy of storage
o Should be minimum redundancy in the data
o Redundancy can be used to speed access such as an index
Simple maintenance
Reliability
File Organization:
The Pile
o Data are collected in the order they arrive
o Purpose is to accumulate a mass of data and save it
o Records may have different fields
o No structure
o Record access is by exhaustive search
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
The overflow is merged with the main file during a batch update
Multiple indexes for the same key field can be set up to increase efficiency
Indexed File
May contain an exhaustive index that contains one entry for every record
in the main file
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
File Directories
Sequential file with the name of the file serving as the key
Forces user to be careful not to use the same name for two different files
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Files can be located by following a path from the root, or master, directory down
various branches
Can have several files with the same file name as long as they have unique path
names
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
File Sharing
Two issues
o Access rights
o Management of simultaneous access
Access Rights:
None
o User may not know of the existence of the file
o User is not allowed to read the user directory that includes the file
Knowledge
o User can only determine that the file exists and who its owner is
Execution
o The user can load and execute a program but cannot copy it
Reading
o The user can read the file for any purpose, including copying and
execution
Appending
o The user can add data to the file but cannot modify or delete any of the
files contents
Updating
o The user can modify, deleted, and add to the files data. This includes
creating the file, rewriting it, and removing all or part of the data
Changing protection
o User can change access rights granted to other users
Deletion
o User can delete the file
Owners
o Has all rights previously listed
o May grant rights to others using the following classes of users
Specific user
User groups
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Record Blocking
Fixed Blocking:
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Variable Blocking-Spanned:
Variable Blocking-Unspanned:
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Preallocation:
Need the maximum size for the file at the time of creation
Contiguous allocation
o Single set of blocks is allocated to a file at the time of creation
o Only a single entry in the file allocation table
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Chained allocation
No external fragmentation
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Indexed allocation
o File allocation table contains a separate one-level index for each file
o The index has one entry for each portion allocated to the file
o The file allocation table contains block number for the index
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CASE STUDIES
LINUX FILE MANAGEMENT
Linux Virtual File System:
Assumes files are objects that share basic properties regardless of the target file
system
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Superblock object
o Represents a specific mounted file system
Inode object
o Represents a specific file
Dentry object
o Represents a specific directory entry
File object
o Represents an open file associated with a process
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
Index node
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM
CS0206-OPERATING SYSTEMS
SRM UNIVERSITY,RAMAPURAM