Softdot Hi - Tech Educational & Training Institute Unit-1 Operating System Overview
Softdot Hi - Tech Educational & Training Institute Unit-1 Operating System Overview
UNIT-1
Operating System Overview
DEFINITION
Operating system acts as interface between the user and the computer hardware. They
sit between the user and the hardware of the computer providing an operational
environment to the users and application programs. For a user, therefore, a computer
is nothing but the operating system running on it. It is an extended machine.
User does not interact with the hardware of a computer directly but through the
services offered by OS. This is because the language that users employ is different
from that of the hardware where as users prefer to use natural language or near
natural language for interaction, the hardware uses machine language. Os takes
instruction in the form of commands from the user and translates into machine
understandable instructions, gets these instructions executed by CPU and translates
the result back into user understandable form.
• OS is a resource allocate
• Manages all resources
• Decides between conflicting requests for efficient and fair resource use
OS is a control program
• Controls execution of programs to prevent errors and improper use of the computer
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
1
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• One or more CPUs, device controllers connect through common bus providing
access to shared memory.
• Concurrent execution of CPUs and devices competing for memory cycles.
• I/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 buffers.
• I/O is from the device to local buffer of controller.
• Device controller informs CPU that it has finished its operation by causing an
interrupt.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
2
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• All operating system contain the same components whose functionalities are almost
the same. For instance, all the operating systems perform the functions of storage
management, process management, protection of users from one-another, etc.
• Operating system in general, performs similar functions but may have
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
3
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
distinguishing features. Therefore, they can be classified into different categories on
different bases.
Operating System
Hardware
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
4
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
5
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• 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.
• Process Management.
• A 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 task.
• CPU, memory, I/O, files.
• Initialization data.
• Process termination requires reclaim of any reusable resources.
• Single-threaded process has one program counter specifying location of next
instruction to execute.
• Process executes instructions sequentially, one at a time, until completion.
• Multi-threaded process has one program counter per thread.
• Typically system has many processes, some user, some operating system running
concurrently on one or more CPUs.
• Concurrency by multiplexing the CPUs among the processes / threads.
Memory Management
Storage Management
SYSTEM CALL
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
7
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• Three most common APIs are Win32 API for Windows, POSIX API for POSIX-
based systems (including virtually all versions of UNIX, Linux, and Mac OS X),
and Java API for the Java virtual machine (JVM).
• Why use APIs rather than system calls?
(Note that the system-call names used throughout this text are generic)
OBJECTIVE
• To describe the services an operating system provides to users, processes, and other
systems
• To discuss the various ways of structuring an operating system
• To explain how operating systems are installed and customized and how they boot
SERVICES OF OS
One set of operating-system services provides functions that are helpful to the user:
• User interface - Almost all Operating systems have a User Interface (UI).
• Varies between Command Line (CLI), Graphics User Interface (GUI) and Batch.
• Program Execution - The system must be able to load a program into memory and
to run that program, end execution, either normally or abnormally (indicating error)
• I/O operations - A running program may require I/O, which may involve a file or
an I/O device.
• File-system manipulation - The file system is of particular interest. Obviously,
programs need to read and write files and directories, create and delete them, search
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
8
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
them, list file Information, permission management.
SYSTEM CALL
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
9
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• Process control
• File management
• Device management
• Information maintenance
• Communications
SYSTEM PROGRAM
SYSTEM BOOT
• Operating system must be made available to hardware so hardware can start it.
• Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and
starts it.
• Sometimes two-step process where boot block at fixed location loads bootstrap
loader.
• When power initialized on system, execution starts at a fixed memory location.
• Firmware used to hold initial boot code.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
10
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
UNIT – 2
Operating System Functions
Process Concept
Process in Memory
Process State
• As a process executes, it changes state
o new: The process is being created
o running: Instructions are being executed
o waiting: The process is waiting for some event to occur
o ready: The process is waiting to be assigned to a processor
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
11
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
o terminated: The process has finished execution
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
12
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
13
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Schedulers
Process Creation
• Parent process create children processes, which, in turn create other processes,
forming a tree of processes
• Resource sharing
o Parent and children share all resources
o Children share subset of parent’s resources
o Parent and child share no resources
• Execution
o Parent and children execute concurrently
o Parent waits until children terminate
• Address space
• Child duplicate of parent
• Child has a program loaded into it
• UNIX examples
• fork system call creates new process
• exec system call used after a fork to replace the process’ memory
space with a new program
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
14
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Process Creation
Cooperating Processes
Context Switch
• When CPU switches to another process, the system must save the state of the old
process and load the saved state for the new process
• Context-switch time is overhead; the system does no useful work while switching
• Time dependent on hardware support
CPU Scheduling
Basic Concepts
• Maximum CPU utilization obtained with multiprogramming
• CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution
and I/O wait
• CPU burst distribution
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
15
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
CPU Scheduler
• Selects 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 non-preemptive
• All other scheduling is preemptive
Dispatcher
• Dispatcher module gives control of the CPU to the process selected by the short-
term scheduler; this involves:
o switching context
o switching to user mode
o jumping to the proper location in the user program to restart that program
• Dispatch latency – time it takes for the dispatcher to stop one process and start
another running
Scheduling Criteria
Optimization Criteria
• Associate with each process the length of its next CPU burst. Use these lengths to
schedule the process with the shortest time
• Two schemes:
o no preemptive – once CPU given to the process it cannot be preempted
until completes its CPU burst
o 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
P1 P3 P2 P4
0 3 7 8 12 16
• Average waiting time = (0 + 6 + 3 + 7)/4 = 4
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
17
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
P1 P2 P3 P2 P4 P1
0 2 4 5 7 11 16
• Average waiting time = (9 + 1 + 0 +2)/4 = 3
Priority Scheduling
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
18
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
o q small ⇒ q must be large with respect to context switch, otherwise
overhead is too high
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
2 3 5 7 9 11 12 13 15 16
0
0 7 7 7 7 7 1 4 4 2
Typically, higher average turnaround than SJF, but better response
Multilevel Queue
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
19
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• Three queues:
o Q0 – RR with time quantum 8 milliseconds
o Q1 – RR time quantum 16 milliseconds
o Q2 – FCFS
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
20
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• Scheduling
o A new job enters queue Q0 which is served FCFS. When it gains CPU, job
receives 8 milliseconds. If it does not finish in 8 milliseconds, job is
moved to queue Q1.
o At Q1 job is again served FCFS and receives 16 additional milliseconds.
If it still does not complete, it is preempted and moved to queue Q2.
Multiple-Processor Scheduling
Deadlock handling
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
21
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
System model
• Resource types R1, R2, . . ., Rm.
• CPU cycles, memory space, I/O devices.
• Each resource type Ri has Wi instances.
• Each process utilizes a resource as follows:
o request
o use
o release
Resource-Allocation Graph
A set of vertices V and a set of edges E.
Process
• Pi requests instance of Rj
Pi
• Pi is holding an instance of Rj
Rj
Pi
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
23
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
24
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Basic facts-:
• If graph contains no cycles ⇒ no deadlock.
• If graph contains a cycle ⇒ deadlock.
• If only one instance per resource type, then deadlock.
• If several instances per resource type, possibility of deadlock.
Deadlock Prevention
No Preemption –
1. If a process that is holding some resources requests another resource that
cannot be immediately allocated to it, then all resources currently being held
are released.
2. Preempted resources are added to the list of resources for which the process is
waiting.
3. Process will be restarted only when it can regain its old resources, as well as
the new ones that it is requesting.
4. Circular Wait – impose a total ordering of all resource types, and require that
each process requests resources in an increasing order of enumeration.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
25
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Deadlock Avoidance
Requires that the system has some additional priori information available.
• Simplest and most useful model requires that each process declare the maximum
number of resources of each type that it may need.
• The deadlock-avoidance algorithm dynamically examines the resource-allocation
state to ensure that there can never be a circular-wait condition.
• Resource-allocation state is defined by the number of available and allocated
resources, and the maximum demands of the processes.
Safe State
• When a process requests an available resource, system must decide if immediate
allocation leaves the system in a safe state.
• System is in safe state if there exists a sequence <P1, P2, …, Pn> of ALL the
processes is the systems such that for each Pi, the resources that Pi can still
request can be satisfied by currently available resources + resources held by all
the Pj, with j < i.
• That is:
o If Pi resource needs are not immediately available, then Pi can wait until
all Pj have finished.
o When Pj is finished, Pi can obtain needed resources, execute, return
allocated resources, and terminate.
o When Pi terminates, Pi +1 can obtain its needed resources, and so on.
Basic facts
• If a system is in safe state ⇒ no deadlocks.
• If a system is in unsafe state ⇒ possibility of deadlock.
• Avoidance ⇒ Ensure that a system will never enter an unsafe state.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
26
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Avoidance algorithms
• Single instance of a resource type. Use a resource-allocation graph
• Multiple instances of a resource type. Use the banker’s algorithm
Resource-Allocation Graph
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
27
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Resource-Allocation Graph Algorithm
• Suppose that process Pi requests a resource Rj
• The request can be granted only if converting the request edge to an assignment
edge does not result in the formation of a cycle in the resource allocation graph
Banker’s Algorithm
• Multiple instances.
• Each process must a priori claim maximum use.
• When a process requests a resource it may have to wait.
• When a process gets all its resources it must return them in a finite amount of
time.
Safety Algorithm
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
29
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Need
ABC
P0 743
P1 122
P2 600
P3 011
P4 431
• The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies
safety criteria.
Deadlock Detection
• Allow system to enter deadlock state
• Detection algorithm
• Recovery scheme
Unit-3
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
30
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
INTRODUCTION, BASIC OF
MEMORY MANAGEMENT
Objectives
In the last two lectures, you learnt about deadlocks, their characterization and various
Deadlock-handling techniques. At the end of this lecture, you will learn about Memory
management, swapping and concept of contiguous memory allocation. Memory
Management is also known as Storage or Space Management.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
31
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• A program can be loaded only where specified and cannot move once loaded.
• Not used much any more.
3. At load time
• Similar to at link-edit time, but do not fix the starting address.
• Program can be loaded anywhere.
• Program can move but cannot be split.
• Need modest hardware: base/limit registers.
• Loader sets the base/limit registers.
4. At execution time
• Addresses translated dynamically during execution.
• Hardware needed to perform the virtual to physical address translation quickly.
• Currently dominates.
• Much more information later.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
32
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Dynamic Loading
• Routine is not loaded until it is called.
• Better memory-space utilization; unused routine is never loaded.
• Useful 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.
Dynamic Linking
• Linking postponed until execution time.
• Small 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.
Overlays
• To handle processes larger than their allocated memory.
• Keep in memory only instructions and data needed at any given time.
Implemented by user, no special support needed from OS, programming design is
Complex. Overlay for a two-pass assembler:
Pass 1 70KB
Pass 2 80KB
Symbol Table 20KB
Common Routines 30KB
Total 200KB
Two overlays: 120 + 130KB
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
33
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
34
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Swapping
Swapping is the act of moving processes between memory and a backing store. This is
done to free up available memory. Swapping is necessary when there are more processes
than available memory. At the coarsest level, swapping is done a process at a time. That
is, an entire process is swapped in/out.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
35
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
OPERATING SYSTEM
In this lecture, you will learn about the contiguous memory management scheme. You
will also learn about virtual memory and concept of swapping.
First let me explain what swapping means. You are all aware by now that for a process to
be executed, it must be in the memory. Sometimes, however, a process can be swapped
(removed) temporarily out of the memory to a backing store (such as a hard disk) and
then brought back into memory for continued execution.
Let me explain with an example:
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
36
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
At any time, only one user process is in memory and it is run to completion and then the
next process is brought into the Memory. This scheme is sometimes referred to as the
Single Contiguous Memory Management.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
37
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Protection Bits:
• One bit for each memory block
• The memory block may belong to either user process or the OS
• Size of memory block should be known
• The bit is 0 if the word belongs to OS
• The bit is 1 if the word belongs to user process
Fence Register
Similar to any other register in the CPU
Contains address of the ‘fence’ between OS and the user process (see Fig. 2)
Fence Register value = P
For every memory reference, when final address is in MAR (Memory Address
Register), it is compared with Fence Register value by h/w thereby detecting
protection violations.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
38
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
OPERATING SYSTEM
FENCE
In a multi-programming environment, where more than one process is in the memory, we
have the fixed-partition scheme. In this scheme,
• Main memory is divided into multiple partitions
• Partitions could be of different sizes but ‘fixed’ at the time of system generation
• Could be used with or without ‘swapping’ and ‘relocation’
• To change partition sizes, system needs to be shut down and generated again with a
new partition size
Objectives
In the last lecture, you have learned about memory management, swapping and concept
of contiguous memory allocation. In this lecturer you are going to learn about how OS
manage the memory partitions.
So how does the OS manage or keep track of all these partitions?
In order to manage all the partitions,
The OS creates a Partition Description Table (PDT)Initially all the entries in PDT are
marked as ‘FREE’, When a partition is loaded into one of the partitions, the PCB of
each process contains the Id of the partition in which the process is running.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
39
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
40
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Refer to figure above.Free partitions are 1 and 4.So, which partition should be
allocated to a new process of size 50K?
First Fit and Worst Fit will allocate Partition 1 while Best Fit will allocate
Partition 4.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
41
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Now consider the same 20K process. This time, though there are three partitions of 10K,
5K and 16K available. None of them are large enough to accommodate the 20K process.
There are no other smaller processes in the queue. Hence these three partitions remain
unused. This is waste of memory and is referred to as external fragmentation.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
42
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
43
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
• ‘Protection key’ for the partition is stored in the PSW
(Program Status Word).
• The process makes a memory reference in an instruction.
• The resulting address and the block are computed.
• The 4-bit protection key for that block is extracted from the protection-key string.
• It is then tallied with the value in PSW.
• If there is a match, then fine!
• Else the process is trying to access an address belonging to some other partition.
Limit Register
The Limit Register for each process can be stored in the PCB and can be saved/restored
during context switch.
• If the program size were 1000, logical addresses generated would be 0 to 999
• The Limit Register therefore is set to 999
• Every ‘logical’ or ‘virtual’ address is checked to ensure that it is <= 999 and then
added to base register. If not, then hardware generates an error and process is aborted
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
44
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Objectives
In the last lecture, you learnt about memory management, Swapping and the contiguous
memory management scheme. In this lecture, you will get to know about non-contiguous
Memory management scheme and the concept of Paging and Segmentation.
Why Segmentation?
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
45
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
and the logical structure of a program. In a segmented scheme, each logical unit can be
allocated its own segment.
3. Protection issues
Of course, the sharing of code raises protection issues. This is most easily handled by
associating with each segment table entry an access control field - perhaps a single bit. If
set, this bit might allow a process to read from the segment in question, but not to write to
it. If clear, both read and write access might be allowed. Now, segments that correspond
to pure code (user written or library) are mapped read only. Data is normally mapped
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
46
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
read-write. Shared code is always mapped read only; shared data might be mapped read-
write for one process and read only for others.
What is segmentation?
In paging, the user’s view of memory and the actual physical memory are separated.
They are not the same. The user’s view is mapped onto the physical memory.
A program is 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
Segmentation Architecture
Logical address consists of a two tuple:
<Segment-number, offset>
• Segment table – maps two-dimensional physical addresses; each table entry has: base
– starting physical address of segments in memory limit – 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.
• Allocation: first fit/best fit and get external fragmentation.
• Protection – easier to map; associated with each entry in segment table: 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.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
47
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Let me explain this with an example:
Consider how you think of a program when you are writing it. You think of it as a main
program with set of subroutines, procedures, functions, or variables. Each of these
modules is referred to by a name. You are not concerned about where in memory these
modules are placed. Each of these segments is of variable length and is intrinsically
defined by the purpose of the segment in the program.
Thus segmentation is a memory management scheme that supports this user view of
memory. Thus a logical address space is a collection of segments with each segment
having a name and length.
Review Questions
1. How does paging differ from segmentation?
2. Describe the mechanism of translating a logical address to physical address in
segmentation.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
48
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Objectives
In the last lecture, you learnt about memory management, swapping and the contiguous
memory management scheme. In this lecture, you will get to know about Virtual Memory
Virtual memory is a memory management technique that allows the execution of
processes that may not be completely in main memory and do not require contiguous
memory allocation. The address space of virtual memory can be larger than that physical
memory.
Advantages:
• Programs are no longer constrained by the amount of physical memory that is
available
• Increased degree of multiprogramming
• Less overhead due to swapping
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
49
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Program objectives and machine advancements in the ’60s made the predictions required
for static allocation difficult, if not impossible. Therefore, the dynamic allocation solution
was generally accepted, but opinions about implementation were still divided. One group
believed the programmer should continue to be responsible for storage allocation, which
would be accomplished by system calls to allocate or dellocate memory. The second
group supported automatic storage allocation performed by the operating system,
because of increasing complexity of storage allocation and emerging importance of
multiprogramming. In 1961, two groups proposed a one-level memory store. One
proposal called for a very large main memory to alleviate any need for storage allocation.
This solution was not possible due to very high cost.
The second proposal is known as virtual memory
Definition
Virtual memory is a technique that allows processes that may not be entirely in the
memory to execute by means of automatic storage allocation upon request. The term
virtual memory refers to the abstraction of separating LOGICAL memory—memory as
seen by the process—from PHYSICAL memory—memory as seen by the processor.
Because of this separation, the programmer needs to be aware of only the logical memory
space while the operating system maintains two or more levels of physical memory
space.
The virtual memory abstraction is implemented by using secondary storage to augment
the processor’s main memory.
Data is transferred from secondary to main storage as and when
necessary and the data replaced is written back to the secondary
Storage according to a predetermined replacement algorithm. If the data swapped is
designated a fixed size, this swapping is called paging; if variable sizes are permitted and
the data is split along logical lines such as subroutines or matrices, it is called
Segmentation. Some operating systems combine segmentation and paging. The diagram
illustrates that a program generated address ( 1 ) or” logical address” consisting of a
logical page number plus the location within that page (x) must be interpreted or
“mapped” onto an actual (physical) main memory address by the operating System using
an address translation function or mapper (2). If the page is present in the main memory,
the mapper substitutes.
The physical page frame number for the logical number (3). If the mapper detects that the
page requested is not present in main memory, a fault occurs and the page must be read
into a frame in main memory from secondary storage (4, 5).
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
50
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
What does the Mapper do?
The mapper is the part of the operating system that translates the logical page number
generated by the program into the physical page frame number where the main memory
holds the page. This translation is accomplished by using a directly indexed table called
the page table which identifies the location of all the program’s pages in the main store. If
the page table reveals that the page is, in fact, not resident in the main memory, the
mapper issues a page fault to the operating system so that execution is suspended on the
process until the desired page can be read in from the secondary store and placed in main
memory.
The mapper function must be very fast if it is not to substantially increase the running
time of the program. With efficiency in mind, where is the page table kept and how is it
accessed by the mapper? The answer involves associative memory.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
51
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
paper to start with and later on, as and when required, you could demand additional
sheets of paper. This way, you will not be wasting money.
You talked about hardware support being required for demand paging. How does
this support work?
An extra bit called the valid-invalid bit is attached to each entry in the page table. This bit
indicates whether the page is in memory or not. If the bit is set to invalid, then it means
that the page is not in memory. On the other hand, if the bit is set to valid, it means that
the page is in memory. The following figure illustrates this:
What happens if a process tries to use a page that was not brought into memory?
If you try to access a page that is marked invalid (not in memory), then page fault occurs.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
52
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
1. Violations
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
53
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
The logical address is outside the range of valid logical addresses for the process. This
will lead to aborting the process, as before. (We will call this condition a memory
management violation.)
2. Page Faults
The logical address is in the range of valid addresses, but the corresponding page is not
currently present in memory, but rather is stored on disk. The operating system must
bring it into memory before the process can continue to execute. (We will call this
condition a page fault).
Paging
Paging device first. (It need not be written out if it has not been altered since it was
brought into memory from the paging device.)
3. When a page is on the paging device rather than in physical memory, the page table
entry is used to store a pointer to the page’s location on a the paging device.
RUNNING
READY
WAITING for IO to complete
to:
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
54
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
RUNNING
READY
WAITING for IO to complete
WAITING for a page to be brought in
(Note, though, that a page wait is in reality just another form of IO wait, except that here
the reason for the wait is not an explicit IO instruction in the process.)
G. Hardware support beyond that for paging along is required for virtual
memory
Though the burden of recognizing and handling page faults falls on the operating system,
certain provisions must be present in the hardware that are not needed with simple
paging:
1. A page fault could occur while a single instruction is being carried out
The ability to restart an instruction that caused a fault in midstream. This can be tricky if
the instruction accesses large blocks of memory - e.g. a block move that copies a
character string en masse.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
55
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
2. Demand paging
The simplest policy is demand paging. Simply stated, under demand paging, a given
page is only brought into memory when the process it belongs to attempts to access it.
Thus, the number of page faults generated by a process will at least be equal to the
number of pages it uses. (The number of faults will be higher if a page that has been used
is removed from memory and then is used again.) In particular, when a process starts
running a program there will be a period of time when the number of faults generated by
the process is very high:
3. Anticipatory or Pre-paging
Some systems combine demand paging with some form of anticipatory paging or pre-
paging. Here, the idea is to bring a page in before it is accessed because it is felt that there
is good reason to expect that it will be accessed. This will reduce the number of page
faults a process generates, and thus speed up its startup at the expense of possibly wasting
physical memory space on unneeded pages. Anticipatory paging becomes increasingly
attractive as physical memory costs go down.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
56
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
If a process is totally swapped out during a long IO wait, then swap the whole set of
pages that were swapped out back in when it is resumed instead of paging it back in a
little bit at a time.
c. Structure of page device may make it advantageous to read several pages at once
Another form of anticipatory paging is based on the clustering of the paging device. If
several pages reside in the same cluster on the paging device, then it may be
advantageous to read all of them in if any one of them is demanded, since the added
transfer time is only a small fraction of the total time needed for a disk access. This is
especially advantageous if the pages correspond to logically-adjacent memory locations.
1. Global policies
When process X needs to fault in a new page, the set of
Candidates for replacement includes all pages belonging to all
Processes on the system. Note that unless a page belonging
to X already happens to be chosen, this will result in an
Increase in the total amount of physical memory allocated to
X.
2. Local policies
When process X needs to fault in a new page, the set of candidates for replacement
includes only those pages currently belonging to process X. Note that this means that the
total amount of physical memory allocated to X will not change.
b. Local paging may be used to keep a particular process from using too much
memory
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
57
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Eventually, however, a local policy may have to be imposed to keep a given process from
consuming too much of the system’s resources.
a. The working set is the set of pages that a process has accessed in the time interval
[T - T, T]
The working set for a process is defined in terms of some interval T back from the
current time T. Building on the principle of locality of reference, it is assumed that this
is a good approximation to the set of pages that the process must have physically resident
in order to run for an interval T into the future without a page fault. (The interval T is
chosen to keep the percentage of memory accesses resulting in a fault to an acceptable
level. A time corresponding to around 10,000 memory accesses being a good rule of
thumb.)
b. During the life of a process, there are times when the working set changes slowly
and other times when it changes rapidly
Studies of the memory access behavior of processes show that typically there are periods
of time during which the working set of a given process changes very little. During these
periods, if sufficient physical memory is allocated to the process then it can page locally
against itself with an acceptably low rate of page faults. These periods are separated by
bursts of paging activity when the process’s working set is changing rapidly. These
correspond to major stages in the program execution - e.g. the termination of one top
level subroutine and the starting up of another. When this happens performance is
improved if the global paging is used.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
58
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
d. The working set concept can also be applied without going to all of the effort
needed to determine the exact working set:
• If the page fault rate for a process lies within a certain empirically determined
range, then assume that it has sufficient physical memory allocated to it to hold its
(slowly evolving) working set and page it locally.
• If the page fault rate increases above the upper limit, assume its working set is
expanding and page it globally, allowing its physical memory allocation to grow to
keep pace with its presumably growing working set.
• If the page fault rate drops too low, then consider reducing its physical memory
allocation by not only paging it against itself but also allowing other processes to
take page frames from it. This corresponds to an assumption that the size of its
working set is less than the amount of physical memory currently allocated to it.
5. We defer detailed discussion of page replacement policies until we briefly note one
further issue.
2. However, the sum of memory required by all processes on the system often exceeds
the amount of physical memory
However, the sum total of the logical address spaces allocated to all the processes on the
system will generally be far greater than the total amount of physical memory available.
(If this were not so, then virtual memory would be of no benefit.) When memory is over
allocated, each page faulted in will result in another page having to be moved out to make
room for it. In general:
a. Too little over allocation (or none at all)
This means that the resource of physical memory is not really being used well. Pages
that could be moved out to the paging device without harm are being kept in physical
memory needlessly.
b. But too much over allocation can lead to a serious performance problem known
as thrashing occurs when all of the pages that are memory resident are high-demand
pages that will be referenced in the near future. Thus, when a page fault occurs, the
page that is removed from memory will soon give rise to a new fault, which in turn
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
59
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
removes a page that will soon give rise to a new fault ... In a system that is thrashing,
a high percentage of the system’s resources is devoted to paging, and overall CPU
utilization and throughput drop dramatically.
c. The only way to prevent thrashing is to limit the number of processes that are
actively competing for physical memory.
This can be done by using a form of intermediate scheduling, with certain processes
being swapped out wholesale as in a non virtual memory system.
Ex: VMS has the concept of the balance set - which is the set of processes currently
allowed to compete for physical memory. The size of the balance set is determined by the
criterion: sum total of the working sets of all processes in the balance set <= available
physical memory
Paged Segmentation
In this model, the logical memory is composed of segments.
Each segment is composed of pages. The per process segment
Table is in memory pointed to by register. Entries map segment
Number to page table base. The page table is as described in the
previous lecture.
How is the mapping from the logical address to?
Physical address done in this combined approach?
The Logical address now consists of segment number, page
Number, and offset. The segment number is indexed into
Segment table to get base of page table. The page number is
Then used to index into page table to get the frame number.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
60
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
The frame number is then concatenated with the offset to get
the physical address. The figure below gives an example of this
mapping.
What are the main advantages of this combined
approach?
The advantages stem out from the fact that it combines the
individual advantages of paging and segmentation.
• Reduces external fragmentation (due to paging within a
• segment)
• Multiple address spaces available (for various segments)
• Distinguishes between access violations and page faults
• Swapping can occur incrementally
• Instructions can have smaller address fields
What are the main disadvantages of this combined
approach?
• Two memory accesses per translation. First the SMT and
• then PMT.
• More tables to manage (SMT and PMT)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
61
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Page is retrieved from the virtual memory and loaded into the
PMT and then the TLB.
INTRODUCTION TO INFORMATION
MANAGEMENT-CONCEPT OF FILE
STRUCTURES
• By going thru you will come across basic concepts related to
• files
• Basic file structures
• Various file operations
Introduction
Whatever the objectives of the applications, it involves the
generation and use of information. As you know the input of
the application is by means of a file, and in virtually all
Applications, output is saved in a file for long-term storage.
You should be aware of the objectives such as accessing of files,
saving the information and maintaining the integrity of the
contents, virtually all computer systems provide file management
services. Hence a file management system needs special
services from the operating system.
1. Files
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
62
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
The following are the commonly discussed with respect to files:
• Field: Basic element of data. Its length and data type
• characterizes it. They can be of fixed or variable length.
• Record: Collection of related fields. Depending on the
• design, records may be of fixed or variable length. Ex: In
• sequential file organization the records are of fixed length
• where as in Line sequential file organization the records are
• of variable length.
• File: Collection of similar records and is referenced by name.
They have unique file names. Restrictions on access control
usually apply at the file level. But in some systems, such
controls are enforced at the record or even at the field level
also.
• Database: Collection of related data. The essential aspects of
• a database are that the relationships that exists among
• elements of data. The database itself consists of one or
• more types of files.
Files are managed by the operating system. How they are
structured, named, accessed, used, protected and implemented
are the major issues in operating system design. As a whole, the
part of the operating system deals with files is known as the file
system. The linked lists and bitmaps are used to keep track of
free storage and how many sectors there are in a logical block are
important to the designers of the file system.
1.1 File Naming: Files are an abstraction mechanism. The main
characteristic feature of abstraction mechanism is the way the
objects being managed are name. The exact rules for the file
naming vary from system to system, but all current operating
system allows strings of one to eight letters as legal file names.
Many file systems support names as long as 255 characters with
a distinguish in upper and lower case. Many operating systems
support two-part file names, with the two parts separated by a
period. The first part is called primary file name and the second
part is called secondary or extension file name.
1.2 File Structure: File can be structured in any of several ways.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
63
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
Three common possibilities are depicted (a) is an unstructured
sequence of bytes (b) record sequence (c) tree structure.
a) Unstructured sequence of bytes: It provide the maximum
flexibility. User programs can put anything they want in their
files and name them any way that is convenient.
b) Record sequence: In this model, a file is a sequence of fixed
length records each with some internal structure. Central idea
of a file being a sequence of records is the idea that the read
operation returns and the write operation overwrites or
appends one record.
c) Tree structure: In this organization, a file consists of a tree of
records, not necessarily all the same length, each containing a
key field in a fixed position in the record. The tree is sorted
on the key field, to allow rapid searching for a particular key.
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
66
SoftDot Hi –Tech Educational & Training Institute
(A unit of De Unique Educational Society)
__________________________________________________
SoftDot Hi –Tech Educational & Training Institute
South–Extension PitamPura Preet Vihar Janakpuri
New Delhi New Delhi New Delhi New Delhi
67