Overview of Operating Systems Concepts
Overview of Operating Systems Concepts
UNIT-1
INTRODUCTION
Computer System - Elements and organization; Operating System Overview -
Objectives and Functions - Evolution of Operating System; Operating System
Structures – Operating System Services - User Operating System Interface - System
Calls – System Programs - Design and Implementation - Structuring methods.
[Link]-System
Computer system consists of one or more CPUs and a number of device controllers
connected through a common bus that provides access to shared memory.
Each device controller is in charge of a specific type of device. The CPU and the device
controllers can execute concurrently, competing for memory cycles. To ensure orderly
access to the shared memory, a memory controller is provided whose function is to
synchronize access to the memory.
Hardware may trigger an interrupt at any time by sending a signal to the CPU, usually by
way of the system bus. Software may trigger an interrupt by executing a special operation
called a system call (also called a monitor call).
When the CPU is interrupted, it stops what it is doing and immediately transfers
execution to a fixed location. The fixed location usually contains the starting address
where the service routine for the interrupt is located. The interrupt service routine
executes; on completion, the CPU resumes the interrupted computation.
A time line of this operation is shown in Figure 1.3.
Interrupts are an important part of computer architecture. Each computer design has its
own interrupt mechanism, but several functions are common. The interrupt must
transfer control to the appropriate interrupt service routine.
[Link]
Computer programs must be in main memory (also called random- access
memory or RAM) to be executed. Main memory is the only large storage area
(millions to billions of bytes) that the processor can access directly. Dynamic
random-access memory (DRAM) -> is implemented in a semiconductor technology
which forms an array of memory words.
A typical instruction-execution cycle, as executed on a system with a von Neumann
architecture, first fetches an instruction from memory and stores that instruction
in the instruction register.
Two possible reasons if we want the programs and data to reside in main memory
permanently.
1. Main memory is usually too small to store all needed programs and
data permanently.
2. Main memory is a volatile storage device that loses its contents when power is
turned off or otherwise lost.
3. I/OStructure
Storage is only one of many types of I/O devices within a computer. A large
portion of operating system code is dedicated to managing I/O, both because of its
importance to the reliability and performance of a system and because of the
varying nature of the devices.
A general-purpose computer system consists of CPUs and multiple
device controllers that are connected through a common bus. Each device
controller is in charge of a specific type of device. Depending on the controller, there
may be more than one attached device.
A device controller maintains some local buffer storage and a set of special-
purpose registers. The device controller is responsible for moving the data between
the peripheral devices that it controls and its local buffer storage.
Typically, operating systems have a device driver for each device controller. This
device driver understands the device controller and presents a uniform interface
to the device to the rest of the operating system. On these systems, multiple
components can talk to other components concurrently, rather than competing
for cycles on a shared bus.
3. EVALUATION OF OPERATING SYSTEM:
Operating System is a type of software that acts as an interface between the user and
the hardware. It is responsible to handle various critical functions of the computer or any
other machine. Various tasks that are handled by OS are file management, task management,
garbage management, memory management, process management, disk management, I/O
management, peripherals management, etc.
Operating Systems, has evolved in past years. It went through several changes before getting
its original form. These changes in the operating system are known as the evolution
of operating systems. The evolution of the operating system went through four
generations. Let us see these generations in detail:
First Generation:
• This phase is considered from 1945-1955. Earlier mechanical systems were used which
involved the use of large machines whose parts were manually handled by workers. The
limited capacity to work of a human and the tendency to commit an error by a person
often lead to problems. Thus electronic machines were introduced to do the work.
Though these machines did not use an OS at all still this phase is regarded as the
beginning of the Operating Systems era.
• The electronic machines supplied instructions that were to be executed by the machine
immediately because if an error occurred, the whole process was to be restarted again.
The calculation speed in these machines was limited and still errors could occur if there
was any error in the instruction provided to the machine. These systems were referred
to as serial processing systems.
Second Generation:
• The phase from 1955 to 1965 marked the second generation of Operating Systems. The
systems in this generation were regarded as Batch Systems. These were known as
batch operating systems as the jobs to be done were supplied in a batch to the machine.
A Batch referred to a set of similar tasks or jobs. Job Control Language was used to create
the instructions to execute the job. The instructions were punched on a card which was
then loaded onto a tape that had several such cards and then it was finally sent to the
processor.
• The second generation of OS ensured that the machines remained as busy as possible so
that maximum efficiency could be obtained. The machine took up a job, process the
instructions and then move to the next job that was present on the card loaded onto the
tape. If an error occurred during a particular job, then the job needs to be restarted
again.
• These systems made it possible to execute multiple jobs on a single machine and laid the
foundation for multitasking.
• These systems had a drawback in that when the I/O operations were carried out, the
processor had to remain idle.
Third Generation:
• The phase from 1965-1980 is considered as the third generation of OS. It saw the rise of
multi-programmed batched systems. These systems were very similar to the batched
operating systems. These systems had the ability of multitasking and multiprogramming
where the tasks of multiple users could be run simultaneously.
• Users could connect to the machine and submit their tasks through an online terminal.
The OS held all the tasks in the main memory and managed the tasks to be executed using
various scheduling algorithms such as FCFS, SJF, LJF, etc. This also ensured that the tasks
or jobs do not suffer from starvation.
Fourth Generation:
• 1980 onwards, the generation of OS is known as the fourth generation. With the
development of computer networking and various networking protocols, these
operating systems allowed the users to know the existence of other users on the network.
• The operating systems in this generation saw the use of a Graphical User Interface (GUI)
which made it very easy to interact with the operating system and in turn with the
hardware.
• The fourth generation of operating systems saw the invention of time-shared operating
systems and the Macintosh operating systems. Let us see about the time- shared
operating systems and the Macintosh operating systems in brief.
In other operating systems, many times users felt that their work was not being done as
some tasks took too long to get completed. This lead to starvation of processes or jobs. Time-
shared operating systems solved this problem by ensuring that no user feels that his work
is not being done. These operating systems made use of scheduling algorithms such as Round
Robin in which the work of a user was done for a specific time and then the OS moved to
the next job. Thus, in actuality, these OS shared the time between multiple users and hence
got the name Time Shared Operating Systems.
These types of operating systems paved the way for Mac and Windows OS. The use of
personal computers grew as the OS evolved more and more and the computers became more
user-centric instead of being shared by multiple users. Personal computers became
increasingly cheap as the hardware costs decreased. As the hardware evolved more and
more, the color Macs were developed and Microsoft implemented Windows based on the
Graphical User Interface operating system.
4. OBJECTIVE AND FUNCTIONS OF OPERATING SYSTEM
5. OPERATING SYSTEM STRUCTURE
3. MONOLITHIC STRUCTURE:
The kernel is the heart of a computer operating system (OS). Kernel delivers
basic services to all other elements of the System. It serves as the primary
interface between the Operating System and the hardware.
In monolithic systems, kernels can directly access all the resources of the
operating System like physical hardware, exp Keyboard, Mouse etc.
The monolithic kernel is another name for the monolithic operating system.
Batch processing and time-sharing maximize the usability of a processor by
multiprogramming. The monolithic kernel functions as a virtual machine by
working on top of the Operating System and controlling all hardware
components. This is an outdated operating system that was used in banks to
accomplish minor activities such as batch processing and time- sharing, which
enables many people at various terminals to access the Operating System.
• If any service in the monolithic kernel fails, the entire System fails
because, in address space, the services are connected to each other and
affect each other.
• It is not flexible, and to introduce a new service
4 .MICRO-KERNEL
An Operating System provides services to both the users and to the programs.
• Program execution
• I/O operations
• File System manipulation
• Communication
• Error Detection
• Resource Allocation
• Protection
1. Program execution
Operating systems handle many kinds of activities from user programs to system
programs like printer spooler, name servers, file server, etc. Each of these activities is
encapsulated as a process.
A process includes the complete execution context (code to execute, data to manipulate,
registers, OS resources in use). Following are the major activities of an operating system
with respect to program management −
2. I/O Operation
An Operating System manages the communication between user and device drivers.
• I/O operation means read or write operation with any file or any specific I/O
device.
• Operating system provides the access to the required I/O device when required.
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directions. Following are the major activities of
an operating system with respect to file management −
• Program needs to read a file or write a file.
• The operating system gives the permission to the program for operation on file.
• Permission varies from read-only, read-write, denied and so on.
• Operating System provides an interface to the user to create/delete files.
• Operating System provides an interface to the user to create/delete directories.
• Operating System provides an interface to create the backup of file system.
4. Communication
In case of distributed systems which are a collection of processors that do not share
memory, peripheral devices, or a clock, the operating system manages communications
between all the processes. Multiple processes communicate with one another through
communication lines in the network.
The OS handles routing and connection strategies, and the problems of contention and
security. Following are the major activities of an operating system with respect to
communication −
Errors can occur anytime and anywhere. An error may occur in CPU, in I/O devices or
in the memory hardware. Following are the major activities of an operating system with
respect to error handling −
6. Resource Management
In case of multi-user or multi-tasking environment, resources such as main memory,
CPU cycles and files storage are to be allocated to each user or job. Following are the
major activities of an operating system with respect to resource management −
7. Protection
There are many problems that can occur while designing and implementing an
operating system. These are covered in operating system design and
implementation.
1. OPERATING SYSTEM DESIGN GOALS
There are basically two types of goals while designing an operating system. These
are −
2. User Goals
The operating system should be convenient, easy to use, reliable, safe and fast
according to the users. However, these specifications are not very useful as there
is no set method to achieve these goals.
3. SYSTEM GOALS
The operating system should be easy to design, implement and maintain. These are
specifications required by those who create, maintain and operate the operating
system. But there is not specific method to achieve these goals as well.
OPERATING SYSTEM MECHANISMS AND POLICIES
For example - If the mechanism and policy are independent, then few
changes are required in mechanism if policy changes. If a policy favours I/O
intensive processes over CPU intensive processes, then a policy change to
preference of CPU intensive processes will not change the mechanism.
[Link] SYSTEM IMPLEMENTATION
1. PROCESS CONCEPT:
A question that arises in discussing operating systems involves what to call all the
CPU activities. A batch system executes jobs, whereas a time-shared system has
user programs, or tasks. Even on a single-user system such as Microsoft Windows, a
user may be able to run several programs at one time: a word processor, a web
browser, and an e-mail package. Even if the user can execute only one program at a
time, the operating system may need to support its own internal programmed
activities, such as memory management. In many respects, all these activities are
similar, so we call all of them processes. The terms job and process are used almost
interchangeably in this text. Although we personally prefer the term process, much
of operating-system theory and terminology was developed during a time when the
major activity of operating systems was job processing. It would be misleading to
avoid the use of commonly accepted terms that include the word job (such as job
scheduling) simply because process has superseded job.
The Process
Informally, as mentioned earlier, a process is a program in execution. A process is
more than the program code, which is sometimes known as the text section. It also
includes the current activity, as represented by the value of the program counter
and the contents of the processor's registers. A process generally also includes the
process stack, which contains temporary data (such as function parameters, return
addresses, and local variables), and a data section, which contains global variables.
A process may also include a heap, which is memory that is dynamically allocated
during process run time. We emphasize that a program by itself is not a process; a
program is a passive entity, such as a file containing a list of instructions stored on
disk (often called an executable file), whereas a process is an active entity, with a
program counter specifying the next instruction to execute and a set of associated
resources. A program becomes a process when an executable file is loaded into
memory. Two common techniques for loading executable files are double-clicking
an icon representing the executable file and entering the name of the executable file
on the command line (as in prog. exe or a. out.) Although two processes may be
associated with the same program, they are nevertheless considered two separate
execution sequences. For instance, several users may be running different copies of
the mail program, or the same user may invoke many copies of the web browser
program. Each of these is a separate process; and although the text sections are
equivalent, the data, heap, and stack sections vary. It is also common to have a
process that spawns many processes as it runs.
Process State
As a process executes, it changes state. The state of a process is defined in part by
the current activity of that process. Each process may be in one of the following
states:
• New. The process is being created.
• Running. Instructions are being executed.
• Waiting. The process is waiting for some event to occur (such as an I/O
completion or reception of a signal).
• Ready. The process is waiting to be assigned to a processor.
• Terminated.
The process has finished execution. These names are arbitrary, and they vary
across operating systems. The states that they represent are fotind on all systems,
however. Certain operating systems also more finely delineate process states. It is
important to realize that only one process can be running on any processor at any
instant. Many processes may be ready and limiting, however..
Process Control Block
Each process is represented in the operating system by a process control block
(PCB)—also called a task control block. It contains many pieces of information
associated with a specific process, including these: • Process state. The state may be
new, ready, running, waiting, halted, and so on.
Program counter. The counter indicates the address of the next instruction to be
executed for this process.
• CPU registers. The registers vary in number and type, depending on the computer
architecture. They include accumulators, index registers, stack pointers, and
general-purpose registers, plus any condition-code information. Along with the
program counter, this state information must be saved when an interrupt occurs, to
allow the process to be continued correctly afterward
• CPU-scheduling information. This information includes a process priority,
pointers to scheduling queues, and any other scheduling parameters.
• Memory-management information. This information may include such
information as the value of the base and limit registers, the page tables, or the
segment tables, depending on the memory system used by the operating system .
• Accounting information. This information includes the amount of CPU and real
time used, time limits, account mimbers, job or process numbers, and so on.
• I/O status information. This information includes the list of I/O devices allocated
to the process, a list of open files, and so on. In brief, the PCB simply serves as the
repository for any information that may vary from process to process.
[Link] Scheduling
The process scheduling is the activity of the process manager that handles the removal of the running
process from the CPU and the selection of another process on the basis of a particular strategy.
Process scheduling is an essential part of a Multiprogramming operating systems. Such operating systems
allow more than one process to be loaded into the executable memory at a time and the loaded process
shares the CPU using time multiplexing.
Categories of Scheduling
There are two categories of scheduling:
1. Non-preemptive: Here the resource can’t be taken from a process until the process completes
execution. The switching of resources occurs when the running process terminates and moves to a
waiting state.
2. Preemptive: Here the OS allocates the resources to a process for a fixed amount of time. During
resource allocation, the process switches from running state to ready state or from waiting state to ready
state. This switching occurs as the CPU may give priority to other processes and replace the process
with higher priority with the running process.
1
Running
When a new process is created, it enters into the system as in the running state.
2
Not Running
Processes that are not running are kept in queue, waiting for their turn to execute.
Each entry in the queue is a pointer to a particular process. Queue is
implemented by using linked list. Use of dispatcher is as follows. When a process
is interrupted, that process is transferred in the waiting queue. If the process has
completed or aborted, the process is discarded. In either case, the dispatcher
then selects a process from the queue to execute.
Schedulers
Schedulers are special system software which handle process scheduling in various ways. Their main task
is to select the jobs to be submitted into the system and to decide which process to run. Schedulers are of
three types −
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler
2 Speed is lesser than short Speed is fastest among Speed is in between both
term scheduler other two short and long term
scheduler.
Context Switching
A context switching is the mechanism to store and restore the state or context of a CPU in
Process Control block so that a process execution can be resumed from the same point at a
later time. Using this technique, a context switcher enables multiple processes to share a single
CPU. Context switching is an essential part of a multitasking operating system features.
When the scheduler switches the CPU from executing one process to execute another, the state
from the current running process is stored into the process control block. After this, the state
for the process to run next is loaded from its own PCB and used to set the PC, registers, etc. At that
point, the second process can start executing.
Context switches are computationally intensive since register and memory state must be saved
and restored. To avoid the amount of context switching time, some hardware systems employ
two or more sets of processor registers. When the process is switched, the following
information is stored for later use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information
SCHEDULING ALGORITHM
A Process Scheduler schedules different processes to be assigned to the CPU based on
particular scheduling algorithms. There are six popular process scheduling algorithms which we are
going to discuss in this chapter −
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
P0 0 5 0
P1 1 3 5
P2 2 8 14
P3 3 6 8
P0 0-0=0
P1 5-1=4
P2 14 - 2 = 12
P3 8-3=5
P0 0 5 1 0
P1 1 3 2 11
P2 2 8 1 14
P3 3 6 3 5
P0
0-0=0
P1 11 - 1 = 10
P2 14 - 2 = 12
P3 5-3=2
P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P3 (9 - 3) + (17 - 12) = 11
A thread is a flow of execution through the process code, with its own program counter that
keeps track of which instruction to execute next, system registers which hold its current working
variables, and a stack which contains the execution history.
A thread shares with its peer threads few information like code segment, data segment and open
files. When one thread alters a code segment memory item, all other threads see that.
Each thread belongs to exactly one process and no thread can exist outside a process. Each
thread represents a separate flow of control. Threads have been successfully used in
implementing network servers and web server. They also provide a suitable foundation for parallel
execution of applications on shared memory multiprocessors. The following figure shows the
working of a single-threaded and a multithreaded process.
Difference between Process and Thread
2 Process switching needs interaction with operating Thread switching does not need
system. to interact with operating system.
3 In multiple processing environments, each process All threads can share same set of
executes the same code but has its own memory and open files, child processes.
file resources.
4 If one process is blocked, then no other process can While one thread is blocked and
execute until the first process is unblocked. waiting, a second thread in the
same task can run.
5 Multiple processes without using threads use more Multiple threaded processes use
resources. fewer resources.
6 In multiple processes each process operates One thread can read, write or
independently of the others. change another thread's data.
Advantages of Thread
Types of Thread
In this case, the thread management kernel is not aware of the existence of threads. The thread
library contains code for creating and destroying threads, for passing message and data between
threads, for scheduling thread execution and for saving and restoring thread contexts. The
application starts with a single thread.
Advantages
• Thread switching does not require Kernel mode privileges.
• User level thread can run on any operating system.
• Scheduling can be application specific in the user level thread.
• User level threads are fast to create and manage.
Disadvantages
• In a typical operating system, most system calls are blocking.
• Multithreaded application cannot take advantage of multiprocessing.
In this case, thread management is done by the Kernel. There is no thread management
code in the application area. Kernel threads are supported directly by the operating system. Any
application can be programmed to be multithreaded. All of the threads within an application are
supported within a single process.
The Kernel maintains context information for the process as a whole and for individual’s threads
within the process. Scheduling by the Kernel is done on a thread basis. The Kernel performs
thread creation, scheduling and management in Kernel space. Kernel threads are generally
slower to create and manage than the user threads.
Advantages
• Kernel can simultaneously schedule multiple threads from the same process on multiple
processes.
• If one thread in a process is blocked, the Kernel can schedule another thread of the same
process.
• Kernel routines themselves can be multithreaded.
Disadvantages
• Kernel threads are generally slower to create and manage than the user threads.
• Transfer of control from one thread to another within the same process requires a mode
switch to the Kernel.
Multithreading Models
Some operating system provides a combined user level thread and Kernel level thread facility.
Solaris is a good example of this combined approach. In a combined system, multiple threads
within the same application can run in parallel on multiple processors and a blocking system call
need not block the entire process. Multithreading models are three types
The many-to-many model multiplexes any number of user threads onto an equal or smaller
number of kernel threads.
The following diagram shows the many-to-many threading model where 6 user level threads are
multiplexing with 6 kernel level threads. In this model, developers can create as many user
threads as necessary and the corresponding Kernel threads can run in parallel on a
multiprocessor machine. This model provides the best accuracy on concurrency and when a
thread performs a blocking system call, the kernel can schedule another thread for execution.
Many to One Model
Many-to-one model maps many user level threads to one Kernel-level thread. Thread
management is done in user space by the thread library. When thread makes a blocking system
call, the entire process will be blocked. Only one thread can access the Kernel at a time, so
multiple threads are unable to run in parallel on multiprocessors.
If the user-level thread libraries are implemented in the operating system in such a way that
the system does not support them, then the Kernel threads use the many-to-one relationship
modes.
One to One Model
There is one-to-one relationship of user-level thread to the kernel-level thread. This model
provides more concurrency than the many-to-one model. It also allows another thread to run when
a thread makes a blocking system call. It supports multiple threads to execute in parallel on
microprocessors.
Disadvantage of this model is that creating user thread requires the corresponding Kernel thread.
OS/2, windows NT and windows 2000 use one to one relationship model.
Difference between User-Level & Kernel-Level Thread
1 User-level threads are faster to create and manage. Kernel-level threads are slower to
create and manage.
2 Implementation is by a thread library at the user level. Operating system supports creation
of Kernel threads.
3 User-level thread is generic and can run on any Kernel-level thread is specific to the
operating system. operating system.
We can discuss some of the issues to consider in designing multithreaded programs. These
issued are as follows −
If one thread in a program which calls fork(), does the new process duplicate all threads, or is the
new process single-threaded? If we take, some UNIX systems have chosen to have two versions
of fork(), one that duplicates all threads and another that duplicates only the thread that invoked
the fork() system call.
If a thread calls the exec() system call, the program specified in the parameter to exec() will
replace the entire process which includes all threads.
Signal Handling
Generally, signal is used in UNIX systems to notify a process that a particular event has occurred.
A signal received either synchronously or asynchronously, based on the source of and the reason
for the event being signalled.
All signals, whether synchronous or asynchronous, follow the same pattern as given below −
For example − If multiple database threads are concurrently searching through a database and
one thread returns the result the remaining threads might be cancelled.
A target thread is a thread that is to be cancelled, cancellation of target thread may occur in two
different scenarios −
• Asynchronous cancellation − One thread immediately terminates the target thread.
• Deferred cancellation − The target thread periodically checks whether it should terminate,
allowing it an opportunity to terminate itself in an ordinary fashion.
Thread polls
Multithreading in a web server, whenever the server receives a request it creates a separate
thread to service the request.
• The amount of time required to create the thread prior to serving the request together with
the fact that this thread will be discarded once it has completed its work.
• If all concurrent requests are allowed to be serviced in a new thread, there is no bound on
the number of threads concurrently active in the system.
• Unlimited thread could exhaust system resources like CPU time or memory.
A thread pool is to create a number of threads at process start-up and place them into a pool,
where they sit and wait for work.
10. PROCESS SYNCHRONIZATION
• Independent Process
• Cooperative Process
1. Independent Processes
2. Cooperative Processes
Two processes are said to be cooperative if the execution of one process
affects the execution of another process. These processes need to be
synchronized so that the order of execution can be guaranteed.
Process Synchronization
1. Race Condition
At the time when more than one process is either executing the
same code or accessing the same memory or any shared variable; In that
condition, there is a possibility that the output or the value of the shared
variable is wrong so for that purpose all the processes are doing the race
to say that my output is correct. This condition is commonly known as a
race condition. As several processes access and process the
manipulations on the same data in a concurrent manner and due to
which the outcome depends on the particular order in which the access
of data takes place.
In this section mainly the process requests for its entry in the
critical section.
4. Exit Section
2. Progress
3. Bounded Waiting
After a process makes a request for getting into its critical section, there
is a limit for how many other processes can get into their critical section,
before this process's request is granted. So after the limit is reached, the
system must grant the process permission to get into its critical section.
Synchronization Hardware
This message transmission lag delays the entry of threads into the
critical section, and the system efficiency decreases.
Mutex Locks
1. MAIN MEMORY
The main memory is the fundamental storage unit in a computer system. It is associatively large and quick
memory and saves programs and information during computer operations. The technology that makes the main
memory work is based on semiconductor integrated circuits.
RAM is the main memory. Integrated circuit Random Access Memory (RAM) chips are applicable in two
possible operating modes are as follows −
• Static − It consists of internal flip-flops, which store the binary information. The stored data remains solid
considering power is provided to the unit. The static RAM is simple to use and has smaller read and write
cycles.
• Dynamic − It saves the binary data in the structure of electric charges that are used to capacitors. The
capacitors are made available inside the chip by Metal Oxide Semiconductor (MOS) transistors. The stored
value on the capacitors contributes to discharge with time and thus, the capacitors should be regularly
recharged through stimulating the dynamic memory.
SRAM
RAMs that are made up of circuits and can preserve the information as long as power is supplied are referred to
as Static Random Access Memories (SRAM). Flip-flops form the basic memory elements in an SRAM device.
An SRAM consists of an array of flip-flops, one for each bit. SRAM consists of an array of flip-flops, a large
number of flip-flops are needed to provide higher capacity memory. Because of this, simpler flip-flop circuits,
BJT, and MOS transistors are used for SRAM.
DRAM
SRAMs are faster but their cost is high because their cells require many transistors. RAMs can be obtained at a
lower cost if simpler cells are used. A MOS storage cell based on capacitors can be used to replace the SRAM
cells. Such a storage cell cannot preserve the charge (that is, data) indefinitely and must be recharged
periodically. Therefore, these cells are called dynamic storage cells. RAMs using these cells are referred to as
Dynamic RAMs or simply DRAMs.
2. SWAPPING:
Swapping is a mechanism in which a process can be swapped temporarily out of main memory (or move)
to secondary storage (disk) and make that memory available to other processes. At some later time, the system
swaps back the process from the secondary storage to main memory.
Though performance is usually affected by swapping process but it helps in running multiple and big
processes in parallel and that's the reason Swapping is also known as a technique for memory compaction.
The total time taken by swapping process includes the time it takes to move the entire process to a
secondary disk and then to copy the process back to memory, as well as the time the process takes to regain main
memory.
Let us assume that the user process is of size 2048KB and on a standard hard disk where swapping will
take place has a data transfer rate around 1 MB per second. The actual transfer of the 1000K process to or from
memory will take
2048KB / 1024KB per second
= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds plus other overhead where the process
competes to regain main memory.
Memory Allocation
Main memory usually has two partitions −
• Low Memory − Operating system resides in this memory.
• High Memory − User processes are held in high memory.
Operating system uses the following memory allocation mechanism.
S.N. Memory Allocation & Description
1
Single-partition allocation
In this type of allocation, relocation-register scheme is used to protect user processes from
each other, and from changing operating-system code and data. Relocation register
contains value of smallest physical address whereas limit register contains range of logical
addresses. Each logical address must be less than the limit register.
2
Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed-sized partitions
where each partition should contain only one process. When a partition is free, a process is
selected from the input queue and is loaded into the free partition. When the process
terminates, the partition becomes available for another process.
Fragmentation
As processes are loaded and removed from memory, the free memory space is broken into little pieces. It happens
after sometimes that processes cannot be allocated to memory blocks considering their small size and memory
blocks remains unused. This problem is known as Fragmentation.
Fragmentation is of two types −
1
External fragmentation
Total memory space is enough to satisfy a request or to reside a process in it, but it is not
contiguous, so it cannot be used.
2
Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left unused, as it
cannot be used by another process.
The following diagram shows how fragmentation can cause waste of memory and a compaction technique can be
used to create more free memory out of fragmented memory −
External fragmentation can be reduced by compaction or shuffle memory contents to place all free memory
together in one large block. To make compaction feasible, relocation should be dynamic.
The internal fragmentation can be reduced by effectively assigning the smallest partition but large enough for the
process.
Paging
A computer can address more memory than the amount physically installed on the system. This extra memory is
actually called virtual memory and it is a section of a hard that's set up to emulate the computer's RAM. Paging
technique plays an important role in implementing virtual memory.
Paging is a memory management technique in which process address space is broken into blocks of the same size
called pages (size is power of 2, between 512 bytes and 8192 bytes). The size of the process is measured in the
number of pages.
Similarly, main memory is divided into small fixed-sized blocks of (physical) memory called frames and the size
of a frame is kept the same as that of a page to have optimum utilization of the main memory and to avoid
external fragmentation.
Address Translation
Page address is called logical address and represented by page number and the offset.
Logical Address = Page number + page offset
Frame address is called physical address and represented by a frame number and the offset.
Physical Address = Frame number + page offset
A data structure called page map table is used to keep track of the relation between a page of a process to
a frame in physical memory.
When the system allocates a frame to any page, it translates this logical address into a physical address
and create entry into the page table to be used throughout execution of the program.
When a process is to be executed, its corresponding pages are loaded into any available memory frames.
Suppose you have a program of 8Kb but your memory can accommodate only 5Kb at a given point in time, then
the paging concept will come into picture. When a computer runs out of RAM, the operating system (OS) will
move idle or unwanted pages of memory to secondary memory to free up RAM for other processes and brings
them back when needed by the program.
This process continues during the whole execution of the program where the OS keeps removing idle
pages from the main memory and write them onto the secondary memory and bring them back when required by
the program.
Segmentation
Segmentation is a memory management technique in which each job is divided into several segments of different
sizes, one for each module that contains pieces that perform related functions. Each segment is actually a different
logical address space of the program.
When a process is to be executed, its corresponding segmentation are loaded into non-contiguous memory though
every segment is loaded into a contiguous block of available memory.
Segmentation memory management works very similar to paging but here segments are of variable-length where
as in paging pages are of fixed size.
A program segment contains the program's main function, utility functions, data structures, and so on. The
operating system maintains a segment map table for every process and a list of free memory blocks along with
segment numbers, their size and corresponding memory locations in main memory. For each segment, the table
stores the starting address of the segment and the length of the segment. A reference to a memory location
includes a value that identifies a segment and an offset.
3. Contiguous Memory Allocation
Contiguous memory allocation is a memory allocation method that allocates a single contiguous section of
memory to a process or a file. This method takes into account the size of the file or a process and also estimates the
maximum size, up to what the file or process can grow?
Taking into account the future growth of the file and its request for memory, the operating system allocates
sufficient contiguous memory blocks to that file. Considering this future expansion and the file’s request for
memory, the operating system will allocate those many contiguous blocks of memory to that file.
In this section, we will discuss contiguous memory allocation in detail along with its advantages and disadvantages.
So let us star
1. Memory Allocation
2. Memory Management
3. Fragmentation
4. Advantages and Disadvantages
5. Key Takeaways
Memory Allocation
The main memory has to accommodate both the operating system and userspace. Now, here the userspace has to
accommodate various user processes. We also want these several user processes must reside in the main memory at
the same time.
Now, the question arises how to allocate the available memory space to the user processes that are waiting in a ready
queue?
In Contiguous memory allocation, when the process arrives from the ready queue to the main memory for
execution, the contiguous memory blocks are allocated to the process according to its requirement. Now, to allocate
the contiguous space to user processes, the memory can be divide either in the fixed-sized partition or in the
variable-sized partition.
Fixed-Sized Partition: In the fixed-sized partition, the memory is divided into fixed-sized blocks and each block
contains exactly one process. But, the fixed-sized partition will limit the degree of multiprogramming as the number
of the partition will decide the number of processes.
Variable-Size Partition: In the variable size partition method, the operating system maintains a table that contains
the information about all memory parts that are occupied by the processes and all memory parts that are
still available for the processes.
How holes are created in the memory?
Initially, the whole memory space is available for the user processes as a large block, a hole. Eventually, when the
processes arrive in the memory, executes, terminates and leaves the memory you will see the set of holes of variable
sizes.
In the figure above, you can see that when file A and file C release the memory allocated to them, creates the holes
in the memory of variable size.
In the variable size partition method, the operating system analyses the memory requirement of the process and see
whether it has a memory block of the required size. If it finds the match, then it allocates that memory block to the
process. If not, then it searches the ready queue for the process that has a smaller memory requirement.
The operating system allocates the memory to the process until it cannot satisfy the memory requirement of the next
process in the ready queue. It stops allocating memory to the process if it does not have a memory block (hole) that
is large enough to hold that process.
If the memory block (hole) is too large for the process it gets spilt into two parts. One part of the memory block is
allocated to the arrived process and the other part is returned to the set of holes. When a process terminates and
releases the memory allocated to it, the released memory is then placed back to the set of holes. The two holes that
are adjacent to each other, in the set of holes, are merged to form one large hole.
Now, at this point, the operating system checks whether this newly formed free large hole is able to satisfy the
memory requirement of any process waiting in the ready queue. And the process goes on.
Memory Management
In the above section, we have seen, how the operating system allocates the contiguous memory to the processes.
Here, we will see how the operating system selects a free hole from the set of holes?
The operating system uses either the block allocation list or the bit map to select the hole from the set of holes.
Block allocation list maintains two tables. One table contains the entries of the blocks that are allocated to the
various files. The other table contains the entries of the holes that are free and can be allocated to the process in the
waiting queue.
Now, as we have entries of free blocks which one must be chosen can be decided using either of these strategies:
first-fit, best-fit, worst-fit strategies.
1. First-fit
Here, the searching starts either at the beginning of the table or from where the previous first-fit search has ended.
While searching, the first hole that is found to be large enough for a process to accommodate is selected.
2. Best-fit
This method needs the list of free holes to be sorted according to their size. Then the smallest hole that is large
enough for the process to accommodate is selected from the list of free holes. This strategy reduces the wastage of
memory as it does not allocate a hole of larger size which leaves some amount of memory even after the process
accommodates the space.
3. Worst-fit
This method requires the entire list of free holes to be sorted. Here, again the largest hole among the free holes is
selected. This strategy leaves the largest leftover hole which may be useful for the other process.
Bit Map
The bit map method only keeps track of the free or allocated block. One block is represented by one bit, bit 0
resembles the free block and bit 1 resembles that the block is allocated to a file or a process.
It does not have entries of the files or processes to which the specific blocks are allocated. Normally, implementing
the first fit will search the number of consecutive zeros/free blocks required by a file of process. Having found that
much of consecutive zeros it allocates a file or process to those blocks.
But implementing best-fit or worse-fit will be expensive, as the table of free blocks sorted according to the hole size
has to be maintained. But the bit map method is easy to implement.
FRAGMENTATION:
Fragmentation can either be external fragmentation or internal fragmentation. External fragmentation is when the
free memory blocks available in memory are too small and even non-contiguous. Whereas, the internal
fragmentation occurs when the process does not fully utilize the memory allocated to it.
The solution to the problem of external fragmentation is memory compaction. Here, all the memory contents are
shuffled to the one area of memory thereby creating a large block of memory which can be allocated to one or more
new processes.
Advantages and Disadvantages
The main disadvantage of contiguous memory allocation is memory wastage and inflexibility. As the memory is
allocated to a file or a process keeping in mind that it will grow during the run. But until a process or a file grows
many blocks allocated to it remains unutilized. And they even they cannot be allocated to the other process leading
to wastage of memory.
In case, the process or the file grows beyond the expectation i.e. beyond the allocated memory block, then it will
abort with the message “No disk space” leading to inflexibility.
The advantage of contiguous memory allocation is it increases the processing speed. As the operating system uses
the buffered I/O and reads the process memory blocks consecutively it reduces the head movements. This speed ups
the processing.
Key Takeaways
• Memory allocation can be done either by a fixed-sized partition scheme or by variable-sized partition scheme.
• Block allocation list has three methods to select a hole from the list of free holes first-fit, best-fit and worse-fit.
• Bit map keeps track of free blocks in memory, it has one bit for one memory block, bit 0 shows that the block is free
and bit 1 shows the block is allocated to some file or a process.
• Contiguous memory allocation leads to fragmentation. Further fragmentation can either be external or internal.
• Contiguous memory allocation leads to memory wastage and inflexibility.
• If the operating system uses buffered I/O during processing, then contiguous memory allocation can enhance
processing speed.
his is all about contiguous memory allocation. We have discussed how the memory is allocated, managed. How does
mentation occur in contiguous
PAGING:
• The address space of a process is broken into fixed sized blocks.
• These fixed size blocks are known as pages.
• The operating system divides the memory blocks into pages.
• The size of the page is determined based on the memory available.
• This technique is quick in terms of memory access.
• It can cause internal fragmentation since some pages would not be utilized as much as the other
pages.
• During the process of paging, a logical address is divided into page number and page offset.
• A page table is used to store the page data.
This is how Paging works −
Segmentation
• In this method, the address space of a process is broken down into varying sized blocks.
• These varying sized blocks are known as sections.
• A compiler is responsible in determining the size of the segment, the virtual address and the
actual address.
• The size of the section is determined by the user.
• The process of segmentation is slower in comparison to paging.
• It can result in external fragmentation since some memory blocks may not be used at all.
• During this process, a logical address gets divided into a section number and a section offset.
• A segmentation table can be used to store the segmentation data.
This is how Segmentation techniques works with Segment Map Table −
Both paging and swapping are important concepts in operating systems that place a process in the
main memory for its execution, but they are quite different from each other in many aspects. Read
this article to learn more about paging and swapping and their specific characteristics.
What is Paging?
In OS, Paging is a memory management strategy in which the process address space is divided into
blocks of the same size, called pages (where the size of each page is power of 2, and is between 512
bytes and 8192 bytes). The size of the process is then measured in the number of pages.
In the same way, the main memory is divided into small blocks of fixed size called frames. The size of
each frame is kept the same as that of a page to have the optimum utilization of the main memory
and to avoid the external fragmentation. Therefore, paging is basically a memory allocation technique.
It utilizes non-contiguous memory management technique.
What is Swapping?
Swapping is a memory management technique in which an entire process is copied to another
location. In other words, swapping is a technique in which an entire process is to be placed in the main
memory for its execution. Also, swapping removes the inactive processes from the main memory of
the system.
Swapping helps to provide memory space for the operation of other processes. Hence, swapping
impacts the performance of a system, as it helps in executing multiple large operations concurrently.
Swapping can be done without using any memory management technique.
Now, let us discuss the differences between paging and swapping in detail.
This process occurs when the entire This process occurs when a part of a process is
2. process has been transferred to the transferred to the disk.
disk.
Here, the data is swapped The contiguous block of memory is made non-
3. temporarily from the main memory contiguous but it consists of fixed size called
to a secondary memory. frames known as pages.
It can be done by processes that are Only a process that is currently active can
5.
inactive as well. perform paging operation.
It helps give a direction with respect There is no suggestion about the solution in
6.
to the solution. this technique.
Structure of Page Table in Operating Systems
In this tutorial, we will cover some of the most common techniques used for structuring the Page table.
The data structure that is used by the virtual memory system in the operating system of a computer in
order to store the mapping between physical and logical addresses is commonly known as Page Table.
As we had already told you that the logical address that is generated by the CPU is translated into the
physical address with the help of the page table.
• Thus page table mainly provides the corresponding frame number (base address of the frame)
where that page is stored in the main memory.
The above diagram shows the paging model of Physical and logical memory.
1. Hierarchical Paging
2. Hashed Page Tables
3. Inverted Page Tables
Hierarchical Paging
Another name for Hierarchical Paging is multilevel paging.
• There might be a case where the page table is too big to fit in a contiguous space, so we may
have a hierarchy with several levels.
• In this type of Paging the logical address space is broke up into Multiple page tables.
• Hierarchical Paging is one of the simplest techniques and for this purpose, a two-level page
table and three-level page table can be used.
Consider a system having 32-bit logical address space and a page size of 1 KB and it is further divided
into:
P2 indicates the displacement within the page of the Inner page Table.
As address translation works from outer page table inward so is known as forward-mapped Page
Table.
Below given figure below shows the Address Translation scheme for a two-level page table
For a system with 64-bit logical address space, a two-level paging scheme is not appropriate. Let us
suppose that the page size, in this case, is [Link] in this case, we will use the two-page level scheme
then the addresses will look like this:
Thus in order to avoid such a large table, there is a solution and that is to divide the outer page table,
and then it will result in a Three-level page table:
Given below figure shows the address translation scheme of the Hashed Page Table:
The above Figure shows Hashed Page Table
The Virtual Page numbers are compared in this chain searching for a match; if the match is found then
the corresponding physical frame is extracted.
In this scheme, a variation for 64-bit address space commonly uses clustered page tables.
• These are similar to hashed tables but here each entry refers to several pages (that is 16) rather
than 1.
• Mainly used for sparse address spaces where memory references are non-contiguous and
scattered
• There is one entry for each virtual page number and a real page of memory
• And the entry mainly consists of the virtual address of the page stored in that real memory
location along with the information about the process that owns the page.
• Though this technique decreases the memory that is needed to store each page table; but it
also increases the time that is needed to search the table whenever a page reference occurs.
Given below figure shows the address translation scheme of the Inverted Page Table:
In this, we need to keep the track of process id of each entry, because many processes may have the
same logical addresses.
Also, many entries can map into the same index in the page table after going through the hash
function. Thus chaining is used in order to handle this.
Segmentation is another way of dividing the addressable memory. It is another scheme of memory
management and it generally supports the user view of memory. The Logical address space is basically
the collection of segments. Each segment has a name and a length.
Basically, a process is divided into segments. Like paging, segmentation divides or segments the
memory. But there is a difference and that is while the paging divides the memory into a fixed size and
on the other hand, segmentation divides the memory into variable segments these are then loaded
into logical memory space.
A Program is basically a collection of segments. And a segment is a logical unit such as:
• main program
• procedure
• function
• method
• object
• local variable and global variables.
• symbol table
• common block
• stack
• arrays
Types of Segmentation
Given below are the types of Segmentation:
• Virtual Memory Segmentation With this type of segmentation, each process is segmented into
n divisions and the most important thing is they are not segmented all at once.
• Simple Segmentation With the help of this type, each process is segmented into n divisions and
they are all together segmented at once exactly but at the runtime and can be non-contiguous
(that is they may be scattered in the memory).
Characteristics of Segmentation
Some characteristics of the segmentation technique are as follows:
Need of Segmentation
One of the important drawbacks of memory management in the Operating system is the separation of
the user's view of memory and the actual physical memory. and Paging is a technique that provides the
separation of these two memories.
User'view is basically mapped onto physical storage. And this mapping allows differentiation between
Physical and logical memory.
It is possible that the operating system divides the same function into different pages and those pages
may or may not be loaded into the memory at the same time also Operating system does not care
about the User's view of the process. Due to this technique system's efficiency decreases.
logical address
Basic Method
A computer system that is using segmentation has a logical address space that can be viewed as
multiple segments. And the size of the segment is of the variable that is it may grow or shrink. As we
had already told you that during the execution each segment has a name and length. And the address
mainly specifies both thing name of the segment and the displacement within the segment.
Therefore the user specifies each address with the help of two quantities: segment name and offset.
For simplified Implementation segments are numbered; thus referred to as segment number rather
than segment name.
<segment-number,offset>
where,
Segment Number(s): Segment Number is used to represent the number of bits that are required to
represent the segment.
Offset(d) Segment offset is used to represent the number of bits that are required to represent the size
of the segment.
Segmentation Architecture
Segment Table
A Table that is used to store the information of all segments of the process is commonly known as
Segment Table. Generally, there is no simple relationship between logical addresses and physical
addresses in this scheme.
1. Segment Base/base address: The segment base mainly contains the starting physical address
where the segments reside in the memory.
2. Segment Limit: The segment limit is mainly used to specify the length of the segment.
Segment Table Base Register(STBR) The STBR register is used to point the segment table's location in
the memory.
Segment Table Length Register(STLR) This register indicates the number of segments used by a
program. The segment number s is legal if s<STLR
Segmentation Hardware
Given below figure shows the segmentation hardware :
Offset(d): It must lie in between '0' and 'segment limit'.In this case, if the Offset exceeds the segment
limit then the trap is generated.
Advantages of Segmentation
The Advantages of the Segmentation technique are as follows:
• In the Segmentation technique, the segment table is mainly used to keep the record of
segments. Also, the segment table occupies less space as compared to the paging table.
• There is no Internal Fragmentation.
• Segmentation generally allows us to divide the program into modules that provide better
visualization.
• Segments are of variable size.
Disadvantages of Segmentation
Some disadvantages of this technique are as follows:
Example of Segmentation
Given below is the example of the segmentation, There are five segments numbered from 0 to 4. These
segments will be stored in Physical memory as shown. There is a separate entry for each segment in
the segment table which contains the beginning entry address of the segment in the physical memory(
denoted as the base) and also contains the length of the segment(denoted as limit).
Segment 2 is 400 bytes long and begins at location 4300. Thus in this case a reference to byte 53 of
segment 2 is mapped onto the location 4300 (4300+53=4353). A reference to segment 3, byte 85 is
mapped to 3200(the base of segment 3)+852=4052.
A reference to byte 1222 of segment 0 would result in the trap to the OS, as the length of this segment
is 1000 bytes.
With the help of this technique, the main memory is split into the small blocks of physical memory that
are commonly known as frames. In paging size of frames is fixed. In order to prevent external
fragmentation and for the maximum usage of the main memory, the frame size must be the same as
the page size. This technique helps to access the data faster.
Segmentation in OS
Segmentation is another technique of memory management. This technique is similar to Paging except
for the fact that in segmentation the segments of a process are of variable length but in Paging the
pages are of fixed size.
The memory is split into variable-length parts in segmentation. Each part is commonly known as
segments. Information related to each segment is stored in a table and this table is commonly known
as the segment table. The segment table generally occupies less space as compared to the paging
table.
Differences between Paging and Segmentation
Now, we will cover the differences between Paging and Segmentation in the table given below:
Paging Segmentation
With the help of Paging, the logical address is With the help of Segmentation, the logical address is
divided into a page number and page offset. divided into section number and section offset.
In Paging, the page size is decided by the While in Segmentation, the size of the segment is
hardware. decided by the user.
In order to maintain the page data, the page table In order to maintain the segment data, the segment table
is created in the Paging is created in the Paging
The page table mainly contains the base address The segment table mainly contains the segment number
of each page. and the offset.
This technique is faster than segmentation. On the other hand, segmentation is slower than paging.
In Paging, a list of free frames is maintained by the In Segmentation, a list of holes is maintained by the
Paging Segmentation
In this technique, in order to calculate the In this technique, in order to calculate the absolute
absolute address page number and the offset both address segment number and the offset both are
are required. required.
VIRTUAL MEMORY:
A computer can address more memory than the amount physically installed on the system. This extra
memory is actually called virtual memory and it is a section of a hard disk that's set up to emulate the
computer's RAM.
The main visible advantage of this scheme is that programs can be larger than physical memory. Virtual
memory serves two purposes. First, it allows us to extend the use of physical memory by using disk. Second, it
allows us to have memory protection, because each virtual address is translated to a physical address.
Following are the situations, when entire program is not required to be loaded fully in main memory.
• User written error handling routines are used only when an error occurred in the data or computation.
• Certain options and features of a program may be used rarely.
• Many tables are assigned a fixed amount of address space even though only a small amount of the table
is actually used.
• The ability to execute a program that is only partially in memory would counter many benefits.
• Less number of I/O would be needed to load or swap each user program into memory.
• A program would no longer be constrained by the amount of physical memory that is available.
• Each user program could take less physical memory, more programs could be run the same time, with a
corresponding increase in CPU utilization and throughput.
Modern microprocessors intended for general-purpose use, a memory management unit, or MMU, is built into
the hardware. The MMU's job is to translate virtual addresses into physical addresses. A basic example is
given below −
Virtual memory is commonly implemented by demand paging. It can also be implemented in a segmentation
system. Demand segmentation can also be used to provide virtual memory.
Virtual memory is the partition of logical memory from physical memory. This partition supports large virtual
memory for programmers when only limited physical memory is available.
Virtual memory can give programmers the deception that they have a very high memory although the
computer has a small main memory. It creates the function of programming easier because the programmer no
longer requires to worry about the multiple physical memory available.
Virtual memory works similarly, but at one level up in the memory hierarchy. A memory management unit
(MMU) transfers data between physical memory and some gradual storage device, generally a disk. This
storage area can be defined as a swap disk or swap file, based on its execution. Retrieving data from physical
memory is much faster than accessing data from the swap disk.
There are two primary methods for implementing virtual memory are as follows −
• Paging
Paging is a technique of memory management where small fixed-length pages are allocated instead of a single
large variable-length contiguous block in the case of the dynamic allocation technique. In a paged system,
each process is divided into several fixed-size ‘chunks’ called pages, typically 4k bytes in length. The memory
space is also divided into blocks of the equal size known as frames.
Advantages of Paging
Disadvantage of Paging
Demand Paging
A demand paging system is quite similar to a paging system with swapping where processes reside in
secondary memory and pages are loaded only on demand, not in advance. When a context switch occurs, the
operating system does not copy any of the old program’s pages out to the disk or any of the new program’s
pages into the main memory Instead, it just begins executing the new program after loading the first page and
fetches that program’s pages as they are referenced.
While executing a program, if the program references a page which is not available in the main memory
because it was swapped out a little ago, the processor treats this invalid memory reference as a page fault and
transfers control from the program to the operating system to demand the page back into the memory.
Advantages
Following are the advantages of Demand Paging −
Reference String
The string of memory references is called reference string. Reference strings are generated artificially or by
tracing a given system and recording the address of each memory reference. The latter choice produces a large
number of data, where we note two things.
• For a given page size, we need to consider only the page number, not the entire address.
• If we have a reference to a page p, then any immediately following references to page p will never
cause a page fault. Page p will be in memory after the first reference; the immediately following
references will not fault.
• For example, consider the following sequence of addresses − 123,215,600,1234,76,96
• If page size is 100, then the reference string is 1,2,6,12,0,0
• Oldest page in main memory is the one which will be selected for replacement.
• Easy to implement, keep a list, replace pages from the tail and add new pages at the head.
Optimal Page algorithm
• An optimal page-replacement algorithm has the lowest page-fault rate of all algorithms. An optimal
page-replacement algorithm exists, and has been called OPT or MIN.
• Replace the page that will not be used for the longest period of time. Use the time when a page is to be
used.
• Page which has not been used for the longest time in main memory is the one which will be selected for
replacement.
• Easy to implement, keep a list, replace pages by looking back into time.
Page Buffering algorithm
• The page with the smallest count is the one which will be selected for replacement.
• This algorithm suffers from the situation in which a page is used heavily during the initial phase of a
process, but then is never used again.
• This algorithm is based on the argument that the page with the smallest count was probably just brought
in and has yet to be used.
COPY-ON-WRITE IN OPERATING SYSTEM:
In this tutorial, we will be covering the Copy on Write which is one of the resource management
techniques.
Copy-on-Write(CoW) is mainly a resource management technique that allows the parent and child process
to share the same pages of the memory initially. If any process either parent or child modifies the shared page,
only then the page is copied.
The CoW is basically a technique of efficiently copying the data resources in the computer system. In this
case, if aunit of data is copied but is not modified then "copy" can mainly exist as a reference to the original
data.
But when the copied data is modified, then at that time its copy is created(where new bytes are actually
written )assuggested from the name of the technique.
The main use of this technique is in the implementation of the fork system call in which it shares the virtual
memory/pages of the Operating system.
Recall in the UNIX(OS), the fork() system call is used to create a duplicate process of the parent process which
isknown as the child process.
• The CoW technique is used by several Operating systems like Linux, Solaris, and Windows XP.
• The CoW technique is an efficient process creation technique as only the pages that are
modified arecopied.
Free pages in this technique are allocated from a pool of zeroed-out pages.
The main intention behind the CoW technique is that whenever a parent process creates a child process both
parent andchild process initially will share the same pages in the memory.
• These shared pages between parent and child process will be marked as copy-on-write which means
that if the parent or child process will attempt to modify the shared pages then a copy of these pages will be
created and the modifications will be done only on the copy of pages by that process and it will not affect other
processes.
Now its time to take a look at the basic example of this technique:
Let us take an example where Process A creates a new process that is Process B, initially both these processes will
sharethe same pages of the memory.
Figure: Above figure indicates parent and child process sharing the same pages
Now, let us assume that process A wants to modify a page in the memory. When the Copy-on-write(CoW) technique is
used, only those pages that are modified by either process are copied; all the unmodified pages can be easily shared by
the parent and child process.
And these free pages are allocated typically when the stack/heap for a process must expand or when there are copy-on-
write pages to manage.
These pages are typically allocated using the technique that is known as Zero-fill-on-demand. And the Zero-fill-on-
demand pages are zeroed-out before being allocated and thus erasing the previous content.
Page fault dominates more like an error. It mainly occurs when any program tries to access the data or
the code that is in the address space of the program, but that data is not currently located in the RAM
of the system.
• So basically when the page referenced by the CPU is not found in the main memory then the
situation is termed as Page Fault.
• Whenever any page fault occurs, then the required page has to be fetched from the secondary
memory into the main memory.
In case if the required page is not loaded into the memory, then a page fault trap arises
The page fault mainly generates an exception, which is used to notify the operating system that it must
have to retrieve the "pages" from the virtual memory in order to continue the execution. Once all the
data is moved into the physical memory the program continues its execution normally. The Page fault
process takes place in the background and thus goes unnoticed by the user.
• The hardware of the computer tracks to the kernel and the program counter (PC) is generally
saved on the [Link] registers store the information of the current state of instruction.
• An assembly program is started that usually saves the general registers and also saves the other
volatile information to prevent the OS from destroying it.
If you will access a page that is marked as invalid then it also causes a Page Fault. Then the Paging
hardware during translating the address through the page table will notice that the invalid bit is set
that will cause a trap to the Operating system.
This trap is mainly the result of the failure of the Operating system in order to bring the desired page
into memory.
Let us understand the procedure to handle the page fault as shown with the help of the above
diagram:
1. First of all, internal table(that is usually the process control block) for this process in order to
determine whether the reference was valid or invalid memory access.
2. If the reference is invalid, then we will terminate the process. If the reference is valid, but we
have not bought in that page so now we just page it in.
3. Then we locate the free frame list in order to find the free frame.
4. Now a disk operation is scheduled in order to read the desired page into the newly allocated
frame.
5. When the disk is completely read, then the internal table is modified that is kept with the
process, and the page table that mainly indicates the page is now in memory.
6. Now we will restart the instruction that was interrupted due to the trap. Now the process can
access the page as though it had always been in memory.
Page Replacement Algorithms in Operating System
In this tutorial, we will be covering the concept of Page replacement and its algorithms in the
Operating system.
As studied in Demand Paging, only certain pages of a process are loaded initially into the memory.
This allows us to get more processes into memory at the same time. but what happens when a process
requests for more pages and no free memory is available to bring them in. Following steps can be
taken to deal with this problem :
1. Put the process in the wait queue, until any other process finishes its execution thereby freeing
frames.
2. Or, remove some other process completely from the memory to free frames.
3. Or, find some pages that are not being used right now, move them to the disk to get free
frames. This technique is called Page replacement and is most commonly used.
In this case, if a process requests a new page and supposes there are no free frames, then the
Operating system needs to decide which page to replace. The operating system must use any page
replacement algorithm in order to select the victim frame. The Operating system must then write the
victim frame to the disk then read the desired page into the frame and then update the page tables.
And all these require double the disk access time.
• Page replacement prevents the over-allocation of the memory by modifying the page-fault
service routine.
• To reduce the overhead of page replacement a modify bit (dirty bit) is used in order to
indicate whether each page is modified.
• This technique provides complete separation between logical memory and physical memory.
Page Replacement in OS
In Virtual Memory Management, Page Replacement Algorithms play an important role. The main
objective of all the Page replacement policies is to decrease the maximum number of page faults.
Page Fault – It is basically a memory error, and it occurs when the current programs attempt to access
the memory page for mapping into virtual address space, but it is unable to load into the physical
memory then this is referred to as Page fault.
1. First of all, find the location of the desired page on the disk.
2. Find a free Frame: a) If there is a free frame, then use it. b) If there is no free frame then make
use of the page-replacement algorithm in order to select the victim frame. c) Then after that
write the victim frame to the disk and then make the changes in the page table and frame table
accordingly.
3. After that read the desired page into the newly freed frame and then change the page and
frame tables.
4. Restart the process.
It is a very simple way of Page replacement and is referred to as First in First Out. This algorithm mainly
replaces the oldest page that has been present in the main memory for the longest time.
• This algorithm is implemented by keeping the track of all the pages in the queue.
• As new pages are requested and are swapped in, they are added to the tail of a queue and the
page which is at the head becomes the victim.
• This is not an effective way of page replacement but it can be used for small systems.
Advantages
Disadvantages
• This algorithm does not make the use of the frequency of last used time rather it just replaces
the Oldest Page.
• There is an increase in page faults as page frames increases.
• The performance of this algorithm is the worst.
This Page Replacement algorithm stands for "Last In First Out".This algorithm works in a similar way to
the LIFO principle.
• In this, the newest page is replaced which is arrived at last in the primary memory
• This algorithm makes use of the stack for monitoring all the pages.
This algorithm stands for "Least recent used" and this algorithm helps the Operating system to search
those pages that are used over a short duration of time frame.
• The page that has not been used for the longest time in the main memory will be selected for
replacement.
• This algorithm is easy to implement.
• This algorithm makes use of the counter along with the even-page.
Advantages of LRU
• It is an efficient technique.
• With this algorithm, it becomes easy to identify the faulty pages that are not needed for a long
time.
• It helps in Full analysis.
Disadvantages of LRU
This algorithm mainly replaces the page that will not be used for the longest time in the future. The
practical implementation of this algorithm is not possible.
• Practical implementation is not possible because we cannot predict in advance those pages that
will not be used for the longest time in the future.
• This algorithm leads to less number of page faults and thus is the best-known algorithm
Also, this algorithm can be used to measure the performance of other algorithms.
Advantages of OPR
Disadvantages of OPR
As indicated from the name this algorithm replaces the page randomly. This Algorithm can work like
any other page replacement algorithm that is LIFO, FIFO, Optimal, and LRU.
THRASHING IN OPERATING SYSTEM
In this tutorial, we will be covering the concept of thrashing in the Operating system.
In case, if the page fault and swapping happens very frequently at a higher rate, then the operating
system has to spend more time swapping these pages. This state in the operating system is termed
thrashing. Because of thrashing the CPU utilization is going to be reduced.
Let's understand by an example, if any process does not have the number of frames that it needs to
support pages in active use then it will quickly page fault. And at this point, the process must
replace some pages. As all the pages of the process are actively in use, it must replace a page that
will be needed again right away. Consequently, the process will quickly fault again, and again, and
again, replacing pages that it must bring back in immediately. This high paging activity by a
process is called thrashing.
During thrashing, the CPU spends less time on some actual productive work spend more time
swapping.
Figure: Thrashing
Causes of Thrashing
Thrashing affects the performance of execution in the Operating system. Also, thrashing results in
severe performance problems in the Operating system.
When the utilization of CPU is low, then the process scheduling mechanism tries to load many
processes into the memory at the same time due to which degree of Multiprogramming can be
increased. Now in this situation, there are more processes in the memory as compared to the
available number of frames in the memory. Allocation of the limited amount of frames to each
process.
Whenever any process with high priority arrives in the memory and if the frame is not freely
available at that time then the other process that has occupied the frame is residing in the frame
will move to secondary storage and after that this free frame will be allocated to higher priority
process.
We can also say that as soon as the memory fills up, the process starts spending a lot of time for
the required pages to be swapped in. Again the utilization of the CPU becomes low because most
of the processes are waiting for pages.
Thus a high degree of multiprogramming and lack of frames are two main causes of thrashing in
the Operating system.
Effect of Thrashing
At the time, when thrashing starts then the operating system tries to apply either the Global page
replacement Algorithm or the Local page replacement algorithm.
The Global Page replacement has access to bring any page, whenever thrashing found it tries to
bring more pages. Actually, due to this, no process can get enough frames and as a result, the
thrashing will increase more and more. Thus the global page replacement algorithm is not suitable
whenever thrashing happens.
Unlike the Global Page replacement, the local page replacement will select pages which only
belongs to that process. Due to this, there is a chance of a reduction in the thrashing. As it is also
proved that there are many disadvantages of Local Page replacement. Thus local page replacement
is simply an alternative to Global Page replacement.
As we have already told you the Local Page replacement is better than the Global Page
replacement but local page replacement has many disadvantages too, so it is not suggestible. Thus
given below are some other techniques that are used:
Working-Set Model
This model is based on the assumption of the locality. It makes the use of the parameter ? in order
to define the working-set window. The main idea is to examine the most recent? page reference.
What locality is saying, the recently used page can be used again, and also the pages that are
nearby this page will also be used?
1. Working Set
The set of the pages in the most recent? page reference is known as the working set. If a page is in
active use, then it will be in the working set. In case if the page is no longer being used then it will
drop from the working set ? times after its last reference.
The working set mainly gives the approximation of the locality of the program.
The accuracy of the working set mainly depends on? what is chosen?
This working set model avoids thrashing while keeping the degree of multiprogramming as high as
possible.
2. Page Fault Frequency
The working-set model is successful and its knowledge can be useful in preparing but it is a very
clumpy approach in order to avoid thrashing. There is another technique that is used to avoid
thrashing and it is Page Fault Frequency(PFF) and it is a more direct approach.
The main problem is how to prevent thrashing. As thrashing has a high page fault rate and also we
want to control the page fault rate.
When the Page fault is too high, then we know that the process needs more frames. Conversely, if
the page fault-rate is too low then the process may have too many frames.
We can establish upper and lower bounds on the desired page faults. If the actual page-fault rate
exceeds the upper limit then we will allocate the process to another frame. And if the page fault
rate falls below the lower limit then we can remove the frame from the process.
Thus with this, we can directly measure and control the page fault rate in order to prevent
thrashing.
UNIT IV STORAGE MANAGEMENT
Mass Storage system – Disk Structure - Disk Scheduling and Management; File-System Interface - File
concept - Access methods - Directory Structure - Directory organization - File system mounting - File
Sharing and Protection; File System Implementation - File System Structure - Directory implementation -
Allocation Methods - Free Space Management; I/O Systems – I/O Hardware, Application I/O interface,
Kernel I/O subsystem.
Now, we are going to learn about each and every mass storage device in detail. But before learning about them let
us know about what is a primary and secondary memory.
Primary Memory
A processor or computer initially or directly accesses primary memory while using a computer. It enables a
processor to access programs and services that are now in use and temporarily stored in a particular area of
memory.
Primary storage and main memory are the other terms which can be used as a substitute to the term primary
memory.
The volatile storage component of a computer system is primary memory. Although there may be data buses,
cache memory, or Random Access Memory (RAM), RAM is the most common example for primary memory.
An operating system (OS), user interface, and any user-installed and running software utilities are all loaded into
main memory as soon as a computer turns on. When a program or application is launched from main memory, it
communicates with the system processor to carry out all of its unique functions.
Secondary memory is said to be slower than primary memory.
Secondary Memory
Secondary memory is non-volatile, permanent computer memory that is not directly accessible by a computer or
processor. Data that can be quickly and easily retrieved, transmitted, and utilized by apps and services can be
stored by the user and then used in this manner.
Secondary storage is another name which can be used as a substitute to the word secondary memory.
Read-only memory (ROM), flash drives, hard disk drives (HDD), magnetic tapes, and other forms of internal and
external storage media are all considered secondary memory. Only the major or main memory may access
secondary memory during computations, and only then is it sent to the processor.
Even if the computer is not powered on, data can be stored and retained in secondary memory, which is slower
than primary memory. Additionally, it has large storage capacity, with each memory being capable of holding
anywhere from a few megabytes (MB) to many terabytes (TB).
Secondary memory is said to be slower than primary memory.
All the mass storage media belongs to the secondary memory.
1.) Primary Memory is also primarily known as main Secondary Memory is also primarily
memory or primary storage memory known as secondary memory storage
2.) They are also known as Internal Memory They are also known as Auxiliary Memory
or Backup Memory or Additional Memory.
3.) Primary Memory is more costlier than Secondary Memory Secondary Memory is less costlier than
Secondary Memory
4.) Primary memory is said to be faster than Secondary Secondary memory is said to be slower
memory. than primary memory.
5.) It stores information or data that the processing unit is It has a substantial amount of information
currently using. Usually, capacity ranges from sixteen and data storage. Typically, capacity
Giga Bytes (16 GB) to Thirty Two Giga Bytes (32 GB). ranges from 200 GB to terabytes.
6.) The Primary Memory can be divided as Volatile and Non The Secondary Memory can only be
Volatile Memories classified as Non Volatile Memory only.
7.) Data cannot be preserved in the event of a power outage Because it has a non-volatile memory, the
since it is a volatile memory. information may be kept even in the event
of a power outage.
Now, let us learn about the types of the Mass Storage Media which are present in the market.
Mass Storage Structure
Systems designed to store enormous volumes of data are referred to as mass storage devices. Massive storage
devices are sometimes used interchangeably with peripheral storage, which is the management of bigger volumes
of data that are larger than the native storage capability of a computer or device.
The basic idea of Mass Storage is to create a Data Backup or Data Recovery System.
Along with computer systems, definitions of mass storage technologies and tactics have changed. The earliest and
most basic mass storage techniques date back to the era of main frame supercomputers, according to experts.
Punch cards, Hollerith cards, and other relatively similar manual storage medium are examples of this Mass
Storage Media these days. Today, mass storage may include several kinds of hard disks or solid-state storage
devices, as well as tape drives and other physical data storage devices.
The concepts of data backup and data recovery are frequently linked to mass storage media. The biggest Business
Companies will make plans for recording, storing, and backing up all accessible data, which calls for a lot more
mass storage media than what factory-direct gear can provide. This suggests a method for handling continuous
mass storage that uses tape or other media. Other kinds of mass storage could function well as a data storage plan
for a big network or a bunch of mobile distant devices. To backup data on a portable tablet that doesn't have a lot
of internal capacity, for instance, mass storage for a tablet might require the usage of flash or Universal Serial Bus
media (USB Media).
The Mass Storage Structure Devices are:
1. Magnetic Disks
2. Solid State Disks
3. Magnetic Tapes
Magnetic Disks
Now, we are going to know about all whereabouts of the Magnetic Disk Mass Storage Structure Devices.
The process of magnetization is used to write, rewrite, and access data on a magnetic disk, a storage device. This
process is known as Magnetic Disk. It is coated magnetically and has tracks, spots, and sectors for storing data.
In 1956, IBM created the first magnetic hard drive, a substantial device with 50 21-inch (53-cm) platters. Despite
being large, it could only hold 5 megabytes of information. Since then, magnetic disks' storage capabilities have
multiplied dramatically while simultaneously shrinking in size.
Basic Common Examples of Magnetic Disks are:
1. Floppy Disks
2. Hard Disks
3. Zip Disks
Disk Structure in OS
Disk structure is as shown in following figure
Step wise description of Disk Structure is given below
● Disk surfacе dividеd into tracks
● A rеad/writе hеad positionеd just abovе thе disk surfacе
● Information storеd by magnеtic rеcording on thе track undеr rеad/writе hеad
● Fixеd hеad disk
● Moving hеad disk
● Dеsignеd for largе amount of storagе
● Primary dеsign considеration cost, sizе, and spееd
Hardwarе for disk systеm
● Disk drivе, Dеvicе motor, Rеad/writе hеad, Associatеd logic
Disk controllеr
● Dеtеrminеs thе logical intеraction with thе computеr
● Can sеrvicе morе than onе drivе (ovеrlappеd sееks)
Cylindеr
● Thе samе numbеrеd tracks on all thе disk surfacеs
● Еach track contains bеtwееn 8 to 32 sеctors
Sеctor
● Smallеst unit of information that can bе rеad from/writtеn into disk
● Rangе from 32 bytеs to 4096 bytеs
Disk Performance Parameters
Some important parameters used to measure the performance of hard disk are as follow
Sееk timе
● Seek Timе is time rеquirеd by rеad/writе hеad to movе to rеquеstеd track
● Includеs thе initial startup timе and thе timе rеquirеd to travеrsе thе tracks to bе crossеd oncе thе
accеss arm is up to spееd.
Latеncy or rotational dеlay
● Timе rеquirеd for thе rеquеstеd sеctor to comе undеr thе rеad/writе hеad.
● Rotational delay is generally the half of the time taken in one rotation.
Data Transfer Rate
Data transfer rate is define as the amount of data transfer in per unit time for example 30 MB/Sec.
Data Transfer Time
Data Transfer time is the total time taken to transfer a specific amount of data from the disk. Data
Transfer time depends on the data transfer rate of the disk.
Average Access Time
Average access time is calculated as
Average Access Time = Seek Time + Rotational Latecny + Data Transfer Time
Disk scheduling and management are essential components of a computer's operating system that handle
the organization and access of data on a disk. Disk scheduling algorithms determine the order in which
the read/write head of the disk moves to access data, which impacts the efficiency and speed of accessing
data. Some commonly used disk scheduling algorithms include First-Come-First-Serve, Shortest Seek
Time First, and SCAN. Disk management, on the other hand, involves tasks such as disk partitioning,
formatting, and file system creation. It ensures that the disk is properly utilized, optimized for
performance, and maintained to prevent data loss or corruption. Efficient disk scheduling and
management are crucial for ensuring the smooth and effective operation of a computer system.
Types of Disk Scheduling Algorithms
● First-Come, First-Served (FCFS) − The FCFS algorithm is the simplest disk scheduling
algorithm, in which the requests are processed in the order they arrive. It is a nonpreemptive
algorithm that does not take into account the distance between the current request and the next
request.
● Shortest Seek Time First (SSTF) − The SSTF algorithm processes the request with the shortest
seek time, i.e., the request that requires the least amount of movement by the disk's head. This
algorithm can minimize the head movement, but it may result in starvation of some requests.
● SCAN − The SCAN algorithm processes the requests in a specific direction, either from the
innermost track to the outermost track or vice versa. After reaching the end of the disk, the head
reverses direction and processes the requests in the opposite direction. This algorithm provides a
balance between the number of requests processed and the time each request waits.
● C-SCAN − The C-SCAN algorithm is similar to the SCAN algorithm, but the head moves only in
one direction and processes requests only in that direction. When it reaches the end of the disk, it
immediately returns to the beginning of the disk and starts processing requests again. This
algorithm can eliminate the possibility of starvation.
● LOOK − The LOOK algorithm is similar to the SCAN algorithm, but the head reverses direction
when it reaches the last request in the current direction. This algorithm can reduce the waiting
time for requests that are close to the head's current position.
● C-LOOK − The C-LOOK algorithm is similar to the C-SCAN algorithm, but the head reverses
direction when it reaches the last request in the current direction. This algorithm can reduce the
waiting time for requests that are close to the head's current position and eliminate the possibility
of starvation.
Evaluation Criteria for Disk Scheduling Algorithms
● Throughput − Throughput is the number of input/output operations that can be processed per
unit time. A disk scheduling algorithm with high throughput can process more requests in a
shorter time, resulting in higher system performance.
● Turnaround time − Turnaround time is the time taken to process a request from the time it is
submitted to the time it is completed. A disk scheduling algorithm with a low turnaround time can
provide faster service to the users.
● Waiting time − Waiting time is the time that a request spends waiting in the queue before it is
processed. A disk scheduling algorithm with a low waiting time can provide faster service to the
users.
● Response time − Response time is the time taken to provide the first response to a user's request.
A disk scheduling algorithm with a low response time can provide faster service to the users.
● Fairness − Fairness refers to the equal treatment of all requests in the queue. A disk scheduling
algorithm that provides fair treatment to all requests can ensure that no request is starved of
resources.
Selection of Disk Scheduling Algorithm
● Deterministic − In deterministic disk scheduling, the algorithm is selected based on the
characteristics of the workload. For example, if the workload consists of short requests, the SSTF
algorithm may be the best choice.
● Dynamic − In dynamic disk scheduling, the algorithm is selected based on the current state of the
system. For example, if the disk is heavily loaded, the operating system may switch to a more
efficient algorithm to handle the increased workload. Dynamic disk scheduling can adapt to
changes in the workload and improve system performance.
The selection of the disk scheduling algorithm depends on several factors, including the characteristics of
the workload, system performance requirements, and the available resources. The operating system must
evaluate the different disk scheduling algorithms based on the evaluation criteria and select the algorithm
that best meets the system's requirements.
Advantages
● Improved performance − Disk scheduling algorithms ensure that data is accessed in the most
efficient manner possible, which improves the performance of the system.
● Fairness − Disk scheduling algorithms ensure that all requests for data access are treated fairly
and given a chance to be processed.
● Reduced disk fragmentation − Disk scheduling algorithms can help to reduce disk
fragmentation by accessing data in a more organized manner.
Disadvantages
● Overhead − Disk scheduling algorithms can create overhead and delay in processing data access
requests, which can reduce overall system performance.
● Complexity − Some disk scheduling algorithms can be complex and difficult to understand,
which may make it difficult to optimize system performance.
● Risk of starvation − Disk scheduling algorithms can result in starvation of certain requests,
which can lead to inefficiencies and reduced system performance.
Disk Management
Disk management is the process of organizing, optimizing, and maintaining data on a disk within a
computer system. It involves tasks such as disk partitioning, formatting, and file system creation to
ensure efficient use of disk space, prevent data loss, and improve system performance. Proper disk
management is crucial for preventing issues such as disk failure, fragmentation, and data corruption. By
allocating space to files and creating a file system, disk management helps to organize data and improve
the efficiency and speed of accessing it.
Techniques for Disk Management
● File Allocation Table (FAT) − FAT is a file system used by many operating systems, including
Windows and some versions of Linux. It uses a table to keep track of the location of files on the
disk, and it supports long file names and basic file security features.
● New Technology File System (NTFS) − NTFS is a file system used by Windows operating
systems that offers advanced features, including file compression, encryption, and disk quotas. It
also provides better performance and reliability compared to FAT.
● Unix File System (UFS) − UFS is a file system used by Unix and Unix-like operating systems,
including Linux and macOS. It supports features such as file permissions, symbolic links, and
journaling, which provides faster recovery from disk errors.
● ZFS − ZFS is a file system used by some operating systems, including FreeBSD and OpenSolaris.
It provides advanced features such as data compression, snapshotting, and automatic repair of
data errors.
● Disk Quotas − Disk quotas are used to limit the amount of disk space that a user or group can
use. This helps to prevent one user from monopolizing disk space and can improve system
performance and reliability.
Disk Optimization Techniques
● Defragmentation − Defragmentation is the process of rearranging files on the disk to reduce
fragmentation, which can slow down disk access times. Defragmentation can improve disk
performance and extend the life of the disk.
● Compression − Compression is the process of reducing the size of files to save disk space. It can
be used to compress files that are not frequently accessed, such as archives or backups.
Compression can improve disk utilization and reduce storage costs.
● Encryption − Encryption is the process of encoding data to prevent unauthorized access. It can
be used to protect sensitive data, such as financial or personal information. Encryption can
improve data security and prevent data breaches.
Advantages
● Data organization − Disk management helps to organize data on a disk by allocating space to
files and creating a file system. This improves the efficiency and speed of accessing data.
● Prevent data loss − Disk management includes features such as disk partitioning, formatting, and
backup. This helps to prevent data loss and recover lost data in the event of disk failure or other
issues.
● Optimized performance − Proper disk management ensures that the disk is optimized for
performance, which improves the speed and efficiency of data access.
Disadvantages
● Complexity − Disk management can be complex and difficult to understand, especially for
novice users. This can result in errors or improper disk configurations that may cause data loss or
corruption.
● Time-consuming − Disk management tasks such as disk partitioning and formatting can be time-
consuming, especially for large disks or complex configurations.
● Risk of data loss − Improper disk management can result in data loss or corruption, which can be
difficult or impossible to recover.
[Link]-SYSTEM INTERFACE
For the majority of users, the file system is the most obvious aspect of any operating system.
This provides users the method for storage and access to data as well as programs of the
operating system where all the users of the computer system can use it.
The file system consists of 2 distinct parts:
● a collection of files, that store related data, and
● a directory structure, which organizes and provides information about all the files in the
system.
In this chapter, you will learn about the different file tribute, concepts of file and its storage
along with operations on files.
File Attributes
A file is named, for the ease of its users and is referred by its name. A name is usually a string of
characters like [Link], along with an extension which designates the file format. Some
systems (like Linux) distinguish between uppercase and lowercase characters in names, whereas
other systems don't. When a file is given a name, it becomes independent of the process, the user
and also the system which created it. Let's suppose, one user might make the file [Link],
and another user might be editing that file by deducing its name. The file's owner may write the
file to a compact disk (CD) or send it via an e-mail or copy it across a network, and it could still
be called [Link] on the destination system.
Fundamental Components of A File
A file's attributes vary from one operating system to another but typically consist of these:
● Name: Name is the symbolic file name and is the only information kept in human
readable form.
● Identifier: This unique tag is a number that identifies the file within the file system; it is
in non-human-readable form of the file.
● Type: This information is needed for systems which support different types of files or its
format.
● Location: This information is a pointer to a device which points to the location of the file
on the device where it is stored.
● Size: The current size of the file (which is in bytes, words, etc.) which possibly the
maximum allowed size gets included in this attribute.
● Protection: Access-control information establishes who can do the reading, writing,
executing, etc.
● Date, Time & user identification: This information might be kept for the creation of the
file, its last modification and last used. These data might be useful for in the field of
protection, security, and monitoring its usage.
File operations
A file is an abstract data type. For defining a file properly, we need to consider the operations
that can be performed on files. The operating system can provide system calls to create, write,
read, reposition, delete, and truncate files. There are six basic file operations within an Operating
system. These are:
● Creating a file: There are two steps necessary for creating a file. First, space in the file
system must be found for the file. We discuss how to allocate space for the file. Second,
an entry for the new file must be made in the directory.
● Writing a file: To write to a file, you make a system call specify about both the name of
the file along with the information to be written to the file.
● Reading a file: To read from a file, you use a system call which specifies the name of the
file and where within memory the next block of the file should be placed.
● Repositioning inside a file: The directory is then searched for the suitable entry, and the
'current-file-position' pointer is relocating to a given value. Relocating within a file need
not require any actual I/O. This file operation is also termed as 'file seek.'
● Deleting a file: For deleting a file, you have to search the directory for the specific file.
Deleting that file or directory release all file space so that other files can re-use that
space.
● Truncating a file: The user may wish for erasing the contents of a file but keep the
attributes same. Rather than deleting the file and then recreate it, this utility allows all
attributes to remain unchanged — except the file length — and let the user add or edit the
file content.
4.8. FILE SYSTEM MOUNTING
Just as a file must be opened before it is used, a file system must be mounted before it can be
available to processes on the system. More specifically, the directory structure can be built out of
multiple volumes, which must be mounted to make them available within the file-system name
space. The mount procedure is straightforward. The operating system is given the name of the
device and the mount point—the location within the file structure where the file system is to be
attached. Typically, a mount point is an empty directory.
For instance, on a UNIX system, a file system containing a user's home directories might be
mounted as /home; then, to access the directory structure within that file system, we could
precede the directory names with ftiome, as in /homc/janc. Mounting that file system under
/users would result in the path name /users/jane, which we could use to reach the same directory.
Next, the operating system verifies that the device contains a valid file system. It does so by
asking the device driver to read the device directory and verifying that the directory has the
expected format. Finally, the operating system notes in its directory structure that a file system is
mounted at the specified mount point. This scheme enables the operating system to traverse its
directory structure, switching among file systems as appropriate. To illustrate file mounting,
consider the file system depicted in Figure 10.12, where the triangles represent subtrees of
directories that are of interest. Figure 10.12(a) shows an existing file system, while Figure
10.12(b) shows an unmounted volume residing on /device'/dsk.
At this point, only the files on the existing file system can be accessed. Figure 10.13 shows the
effects of mounting the volume residing on /device/dsk over /users. If the volume is unmounted,
the file system is restored to the situation depicted in Figure 10.12.
Systems impose semantics to clarify functionality. For example, a system may disallow a mount
over a directory that contains files; or it may make the mounted file system available at that
directory and obscure the directory's existing files until the file system is unmounted, terminating
the use of the file system and allowing access to the original files in that directory.
As another example, a system may allow the same file system to be mounted repeatedly, at
different mount points; or it may only allow one mount per file system. Consider the actions of
the Macintosh operating system. Whenever the system encounters a disk for the first time (hard
disks are found at boot time, and floppy disks are seen when they are inserted into the drive), the
Macintosh operating system searches for a file system on the device. If it finds one, it
automatically mounts the file system at the root level, adding a folder icon on the screen labeled
with the name of the file system (as stored in the device directory). The user is then able to click
on the icon and thus display the newly motinted file system. The Microsoft Windows family of
operating systems (95, 98, NT, small 2000, XP) maintains an extended two-level directory
structure, with devices and volumes assigned drive letters.
Volumes have a general graph directory structure associated with the drive letter. The path to a
specific file takes the form of drive-letter;\path\to\file. The more recent versions of Windows
allow a file system to he mounted anywhere in the directory tree, just as UNIX does. Windows
operating systems automatically discover all devices and mount all located file systems at boot
time. In some systems, like UNIX, the mount commands are explicit. A system configuration file
contains a list of devices and mount points for automatic mounting at boot time, but other
mounts may be executed manually.
File sharing is the practice of distributing or providing access to digital files between two or
more users or devices. While it is a convenient way to share information and collaborate on
projects, it also comes with risks such as malware and viruses, data breaches, legal
consequences, and identity theft. Protecting files during sharing is essential to ensure
confidentiality, integrity, and availability. Encryption, password protection, secure file transfer
protocols, and regularly updating antivirus and anti-malware software are all important measures
that can be taken to safeguard files. This article will explore the different types of file sharing,
risks associated with file sharing, protection measures, and best practices for secure file sharing.
Advantages:
● This is very flexible in terms of file size. File size can be increased easily since the
system does not have to look for a contiguous chunk of memory.
● This method does not suffer from external fragmentation. This makes it relatively better
in terms of memory utilization.
Disadvantages:
● Because the file blocks are distributed randomly on the disk, a large number of seeks are
needed to access every block individually. This makes linked allocation slower.
● It does not support random or direct access. We can not directly access the blocks of a
file. A block k of a file can be accessed by traversing k blocks sequentially (sequential
access ) from the starting block of the file via block pointers.
● Pointers required in the linked allocation incur some extra overhead.
3. Indexed Allocation
In this scheme, a special block known as the Index block contains the pointers to all the blocks
occupied by a file. Each file has its own index block. The ith entry in the index block contains
the disk address of the ith file block. The directory entry contains the address of the index block
as shown in the image:
Advantages:
● This supports direct access to the blocks occupied by the file and therefore provides fast
access to the file blocks.
● It overcomes the problem of external fragmentation.
Disadvantages:
● The pointer overhead for indexed allocation is greater than linked allocation.
● For very small files, say files that expand only 2-3 blocks, the indexed allocation would
keep one entire block (index block) for the pointers which is inefficient in terms of
memory utilization. However, in linked allocation we lose the space of only 1 pointer per
block.
For files that are very large, single index block may not be able to hold all the pointers.
Following mechanisms can be used to resolve this:
1. Linked scheme: This scheme links two or more index blocks together for holding the
pointers. Every index block would then contain a pointer or the address to the next index
block.
2. Multilevel index: In this policy, a first level index block is used to point to the second
level index blocks which inturn points to the disk blocks occupied by the file. This can be
extended to 3 or more levels depending on the maximum file size.
3. Combined Scheme: In this scheme, a special block called the Inode (information
Node) contains all the information about the file such as the name, size, authority, etc and
the remaining space of Inode is used to store the Disk Block addresses which contain the
actual file as shown in the image below. The first few of these pointers in Inode point to
the direct blocks i.e the pointers contain the addresses of the disk blocks that contain
data of the file. The next few pointers point to indirect blocks. Indirect blocks may be
single indirect, double indirect or triple indirect. Single Indirect block is the disk block
that does not contain the file data but the disk address of the blocks that contain the file
data. Similarly, double indirect blocks do not contain the file data but the disk address
of the blocks that contain the address of the blocks containing the file data.
UNIT V
Virtual Machines – History, Benefits and Features, Building Blocks, Types of Virtual
Machines and their Implementations, Virtualization and Operating-System Components;
Mobile OS – iOS and Android.
1. Virtual Machines
Virtual Machine abstracts the hardware of our personal computer such as CPU, disk
drives, memory, NIC (Network Interface Card) etc, into many different execution
environments as per our requirements, hence giving us a feel that each execution environment
is a single computer. For example, Virtual Box.
When we run different processes on an operating system, it creates an illusion that each
process is running on a different processor having its own virtual memory, with the help of
CPU scheduling and virtual-memory techniques. There are additional features of a process that
cannot be provided by the hardware alone like system calls and a file system. The virtual
machine approach does not provide these additional functionalities but it only provides an
interface that is same as basic hardware. Each process is provided with a virtual copy of the
underlying computer system.
virtual machine for several reasons, all of which are fundamentally related to the ability
to share the same basic hardware yet can also support different execution environments, i.e.,
different operating systems simultaneously.
The main drawback with the virtual-machine approach involves disk systems. Let us
suppose that the physical machine has only three disk drives but wants to support seven virtual
machines. Obviously, it cannot allocate a disk drive to each virtual machine, because virtual-
machine software itself will need substantial disk space to provide virtual memory and
spooling. The solution is to provide virtual disks.
Users are thus given their own virtual machines. After which they can run any of the
operating systems or software packages that are available on the underlying machine. The
virtual-machine software is concerned with multi-programming multiple virtual machines onto
a physical machine, but it does not need to consider any user-support software. This
arrangement can provide a useful way to divide the problem of designing a multi-user
interactive system, into two smaller pieces.
Advantages:
1. There are no protection problems because each virtual machine is completely isolated from
all other virtual machines.
2. Virtual machine can provide an instruction set architecture that differs from real computers.
3. Easy maintenance, availability and convenient recovery.
Disadvantages:
1. When multiple virtual machines are simultaneously running on a host computer, one virtual
machine can be affected by other running virtual machines, depending on the workload.
2. Virtual machines are not as efficient as a real one when accessing the hardware.
1. System Virtual Machine: These types of virtual machines gives us complete system
platform and gives the execution of the complete virtual operating system. Just like virtual
box, system virtual machine is providing an environment for an OS to be installed
completely. We can see in below image that our hardware of Real Machine is being
distributed between two simulated operating systems by Virtual machine monitor. And then
some programs, processes are going on in that distributed hardware of simulated
machines separately
.
3. Process Virtual Machine: While process virtual machines, unlike system virtual machine,
does not provide us with the facility to install the virtual operating system completely.
Rather it creates virtual environment of that OS while using some app or program and this
environment will be destroyed as soon as we exit from that app. Like in below image, there
are some apps running on main OS as well some virtual machines are created to run other
apps. This shows that as those programs required different OS, process virtual machine
provided them with that for the time being those programs are running. Example – Wine
software in Linux helps to run Windows applications.
4.
2. HISTORY OF VIRTUAL MACHINES
The concept of virtual machines (VMs) can be traced back to the 1960s when IBM
introduced the concept of time-sharing on its mainframe computers. Time-sharing allowed multiple
users to simultaneously access a single computer, but it required each user tohave their own virtual
machine, which would run its own operating system and applications.
The first true virtual machine, however, was developed in the early 1970s by a team of
researchers at IBM led by Gerald Popek and Robert Goldberg. Their system, called CP-67/CMS,
allowed multiple instances of the IBM System/360 operating system to run simultaneously on a
single mainframe computer.
In the 1980s and 1990s, virtualization technology continued to evolve, with companies
such as DEC and Sun Microsystems developing their own virtual machine software. However, it
wasn't until the early 2000s that virtualization became mainstream, thanks in large part to the
development of the x86 architecture and the introduction of hardware-assisted virtualization
technologies such as Intel VT and AMD-V.
Today, virtual machines are used in a wide variety of applications,from server consolidation
and cloud computing to software development and testing. In recent years, containerization has
emerged as a popular alternative to traditional virtualization, butvirtual machines remain a critical
component of the modern computing landscape.
• Lower hardware costs. Many organizations don’t fully utilize their hardware
resources. Instead of investing in another server, organizations can spin up virtual
servers instead.
• Quicker Desktop Provisioning and Deployment. Deploying a new physical server
often takes numerous time-consuming steps. However, with virtualized systems,
organizations can deploy new virtual servers quickly using secure pre-configured server
templates.
• Smaller Footprint. Utilizing virtualization reduces the office space needed to maintain
and extend IT capabilities while also freeing up desk space to support more employees.
• Enhanced Data Security. Virtualization streamlines disaster recovery by replicating
your servers in the cloud. Since VMs are independent of the underlying hardware,
organizations don’t need the same physical servers offsite to facilitate a secondary
recovery site. In the event of a disaster, employees can be back online quickly with a
cost-effective backup and disaster recovery solution.
• Portability. It’s possible to seamlessly move VMs across virtual environments and
even from one physical server to another, with minimal input on the part of IT teams.
VMs are isolated from one another and have their own virtual hardware, making them
hardware-independent. Moving physical servers to another location is a more resource-
intensive task.
• Improved IT Efficiency. Many IT departments spend at least half of their time
managing routine administrative tasks, however with virtualization it’s possible to
partition one physical server into several virtual machines—administrators can deploy
and manage multiple operating systems at once from a single physical server.
• When simultaneous VMs run on a host computer, each can introduce an unstable performance
depending on the workload of the system.
• Licensing models of virtualization solutions can be tricky. They can result in huge upfront
investment costs due to additional hardware requirements.
• Due to the increasingly high number of breaches on VM and cloud deployments, security is an
added concern.
• For every virtualization solution, the infrastructure setup is complex. Small businesses have to
hire experts to deploy these solutions successfully.
• VMs pose data security threats when multiple users try to access the same or different VMs on
the same physical host.
• Isolation: Each VM is completely isolated from other VMs and the host operating
system, providing a secure environment for running applications.
• Hardware independence: Virtual machines can run on any hardware platform, as long as
the host system provides the necessary resources.
• Software compatibility: Virtual machines can run different operating systems and
software, making them useful for testing and developmentpurposes.
• Snapshots: Virtual machines can take snapshots of the current state of thesystem,
allowing for easy rollback in case of software or configuration issues.
• Resource allocation: Resources such as CPU, memory, and storage canbe allocated
to each VM individually, allowing for efficient use of the underlying hardware.
• Mobility: Virtual machines can be easily moved between physical hosts, making them
useful for disaster recovery and workload balancing.
• Scalability: Virtual machines can be easily created and removed, allowing for flexible
scaling of IT resources.
Overall, virtual machines provide a highly flexible and efficient way to run multiple
operating systems and applications on a single physical machine.
BUILDING BLOCKS OF VIRTUAL MACHINES
Virtual machines (VMs) are essentially software that emulates a computer system within
another computer system. The building blocks of virtual machines include:
• Hypervisor: The hypervisor is the software layer that creates and manages
virtual machines. It is also known as a virtual machine monitor (VMM). The
hypervisor manages the physical resources of the host computer, such as CPU,
memory, and disk space, and allocates them to virtual machines.
• Virtual Disk: A virtual disk is a file that is used to store the virtual machine's operating
system, applications, and data. The virtual disk is mapped to physical storage on the
host computer.
Overall, virtualization technology has revolutionized the way computing resources are
managed and utilized, providing organizations with greaterflexibility, scalability, and
efficiency.
COMPONENTS OF OS
An operating system is a large and complex system that can only be created by
partitioning into small parts. These pieces should be a well-defined part of the system,
carefully defining inputs, outputs, and functions.
Although Windows, Mac, UNIX, Linux, and other OS do not have the same
structure, most operating systems share similar OS system components, such as
file, memory, process, I/O device management.
The components of an operating system play a key role to make a variety of computer
system parts work together. There are the following components of an operating system,
such as:
• Process Management
• File Management
• Network Management
• Security Management
Operating system components help you get the correct computing bydetecting CPU
and memory hardware errors.
PROCESSMANAGEMENT
• For example, when you use a search engine like Chrome, there is aprocess running for that
browser program.
•
FUNCTIONS OF PROCESS MANAGEMENT
• Here are the following functions of process management in theoperating system, such
as:
• Synchronization process
• Communication process
FILEMANAGEMENT
programs (both source and object forms) anddata. Data files can be alphabetic, numeric, or
alphanumeric.
Process scheduling is essential for multitasking as it determines which process runs when and for how long, allowing multiple processes to share CPU time effectively. In preemptive scheduling, the operating system can interrupt and switch the current running process if a higher priority process comes along, facilitating better responsiveness and CPU utilization. Examples include Round Robin and Priority Scheduling. Non-preemptive scheduling, however, does not interrupt running processes until they complete or reach a waiting state, making it simpler but potentially less efficient, as seen in First-Come, First-Served scheduling .
Paging reduces external fragmentation since memory is divided into fixed-size pages. However, it introduces internal fragmentation because the fixed pages may not correspond perfectly with the process needs. On the other hand, segmentation allows for logical division based on program needs, minimizing internal fragmentation but may introduce external fragmentation due to variable segment sizes. Paging is simple to implement and supports efficient memory usage, while segmentation aligns better with the user's logical view of memory. A key disadvantage of paging is the memory overhead required for maintaining page tables, which can be substantial. Segmentation requires more complex hardware to support different memory sizes and base addresses .
Page tables are central to paging as they map logical addresses to physical memory addresses, enabling virtual memory. They facilitate address translation by storing the frame number where each page resides. Page tables need to be efficient because they are accessed frequently during memory operations. Multi-level page tables reduce the size of page tables and virtual memory overhead by organizing pages hierarchically, making it possible to handle large address spaces more efficiently .
File sharing can lead to data breaches, malware infections, and unauthorized access, potentially causing intellectual property loss, financial damage, and reputational harm. To mitigate these risks, important protective measures include using strong encryption, rigorous access controls, and secure file transfer protocols. Regular updates of antivirus and anti-malware programs are essential, along with user education on safe file sharing practices and ensuring that file access is limited to authorized users .
Hierarchical page tables break large page tables into multiple levels, making them suitable for systems with vast address spaces, reducing the memory requirement for page tables. Hashed page tables use a hash table to map virtual to physical addresses efficiently, ideal for sparse address spaces. Inverted page tables store a single entry for each physical page frame, which reduces memory usage for page tables significantly at the cost of slower lookups due to the need for searching. Each technique optimizes different aspects of efficiency, depending on memory size and usage complexity .
The Process Control Block (PCB) is essential for managing processes as it maintains all necessary process-specific information, including the process state, program counter, CPU register content, memory management information, and I/O status. It helps the operating system keep track of process execution history and manage context switching efficiently when a process transitions between states. The PCB acts as a repository for data that can be used to restore the state of a process when it resumes execution, ensuring that resources are adequately managed and that the process runs smoothly .
Semaphores are synchronization tools that manage concurrent process access to shared resources, preventing race conditions and ensuring process synchronization. They use a signaling mechanism to coordinate processes, often implemented via wait and signal operations that adjust a counter indicating resource availability. The main issues semaphores address are critical section management and deadlock prevention, allowing multiple processes to cooperate safely without simultaneously modifying shared data or waiting indefinitely for resources .
Demand paging loads pages into memory only when they are needed, minimizing the pages held in memory at any time, which reduces memory usage and increases efficiency. This approach contrasts with pre-paging, where pages are loaded in anticipation of their need, which could lead to unnecessary memory usage if predictions are inaccurate. The advantages of demand paging include reduced memory footprint, ability to run large programs with limited physical memory, and more efficient memory usage. However, it can incur a performance hit due to page fault handling when pages are not found in memory .
Deadlock occurs when a group of processes become stuck waiting for each other to release resources, leading to a situation where no progress is possible. Various methods for handling deadlocks include prevention (ensuring at least one necessary condition for deadlock cannot hold), avoidance (dynamically managing resource allocation to prevent deadlock), detection (identifying and resolving deadlocks once they occur), and recovery (taking action such as process termination or resource preemption to resolve detected deadlocks). Each method has its trade-offs in terms of complexity and resource usage .
Multithreaded processes allow different parts of a program to run concurrently, improving performance by utilizing system resources more efficiently. In a multithreaded environment, each thread can handle a specific task, sharing the same process resources like memory and files, reducing the overhead associated with process creation and context switching. This can improve responsiveness, particularly in applications like web servers, where multiple threads handle separate client requests simultaneously, thus improving throughput and reducing latency .