Nothing Special   »   [go: up one dir, main page]

CS Oss 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 82

OPERATING SYSTEMS AND SECURITY

UNIT 3
3.1 Main memory
The term memory can be defined as a collection of data in a specific format. It is used to
store instructions and process data. The memory comprises a large array or group of
words or bytes, each with its own location. The primary purpose of a computer system is
to execute programs. These programs, along with the information they access, should be
in the main memory during execution. The CPU fetches instructions from memory
according to the value of the program counter.
To achieve a degree of multiprogramming and proper utilization of memory, memory
management is important. Many memory management methods exist, reflecting various
approaches, and the effectiveness of each algorithm depends on the situation.
Before we start Memory management, let us know what is main memory is.
What is Main Memory?
The main memory is central to the operation of a Modern Computer. Main Memory is a
large array of words or bytes, ranging in size from hundreds of thousands to billions. Main
memory is a repository of rapidly available information shared by the CPU and I/O
devices. Main memory is the place where programs and information are kept when the
processor is effectively utilizing them. Main memory is associated with the processor, so
moving instructions and information into and out of the processor is extremely fast. Main
memory is also known as RAM (Random Access Memory). This memory is volatile. RAM
loses its data when a power interruption occurs.
Main Memory

What is Memory Management?


In a multiprogramming computer, the Operating System resides in a part of memory, and
the rest is used by multiple processes. The task of subdividing the memory among
different processes is called Memory Management. Memory management is a method in
the operating system to manage operations between main memory and disk during
process execution. The main aim of memory management is to achieve efficient utilization
of memory.
Why Memory Management is Required?
 Allocate and de-allocate memory before and after process execution.
 To keep track of used memory space by processes.
 To minimize fragmentation issues.
 To proper utilization of main memory.
 To maintain data integrity while executing of process.
Now we are discussing the concept of Logical Address Space and Physical Address
Space
Logical and Physical Address Space
 Logical Address Space: An address generated by the CPU is known as a “Logical
Address”. It is also known as a Virtual address. Logical address space can be defined
as the size of the process. A logical address can be changed.
 Physical Address Space: An address seen by the memory unit (i.e the one loaded
into the memory address register of the memory) is commonly known as a “Physical
Address”. A Physical address is also known as a Real address. The set of all physical
addresses corresponding to these logical addresses is known as Physical address
space. A physical address is computed by MMU. The run-time mapping from virtual to
physical addresses is done by a hardware device Memory Management Unit(MMU).
The physical address always remains constant.
Static and Dynamic Loading
Loading a process into the main memory is done by a loader. There are two different
types of loading :
 Static Loading: Static Loading is basically loading the entire program into a fixed
address. It requires more memory space.
 Dynamic Loading: The entire program and all data of a process must be in physical
memory for the process to execute. So, the size of a process is limited to the size
of physical memory. To gain proper memory utilization, dynamic loading is used.
In dynamic loading, a routine is not loaded until it is called. All routines are residing on
disk in a relocatable load format. One of the advantages of dynamic loading is that the
unused routine is never loaded. This loading is useful when a large amount of code is
needed to handle it efficiently.
Static and Dynamic Linking
To perform a linking task a linker is used. A linker is a program that takes one or more
object files generated by a compiler and combines them into a single executable file.
 Static Linking: In static linking, the linker combines all necessary program modules
into a single executable program. So there is no runtime dependency. Some operating
systems support only static linking, in which system language libraries are treated like
any other object module.
 Dynamic Linking: The basic concept of dynamic linking is similar to dynamic loading.
In dynamic linking, “Stub” is included for each appropriate library routine reference. A
stub is a small piece of code. When the stub is executed, it checks whether the needed
routine is already in memory or not. If not available then the program loads the routine
into memory.
Swapping
When a process is executed it must have resided in memory. Swapping is a process of
swapping a process temporarily into a secondary memory from the main memory, which
is fast compared to secondary memory. A swapping allows more processes to be run and
can be fit into memory at one time. The main part of swapping is transferred time and the
total time is directly proportional to the amount of memory swapped. Swapping is also
known as roll-out, or roll because if a higher priority process arrives and wants service,
the memory manager can swap out the lower priority process and then load and execute
the higher priority process. After finishing higher priority work, the lower priority process
swapped back in memory and continued to the execution process.
swapping in memory management

Memory Management with Monoprogramming (Without Swapping)


This is the simplest memory management approach the memory is divided into two
sections:
 One part of the operating system
 The second part of the user program
Fence Register

operating system user program


 In this approach, the operating system keeps track of the first and last location
available for the allocation of the user program
 The operating system is loaded either at the bottom or at top
 Interrupt vectors are often loaded in low memory therefore, it makes sense to load the
operating system in low memory
 Sharing of data and code does not make much sense in a single process environment
 The Operating system can be protected from user programs with the help of a fence
register.
Advantages of Memory Management
 It is a simple management approach
Disadvantages of Memory Management
 It does not support multiprogramming
 Memory is wasted
Multiprogramming with Fixed Partitions (Without Swapping)
 A memory partition scheme with a fixed number of partitions was introduced to support
multiprogramming. this scheme is based on contiguous allocation
 Each partition is a block of contiguous memory
 Memory is partitioned into a fixed number of partitions.
 Each partition is of fixed size
Example: As shown in fig. memory is partitioned into 5 regions the region is reserved for
updating the system the remaining four partitions are for the user program.
Fixed Size Partitioning
Operating System

p1

p2

p3

p4
Partition Table
Once partitions are defined operating system keeps track of the status of memory
partitions it is done through a data structure called a partition table.
Sample Partition Table
Starting Address of Partition Size of Partition Status

0k 200k allocated

200k 100k free

300k 150k free

450k 250k allocated


Logical vs Physical Address
An address generated by the CPU is commonly referred to as a logical address. the
address seen by the memory unit is known as the physical address. The logical address
can be mapped to a physical address by hardware with the help of a base register this is
known as dynamic relocation of memory references.
Contiguous Memory Allocation
The main memory should accommodate both the operating system and the different client
processes. Therefore, the allocation of memory becomes an important task in the
operating system. The memory is usually divided into two partitions: one for the
resident operating system and one for the user processes. We normally need several user
processes to reside in memory simultaneously. Therefore, we need to consider how to
allocate available memory to the processes that are in the input queue waiting to be
brought into memory. In adjacent memory allotment, each process is contained in a single
contiguous segment of memory.

Contiguous Memory Allocation

Memory Allocation
To gain proper memory utilization, memory allocation must be allocated efficient manner.
One of the simplest methods for allocating memory is to divide memory into several fixed-
sized partitions and each partition contains exactly one process. Thus, the degree of
multiprogramming is obtained by the number of partitions.
 Multiple partition allocation: In this method, a process is selected from the input
queue and loaded into the free partition. When the process terminates, the partition
becomes available for other processes.
 Fixed partition allocation: In this method, the operating system maintains a table that
indicates which parts of memory are available and which are occupied by processes.
Initially, all memory is available for user processes and is considered one large block of
available memory. This available memory is known as a “Hole”. When the process
arrives and needs memory, we search for a hole that is large enough to store this
process. If the requirement is fulfilled then we allocate memory to process, otherwise
keeping the rest available to satisfy future requests. While allocating a memory
sometimes dynamic storage allocation problems occur, which concerns how to satisfy
a request of size n from a list of free holes. There are some solutions to this problem:
First Fit
In the First Fit, the first available free hole fulfil the requirement of the process allocated.

First Fit

Here, in this diagram, a 40 KB memory block is the first available free hole that can store
process A (size of 25 KB), because the first two blocks did not have sufficient memory
space.
Best Fit
In the Best Fit, allocate the smallest hole that is big enough to process requirements. For
this, we search the entire list, unless the list is ordered by size.

Best Fit

Here in this example, first, we traverse the complete list and find the last hole 25KB is the
best suitable hole for Process A(size 25KB). In this method, memory utilization is
maximum as compared to other memory allocation techniques.
Worst Fit
In the Worst Fit, allocate the largest available hole to process. This method produces the
largest leftover hole.
Worst Fit

Here in this example, Process A (Size 25 KB) is allocated to the largest available memory
block which is 60KB. Inefficient memory utilization is a major issue in the worst fit.
Fragmentation
Fragmentation is defined as when the process is loaded and removed after execution
from memory, it creates a small free hole. These holes can not be assigned to new
processes because holes are not combined or do not fulfill the memory requirement of the
process. To achieve a degree of multiprogramming, we must reduce the waste of
memory or fragmentation problems. In the operating systems two types of fragmentation:
1. Internal fragmentation: Internal fragmentation occurs when memory blocks are
allocated to the process more than their requested size. Due to this some unused
space is left over and creating an internal fragmentation problem.Example: Suppose
there is a fixed partitioning used for memory allocation and the different sizes of blocks
3MB, 6MB, and 7MB space in memory. Now a new process p4 of size 2MB comes and
demands a block of memory. It gets a memory block of 3MB but 1MB block of memory
is a waste, and it can not be allocated to other processes too. This is called internal
fragmentation.
2. External fragmentation: In External Fragmentation, we have a free memory block, but
we can not assign it to a process because blocks are not
contiguous. Example: Suppose (consider the above example) three processes p1, p2,
and p3 come with sizes 2MB, 4MB, and 7MB respectively. Now they get memory
blocks of size 3MB, 6MB, and 7MB allocated respectively. After allocating the process
p1 process and the p2 process left 1MB and 2MB. Suppose a new process p4 comes
and demands a 3MB block of memory, which is available, but we can not assign it
because free memory space is not contiguous. This is called external fragmentation.
Both the first-fit and best-fit systems for memory allocation are affected by external
fragmentation. To overcome the external fragmentation problem Compaction is used. In
the compaction technique, all free memory space combines and makes one large block.
So, this space can be used by other processes effectively.
Another possible solution to the external fragmentation is to allow the logical address
space of the processes to be noncontiguous, thus permitting a process to be allocated
physical memory wherever the latter is available.
Paging
Paging is a memory management scheme that eliminates the need for a contiguous
allocation of physical memory. This scheme permits the physical address space of a
process to be non-contiguous.
 Logical Address or Virtual Address (represented in bits): An address generated by
the CPU.
 Logical Address Space or Virtual Address Space (represented in words or
bytes): The set of all logical addresses generated by a program.
 Physical Address (represented in bits): An address actually available on a memory
unit.
 Physical Address Space (represented in words or bytes): The set of all physical
addresses corresponding to the logical addresses.
Example:
 If Logical Address = 31 bits, then Logical Address Space = 2 31 words = 2 G words (1 G
= 230)
 If Logical Address Space = 128 M words = 2 7 * 2 20 words, then Logical Address =
log 2 227 = 27 bits
 If Physical Address = 22 bits, then Physical Address Space = 2 22 words = 4 M words (1
M = 220)
 If Physical Address Space = 16 M words = 2 4 * 2 20 words, then Physical Address =
log 2 224 = 24 bits
The mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device and this mapping is known as the paging technique.
 The Physical Address Space is conceptually divided into several fixed-size blocks,
called frames.
 The Logical Address Space is also split into fixed-size blocks, called pages.
 Page Size = Frame Size
Let us consider an example:
 Physical Address = 12 bits, then Physical Address Space = 4 K words
 Logical Address = 13 bits, then Logical Address Space = 8 K words
 Page size = frame size = 1 K words (assumption)
Paging

The address generated by the CPU is divided into:


 Page Number(p): Number of bits required to represent the pages in Logical Address
Space or Page number
 Page Offset(d): Number of bits required to represent a particular word in a page or
page size of Logical Address Space or word number of a page or page offset.
Physical Address is divided into:
 Frame Number(f): Number of bits required to represent the frame of Physical Address
Space or Frame number frame
 Frame Offset(d): Number of bits required to represent a particular word in a frame or
frame size of Physical Address Space or word number of a frame or frame offset.
The hardware implementation of the page table can be done by using dedicated registers.
But the usage of the register for the page table is satisfactory only if the page table is
small. If the page table contains a large number of entries then we can use
TLB(translation Look-aside buffer), a special, small, fast look-up hardware cache.
 The TLB is an associative, high-speed memory.
 Each entry in TLB consists of two parts: a tag and a value.
 When this memory is used, then an item is compared with all tags simultaneously. If
the item is found, then the corresponding value is returned.
Page Map Table

Main memory access time = m


If page table are kept in main memory,
Effective access time = m(for page table)
+ m(for particular page in page table)

TLB Hit and Miss


Segmentation

8.4.1 Basic Method

 Most users ( programmers ) do not think of their programs as existing in one


continuous linear address space.
 Rather they tend to think of their memory in multiple segments, each dedicated
to a particular use, such as code, data, the stack, the heap, etc.
 Memory segmentation supports this view by providing addresses with a
segment number ( mapped to a segment base address ) and an offset from
the beginning of that segment.
 For example, a C compiler might generate 5 segments for the user code,
library code, global ( static ) variables, the stack, and the heap, as shown in
Figure 8.7:

Figure 8.7 Programmer's view of a program.


8.4.2 Segmentation Hardware

 A segment table maps segment-offset addresses to physical addresses, and


simultaneously checks for invalid addresses, using a system similar to the page
tables and relocation base registers discussed previously. ( Note that at this
point in the discussion of segmentation, each segment is kept in contiguous
memory and may be of different sizes, but that segmentation can also be
combined with paging as we shall see shortly. )

Figure 8.8 - Segmentation hardware


Figure 8.9 - Example of segmentation

3.2 Virtual memory


Virtual Memory is a storage scheme that provides user an illusion of having a very big main memory. This
is done by treating a part of secondary memory as the main memory.

In this scheme, User can load the bigger size processes than the available main memory by having the
illusion that the memory is available to load the process.
Instead of loading one big process in the main memory, the Operating System loads the different parts of
more than one process in the main memory.

By doing this, the degree of multiprogramming will be increased and therefore, the CPU utilization will
also be increased.

How Virtual Memory Works?


In modern word, virtual memory has become quite common these days. In this scheme, whenever some
pages needs to be loaded in the main memory for the execution and the memory is not available for
those many pages, then in that case, instead of stopping the pages from entering in the main memory,
the OS search for the RAM area that are least used in the recent times or that are not referenced and copy
that into the secondary memory to make the space for the new pages in the main memory.

Since all this procedure happens automatically, therefore it makes the computer feel like it is having the
unlimited RAM.

Snapshot of a virtual memory management system


Let us assume 2 processes, P1 and P2, contains 4 pages each. Each page size is 1 KB. The main memory
contains 8 frame of 1 KB each. The OS resides in the first two partitions. In the third partition, 1 st page of
P1 is stored and the other frames are also shown as filled with the different pages of processes in the
main memory.

The page tables of both the pages are 1 KB size each and therefore they can be fit in one frame each. The
page tables of both the processes contain various information that is also shown in the image.

The CPU contains a register which contains the base address of page table that is 5 in the case of P1 and 7
in the case of P2. This page table base address will be added to the page number of the Logical address
when it comes to accessing the actual corresponding entry.
Advantages of Virtual Memory

1. The degree of Multiprogramming will be increased.


2. User can run large application with less real RAM.
3. There is no need to buy more memory RAMs.

Disadvantages of Virtual Memory

1. The system becomes slower since swapping takes time.


2. It takes more time in switching between applications.
3. The user will have the lesser hard disk space for its use.

Demand Paging
Demand Paging is a popular method of virtual memory management. In demand paging, the pages of a
process which are least used, get stored in the secondary memory.

A page is copied to the main memory when its demand is made or page fault occurs. There are various
page replacement algorithms which are used to determine the pages which will be replaced. We will
discuss each one of them later in detail.
According to the concept of Virtual Memory, in order to execute some process, only a part of the process
needs to be present in the main memory which means that only a few pages will only be present in the
main memory at any time.

However, deciding, which pages need to be kept in the main memory and which need to be kept in the
secondary memory, is going to be difficult because we cannot say in advance that a process will require a
particular page at particular time.

Therefore, to overcome this problem, there is a concept called Demand Paging is introduced. It suggests
keeping all pages of the frames in the secondary memory until they are required. In other words, it says
that do not load any page in the main memory until it is required.

Whenever any page is referred for the first time in the main memory, then that page will be found in the
secondary memory.

After that, it may or may not be present in the main memory depending upon the page replacement
algorithm which will be covered later in this tutorial.

What is a Page Fault?

If the referred page is not present in the main memory then there will be a miss and the concept is called
Page miss or page fault.

The CPU has to access the missed page from the secondary memory. If the number of page fault is very
high then the effective access time of the system will become very high.

Page Replacement Algorithms


There are three types of Page Replacement Algorithms. They are:

o Optimal Page Replacement Algorithm


o First In First Out Page Replacement Algorithm
o Least Recently Used (LRU) Page Replacement Algorithm

First in First out Page Replacement Algorithm

This is the first basic algorithm of Page Replacement Algorithms. This algorithm is basically dependent on
the number of frames used. Then each frame takes up the certain page and tries to access it. When the
frames are filled then the actual problem starts. The fixed number of frames is filled up with the help of
first frames present. This concept is fulfilled with the help of Demand Paging

After filling up of the frames, the next page in the waiting queue tries to enter the frame. If the frame is
present then, no problem is occurred. Because of the page which is to be searched is already present in
the allocated frames.
If the page to be searched is found among the frames then, this process is known as Page Hit.

If the page to be searched is not found among the frames then, this process is known as Page Fault.

When Page Fault occurs this problem arises, then the First In First Out Page Replacement Algorithm
comes into picture.

The First In First Out (FIFO) Page Replacement Algorithm removes the Page in the frame which is allotted
long back. This means the useless page which is in the frame for a longer time is removed and the new
page which is in the ready queue and is ready to occupy the frame is allowed by the First In First Out Page
Replacement.

Let us understand this First In First Out Page Replacement Algorithm working with the help of an example.

Example:

Consider the reference string 6, 1, 1, 2, 0, 3, 4, 6, 0, 2, 1, 2, 1, 2, 0, 3, 2, 1, 2, 0 for a memory with three


frames and calculate number of page faults by using FIFO (First In First Out) Page replacement algorithms.

Points to Remember

Page Not Found - - - > Page Fault

Page Found - - - > Page Hit

Reference String:

Number of Page Hits = 8

Number of Page Faults = 12

The Ratio of Page Hit to the Page Fault = 8 : 12 - - - > 2 : 3 - - - > 0.66
The Page Hit Percentage = 8 *100 / 20 = 40%

The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 40 = 60%

Explanation

First, fill the frames with the initial pages. Then, after the frames are filled we need to create a space in the
frames for the new page to occupy. So, with the help of First in First Out Page Replacement Algorithm we
remove the frame which contains the page is older among the pages. By removing the older page we give
access for the new frame to occupy the empty space created by the First in First out Page Replacement
Algorithm.

OPTIMAL Page Replacement Algorithm


This is the second basic algorithm of Page Replacement Algorithms. This algorithm is basically dependent
on the number of frames used. Then each frame takes up the certain page and tries to access it. When the
frames are filled then the actual problem starts. The fixed number of frames is filled up with the help of
first frames present. This concept is fulfilled with the help of Demand Paging

After filling up of the frames, the next page in the waiting queue tries to enter the frame. If the frame is
present then, no problem is occurred. Because of the page which is to be searched is already present in
the allocated frames.

If the page to be searched is found among the frames then, this process is known as Page Hit.

If the page to be searched is not found among the frames then, this process is known as Page Fault.

When Page Fault occurs this problem arises, then the OPTIMAL Page Replacement Algorithm comes into
picture.

The OPTIMAL Page Replacement Algorithms works on a certain principle. The principle is:

Replace the Page which is not used in the Longest Dimension of time in future

This principle means that after all the frames are filled then, see the future pages which are to occupy the
frames. Go on checking for the pages which are already available in the frames. Choose the page which is
at last.

Example:

Suppose the Reference String is:

0, 3, 4, 6, 0, 2, 1, 2, 1, 2, 0, 3, 2, 1, 2, 0

6, 1, 2 are in the frames occupying the frames.

Now we need to enter 0 into the frame by removing one page from the page
So, let us check which page number occurs last

From the sub sequence 0, 3, 4, 6, 0, 2, 1 we can say that 1 is the last occurring page number. So we can
say that 0 can be placed in the frame body by removing 1 from the frame.

Let us understand this OPTIMAL Page Replacement Algorithm working with the help of an example.

Example:

Consider the reference string 6, 1, 1, 2, 0, 3, 4, 6, 0, 2, 1, 2, 1, 2, 0, 3, 2, 1, 4, 0 for a memory with three


frames and calculate number of page faults by using OPTIMAL Page replacement algorithms.

Points to Remember

Page Not Found - - - > Page Fault

Page Found - - - > Page Hit

Reference String:

Number of Page Hits = 8

Number of Page Faults = 12

The Ratio of Page Hit to the Page Fault = 8 : 12 - - - > 2 : 3 - - - > 0.66

The Page Hit Percentage = 8 *100 / 20 = 40%

The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 40 = 60%

Explanation

First, fill the frames with the initial pages. Then, after the frames are filled we need to create a space in the
frames for the new page to occupy.
Here, we would fill the empty spaces with the pages we and the empty frames we have. The problem
occurs when there is no space for occupying of pages. We have already known that we would replace the
Page which is not used in the Longest Dimension of time in future.

There comes a question what if there is absence of page which is in the frame.

Suppose the Reference String is:

0, 2, 4, 6, 0, 2, 1, 2, 1, 2, 0, 3, 2, 1, 2, 0

6, 1, 5 are in the frames occupying the frames.

Here, we can see that page number 5 is not present in the Reference String. But the number 5 is present
in the Frame. So, as the page number 5 is absent we remove it when required and other page can occupy
that position.

Least Recently Used (LRU) Replacement Algorithm

This is the last basic algorithm of Page Replacement Algorithms. This algorithm is basically dependent on
the number of frames used. Then each frame takes up the certain page and tries to access it. When the
frames are filled then the actual problem starts. The fixed number of frames is filled up with the help of
first frames present. This concept is fulfilled with the help of Demand Paging

After filling up of the frames, the next page in the waiting queue tries to enter the frame. If the frame is
present then, no problem is occurred. Because of the page which is to be searched is already present in
the allocated frames.

If the page to be searched is found among the frames then, this process is known as Page Hit.

If the page to be searched is not found among the frames then, this process is known as Page Fault.

When Page Fault occurs this problem arises, then the Least Recently Used (LRU) Page Replacement
Algorithm comes into picture.

The Least Recently Used (LRU) Page Replacement Algorithms works on a certain principle. The principle is:

Replace the page with the page which is less dimension of time recently used page in the past.

Example:

Suppose the Reference String is:

6, 1, 1, 2, 0, 3, 4, 6, 0

The pages with page numbers 6, 1, 2 are in the frames occupying the frames.

Now, we need to allot a space for the page numbered 0.


Now, we need to travel back into the past to check which page can be replaced.

6 is the oldest page which is available in the Frame.

So, replace 6 with the page numbered 0.

Let us understand this Least Recently Used (LRU) Page Replacement Algorithm working with the help of
an example.

Example:

Consider the reference string 6, 1, 1, 2, 0, 3, 4, 6, 0, 2, 1, 2, 1, 2, 0, 3, 2, 1, 2, 0 for a memory with three


frames and calculate number of page faults by using Least Recently Used (LRU) Page replacement
algorithms.

Points to Remember

Page Not Found - - - > Page Fault

Page Found - - - > Page Hit

Reference String:

Number of Page Hits = 7

Number of Page Faults = 13

The Ratio of Page Hit to the Page Fault = 7 : 12 - - - > 0.5833 : 1

The Page Hit Percentage = 7 * 100 / 20 = 35%

The Page Fault Percentage = 100 - Page Hit Percentage = 100 - 35 = 65%

Explanation
First, fill the frames with the initial pages. Then, after the frames are filled we need to create a space in the
frames for the new page to occupy.

Here, we would fill the empty spaces with the pages we and the empty frames we have. The problem
occurs when there is no space for occupying of pages. We have already known that we would replace the
Page which is not used in the Longest Dimension of time in past or can be said as the Page which is very
far away in the past.

Frame Allocation in Virtual Memory


Demand paging is used to implement virtual memory, an essential component of operating systems. A
page-replacement mechanism and a frame allocation algorithm must be created for demand paging. If
you have numerous processes, frame allocation techniques are utilized to determine how many frames to
provide to each process.

A Physical Address is required by the Central Processing Unit (CPU) for the frame creation and the
physical Addressing provides the actual address to the frame created. For each page a frame must be
created.

Frame Allocation Constraints

o The Frames that can be allocated cannot be greater than total number of frames.
o Each process should be given a set minimum amount of frames.
o When fewer frames are allocated then the page fault ration increases and the process execution
becomes less efficient
o There ought to be sufficient frames to accommodate all the many pages that a single instruction
may refer to

AD

Frame Allocation Algorithms

There are three types of Frame Allocation Algorithms in Operating Systems. They are:

1) Equal Frame Allocation Algorithms

Here, in this Frame Allocation Algorithm we take number of frames and number of processes at once. We
divide the number of frames by number of processes. We get the number of frames we must provide for
each process.

This means if we have 36 frames and 6 processes. For each process 6 frames are allocated.

It is not very logical to assign equal frames to all processes in systems with processes of different sizes. A
lot of allocated but unused frames will eventually be wasted if a lot of frames are given to a little
operation.
2) Proportionate Frame Allocation Algorithms

Here, in this Frame Allocation Algorithms we take number of frames based on the process size. For big
process more number of frames is allocated. For small processes less number of frames is allocated by the
operating system.

The problem in the Proportionate Frame Allocation Algorithm is number of frames are wasted in some
rare cases.

The advantage in Proportionate Frame Allocation Algorithm is that instead of equally, each operation
divides the available frames according to its demands.

3) Priority Frame Allocation Algorithms

According to the quantity of frame allocations and the processes, priority frame allocation distributes
frames. Let's say a process has a high priority and needs more frames; in such case, additional frames will
be given to the process. Processes with lower priorities are then later executed in future and first only high
priority processes are executed first.

What is Thrashing?

If the number of page faults is equal to the number of referred pages or the number of page faults are so
high so that the CPU remains busy in just reading the pages from the secondary memory then the
effective access time will be the time taken by the CPU to read one word from the secondary memory and
it will be so high. The concept is called thrashing.

If the page fault rate is PF %, the time taken in getting a page from the secondary memory and again
restarting is S (service time) and the memory access time is ma then the effective access time can be given
as;

EAT = PF X S + (1 - PF) X (ma)

3.3 Allocating Kernel memory


Introduction:

Allocating kernel memory is a critical task in operating system design, as the kernel needs
to manage memory efficiently and effectively to ensure optimal system performance. Two
common methods for allocating kernel memory are the buddy system and the slab
system.
The buddy system is a memory allocation algorithm that works by dividing memory into
blocks of a fixed size, with each block being a power of two in size. When a request for
memory is made, the algorithm finds the smallest available block of memory that is large
enough to satisfy the request. If the block is larger than the requested size, it is split into
two smaller blocks of equal size (the “buddies”), with each buddy being marked as either
allocated or free. The algorithm then continues recursively until it finds the exact size of
the requested memory or a block that is the smallest possible size.
The slab system is a memory allocation algorithm that is designed specifically for kernel
memory. It works by dividing memory into fixed-size caches or slabs, each of which
contains a set of objects of the same type. When a request for memory is made, the
algorithm first checks if there is an available object in the appropriate slab cache. If there
is, the object is returned. If not, the algorithm allocates a new slab and adds it to the
appropriate cache.
The advantages of the buddy system are that it is easy to implement and can handle a
wide range of memory sizes. The disadvantages are that it can lead to memory
fragmentation and that it can be inefficient for allocating small amounts of memory.
The advantages of the slab system are that it is efficient for allocating small amounts of
memory and that it can prevent memory fragmentation. The disadvantages are that it can
be more complex to implement than the buddy system and that it may require more
memory overhead.
Overall, both the buddy system and the slab system are effective methods for allocating
kernel memory, and the choice between the two depends on the specific needs and
requirements of the operating system being developed.
Two strategies for managing free memory that is assigned to kernel processes:

1. Buddy system –

Buddy allocation system is an algorithm in which a larger memory block is divided into
small parts to satisfy the request. This algorithm is used to give best fit. The two smaller
parts of block are of equal size and called as buddies. In the same manner one of the two
buddies will further divide into smaller parts until the request is fulfilled. Benefit of this
technique is that the two buddies can combine to form the block of larger size according
to the memory request.
Example – If the request of 25Kb is made then block of size 32Kb is allocated.
Four Types of Buddy System –
1. Binary buddy system
2. Fibonacci buddy system
3. Weighted buddy system
4. Tertiary buddy system
Why buddy system?
If the partition size and process size are different then poor match occurs and may use
space inefficiently.
It is easy to implement and efficient then dynamic allocation.
Binary buddy system –
The buddy system maintains a list of the free blocks of each size (called a free list), so
that it is easy to find a block of the desired size, if one is available. If no block of the
requested size is available, Allocate searches for the first non-empty list for blocks of
atleast the size requested. In either case, a block is removed from the free list.
Example – Assume the size of memory segment is initially 256kb and the kernel requests
25kb of memory. The segment is initially divided into two buddies. Let we call A1 and A2
each 128kb in size. One of these buddies is further divided into two 64kb buddies let say
B1 and B2. But the next highest power of 25kb is 32kb so, either B1 or B2 is further
divided into two 32kb buddies(C1 and C2) and finally one of these buddies is used to
satisfy the 25kb request. A split block can only be merged with its unique buddy block,
which then reforms the larger block they were split from.
Fibonacci buddy system –
This is the system in which blocks are divided into sizes which are Fibonacci numbers. It
satisfies the following relation:
Zi = Z(i-1)+Z(i-2)
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 144, 233, 377, 610. The address calculation for the
binary and weighted buddy systems is straight forward, but the original procedure for the
Fibonacci buddy system was either limited to a small, fixed number of block sizes or a
time consuming computation.
Advantages –
 In comparison to other simpler techniques such as dynamic allocation, the buddy
memory system has little external fragmentation.
 The buddy memory allocation system is implemented with the use of a binary tree to
represent used or unused split memory blocks.
 The buddy system is very fast to allocate or deallocate memory.
 In buddy systems, the cost to allocate and free a block of memory is low compared to
that of best-fit or first-fit algorithms.
 Other advantage is coalescing.
 Address calculation is easy.
 Efficient memory management: Kernel memory allocators are designed to efficiently
manage memory resources, ensuring that memory is allocated and deallocated in a
way that minimizes fragmentation and maximizes available space.
 Customizable allocation policies: Kernel memory allocators can be customized to
implement specific allocation policies, such as best fit, worst fit, or first fit. This allows
for more precise control over memory usage and allocation.
 High performance: Kernel memory allocators are typically designed for high-
performance systems, allowing for fast and efficient allocation and deallocation of
memory.
 Reduced memory overhead: Memory allocators can reduce memory overhead by
allowing for more efficient use of memory resources, reducing the overall memory
footprint of the system.
 Improved system stability: Efficient memory management can help improve system
stability by reducing the likelihood of memory leaks, crashes, and other issues related
to memory allocation.
Overall, using a kernel memory allocator can help improve system performance, stability,
and memory management, making it an essential component of any operating system.
What is coalescing?
It is defined as how quickly adjacent buddies can be combined to form larger segments
this is known as coalescing.
For example, when the kernel releases the C1 unit it was allocated, the system can
coalesce C1 and C2 into a 64kb segment. This segment B1 can in turn be coalesced with
its buddy B2 to form a 128kb segment. Ultimately we can end up with the original 256kb
segment.
Drawback –
The main drawback in buddy system is internal fragmentation as larger block of memory
is acquired then required. For example if a 36 kb request is made then it can only be
satisfied by 64 kb segment and remaining memory is wasted.

2. Slab Allocation –

A second strategy for allocating kernel memory is known as slab allocation. It eliminates
fragmentation caused by allocations and deallocations. This method is used to retain
allocated memory that contains a data object of a certain type for reuse upon subsequent
allocations of objects of the same type. In slab allocation memory chunks suitable to fit
data objects of certain type or size are preallocated. Cache does not free the space
immediately after use although it keeps track of data which are required frequently so that
whenever request is made the data will reach very fast. Two terms required are:
 Slab – A slab is made up of one or more physically contiguous pages. The slab is the
actual container of data associated with objects of the specific kind of the containing
cache.
 Cache – Cache represents a small amount of very fast memory. A cache consists of
one or more slabs. There is a single cache for each unique kernel data structure.

Example –
 A separate cache for a data structure representing processes descriptors
 Separate cache for file objects
 Separate cache for semaphores etc.
Each cache is populated with objects that are instantiations of the kernel data structure
the cache represents. For example the cache representing semaphores stores instances
of semaphore objects, the cache representing process descriptors stores instances of
process descriptor objects.
Implementation –
The slab allocation algorithm uses caches to store kernel objects. When a cache is
created a number of objects which are initially marked as free are allocated to the cache.
The number of objects in the cache depends on size of the associated slab.
Example – A 12 kb slab (made up of three contiguous 4 kb pages) could store six 2 kb
objects. Initially all objects in the cache are marked as free. When a new object for a
kernel data structure is needed, the allocator can assign any free object from the cache to
satisfy the request. The object assigned from the cache is marked as used.
In linux, a slab may in one of three possible states:
1. Full – All objects in the slab are marked as used
2. Empty – All objects in the slab are marked as free
3. Partial – The slab consists of both
The slab allocator first attempts to satisfy the request with a free object in a partial slab. If
none exists, a free object is assigned from an empty slab. If no empty slabs are available,
a new slab is allocated from contiguous physical pages and assigned to a cache.
Benefits of slab allocator –
 No memory is wasted due to fragmentation because each unique kernel data structure
has an associated cache.
 Memory request can be satisfied quickly.
 The slab allocating scheme is particularly effective for managing when objects are
frequently allocated or deallocated. The act of allocating and releasing memory can be
a time consuming process. However, objects are created in advance and thus can be
quickly allocated from the cache. When the kernel has finished with an object and
releases it, it is marked as free and return to its cache, thus making it immediately
available for subsequent request from the kernel.

3.4 Mass storage system


A storage device is any device used in a computer to store information. It will
retain this information when the computer is switched off.
• Type of storage device used varies based on the type of data and the rate at which
it is created and used.
• Examples of storage devices are hard disk, CD-ROM, magnetic tape and
removable media etc.
• The computer has many types of data storage devices. Some of them can be
classified as the removable data storage devices and the others as the non
removable data storage devices.

1. Hard disk: The most common form of internal storage device used in a
computer is a hard disk. A hard disk has a circular, magnetized surface on which
the data is stored. A hard disk spins at a speed of between 60 and 120 revolutions
per second. The data stored on the hard disk is read or written by a head that floats
just above the disk (less than 0.1 mm) on a cushion of air. The surface of a hard
disk is divided up into sectors and tracks. Data is stored in the 'blocks' created by
the sectors and tracks. Moving data into a 'block' is called random access.
2. Compact disk: Compact disks can be used to store much more data than aahe
floppy disk. Most compact disks can hold 650 megabytes of data. There are three
main types of compact disk: CD-ROM, CD-R, CD-RW.
3. Magnetic tape: This is a cheap method of storing large amounts of data
(typically 26 gigabytes) and is often used as a 'backing store' for large and
mainframe computers.
4. Removable media: Zip drives are similar to floppy drives and use special (and
rather expensive) floppy disks that can hold between 100 megabytes and 2
gigabytes of data.

Characteristics of Storage Device


1. When power to the device is shut off, data stored on the medium remains.
2. Storage devices are cheaper than memory.
3. They are capable of storing more data.
4. Rotational speeds have increased over time.
5. Storage devices are used for backup.

Magnetic Disk
• To store computer data, hard disks, flash memory, magnetic tape and optical
Wiedsmil
• Alternate storage for hard disk is Solid State Disks (SSD). These flash memory
tollon based devices offer a different set of tradeoffs from a standard disk. At the
same time, capacity of the hard disk also increases.
• Hybrid category is introduced for storage media. It is hard disks with large flash
memory buffers. Disk sizes are specified in gigabytes.
• Performances of hard disk and SSD technology is given below:
• Hard disk contains several rotating platters coated with magnetic film. They are
read and written by tiny skating heads that are mounted on a metal arm that swings
back and forth to position them. Heads float close to the surface of the platters but
do not actually touch.
• A hard disk is really a set of stacked "disks," each of which, like phonograph
records, has data recorded electromagnetically in concentric circles or "tracks" on
the disk.
• A "head" writes or reads the information on the tracks. Two heads, one on each
side of a disk, read or write the data as the disk spins. Each read or write operation
requires that data be located, which is an operation called a "seek."
• A hard disk/drive unit comes with a set rotation speed varying from 4500 to 7200
rpm. Disk access time is measured in milliseconds.
• Although the physical location can be identified with cylinder, track and sector
locations, these are actually mapped to a Logical Block Address (LBA) that works
with the larger address range on today's hard disks.
• Mean Time Between Failures (MTBF) is the predicted elapsed time between
inherent failures of a system during operation. MTBF can be calculated as the
arithmetic mean (average) time between failures of a system.
• Each disk drive is managed by a controller. Each type of controller can support a
fixed number of drives. SCSI controllers support up to seven disks per controller
or up to 15 disks per controller.
• Each disk is assigned a drive address. This address is set by a switch, a dial or
jumpers on the disk or by the physical location of the disk. Some SCSI devices,
such as RAID's, have an additional identifying number called a logical unit
number. It is used to address disks within the device.
• Fig. 5.1.1 shows physical disk.

• A disk consists of circular plates called platters. Each platter has an upper and
lower oxide-coated surface. Recording heads, at least one per surface, are mounted
on arms that can be moved to various radial distances from the center of the
platters. The heads float very close to the surfaces of the platters, never actually
touching them, and read and record data as the platters spin around.
• A ring on one surface is called a track. Each track is divided into disk blocks.
Sometimes called sectors, these physical blocks on a disk are different from file
system blocks.
• Formatting a disk divides the disk into tracks and disk blocks that can be
addressed by the disk controller, writes timing marks, and identifies bad areas on
the disk.
• SCSI disk drives are shipped preformatted. They do not require formatting at any
time. Bad block handling is performed automatically by SCSI disks. Bad blocks
are areas of a disk that cannot reliably store data.
Platter
• Platter is a circular, metal disk that is mounted inside a hard disk drive. Several
platters are mounted on a fixed spindle motor to create more data storage surfaces
in a smaller area.
• The platter has a core made up of aluminum or glass substrate, covered with a
thin layer of Ferric oxide or cobalt alloy. On both sides of the substrate material, a
thin coating is deposited by a special manufacturing technique. This, thin coating
where actual data is stored is the media layer.
• Attributes of platter
1. It is a rigid, round disk this is coated with magnetically sensitive material.
2. Data is stored in binary code.
3. It is encoded by polarizing magnetic areas on the disk surface.
4. Data can be written to and read from both surfaces of a platter.
5. A platter's storage capacity varies across drives.
Tracks
• Each platter is broken into thousands of tightly packed concentric circles, known
as tracks. These tracks resemble the structure of annual rings of a tree.
• All the information stored on the hard disk is recorded in tracks. Starting from
zero at the outer side of the platter, the number of tracks goes on increasing to the
inner side.
• Each track can hold a large amount of data counting to thousands of bytes.
Sectors
• Each track is further broken down into smaller units called sectors. As sector is
the basic unit of data storage on a hard disk. Disk contains concentric tracks.
Tracks are divided into sectors. A sector is the smallest addressable unit in a disk.
• Fig. 5.1.2 shows surface of disk showing tracks and sectors.

• A single track typically can have thousands of sectors and each sector can hold
more than 512 bytes of data. A few additional bytes are required for control
structures and error detection and correction.
Clusters: Sectors are often grouped together to form clusters.
Read/Write Heads
• The heads are an interface between the magnetic media where the data is stored
and electronic components in the hard disk. The heads convert the information,
which is in the form of bits to magnetic pulses when it is to be stored on the platter
and reverses the process while reading.
• The heads are the most sophisticated part of the hard disk. Each platter has two
read/write heads, one mounted on the top and the other one at the bottom. These
heads are mounted on head sliders, which are suspended at the ends of head
• The head arms are all fused into a singular structure called actuator, which is
responsible for their movement. Drives rotate at 60 to 200 times per second.
• Transfer rate is rate at which data flow between drive and computer.
Positioning time (random-access time) is time to move disk arm to desired cylinder
(seek time) and time for desired sector to rotate under the disk head. Head crash
results from disk head making contact with the disk surface.
• "Each platter (disc-shaped) is coated with magnetic material on both surfaces. All
platter surfaces has arm extended from fixed position. Tip of the arm contains
read/write head for reading or writing data.
• The arm moves the heads from the spindle edge to the edge of the disc.
• When a program reads a byte from the disk, the operating system locates the
surface, track and sector containing that byte, and reads the entire sector into a
special area in main memory called buffer.
• The bottleneck of a disk access is moving the read/write arm.
• A cylinder is the set of tracks at a given radius of a disk pack. A cylinder is the
set of tracks that can be accessed without moving the disk arm. All the information
on a cylinder can be accessed without moving the read/write arm.
Fig. 5.1.3 shows moving-head disk mechanism.
• The arm assembly is moved in or out to position a head on a desired track. Tracks
under heads make a cylinder. Only one head reads/writes at any one time. Block
size is a multiple of sector size.
• Disks can be removable. Drive attached to computer via I/O bus. Buses vary,
including EIDE, ATA, SATA, USB, Fibre channel, SCSI etc.
• Host controller in computer uses bus to talk to disk controller built into drive or
storage array.
• Disk controllers typically embedded in the disk drive, which acts as an interface
between the CPU and the disk hardware. The controller has an internal cache that it
uses to buffer data for read/write requests.
Zone Bit Recording
• Also known as multiple zone recording or zone-CAV recording. Disk divided
into zones. Fig. 5.1.4 shows zone bit recording.
• Cylinders in different zones have a different number of sectors. Number of
sectors in a particular zone is constant. Data is buffered so the data rate to the I/O
interface is constant.
• Zoned-bit recording uses the disk more efficiently. It groups tracks into zones
that are based upon their distance from the center of the disk.
• Each zone is assigned an appropriate number of sectors per track. This means
that a zone near the center of the platter has fewer sectors per track than a zone on
the outer edge.

Solid State Disks


• SSD is a storage device that is based on semiconductors rather than rotating
magnetic platters. Most SSDs are based on NAND Flash chips because they are
fast, highly reliable, widely available and are non-volatile, meaning they save data
even without a power source.
• SSDs use the same Serial ATA (SATA) or IDE interface as hard drives, making
them functionally identical.
• Solid-state storage technology typically provides faster system performance than
traditional magnetic media drives. In addition, there are no moving parts in SSDs
and therefore the risk of mechanical failure is near zero. Solid-state drives also
provide improved overall system responsiveness while consuming much less
power than a traditional hard disk drive.
• A flash-based SSD typically uses a small amount of DRAM as a cache, similar to
the cache in hard disk drives. A directory of block placement and wear leveling
data is also kept in the cache while the drive is operating.
• Each page of flash memory in an SSD can be rewritten only a limited number of
times. To limit the wear on any given page, the SSD firmware maintains a
mapping table and distributes writes across all the drive' pages. This remapping is
invisible to operating system.
• Flash memory pages must be erased before they can be rewritten. Erasing is
separate operation that is slower than writing. Rebuilding a buffer of erased pages
is harder than it might seem because filesystems typically do not mark or erase
data blocks they are no longer using.
• Standard size of the disk block is 512 bytes, but that size is too small for
filesystems to deal with efficiently. Filesystem manages the disk in terms of
clusters of 1 KiB to 8 KiB in size. The translation layer maps filesystem clusters
into ranges of disk blocks for reads and writes.
• SSD only can read or write data in 4 KiB pages, file system cluster boundaries
and SSD page boundaries should coincide.
• Solid state disks (SSDs) mirror the functionality of the existing standard of hard
disk drives. SSD is volatile or non-volatile depending upon memory technology.
• Because SSDs do not have moving parts and therefore performance is insensitive
to issues such as seek time and rotational latency. Therefore, a simple FCFS policy
will suffice.
• Solid state disks commonly use the FCFS disk scheduling policy.
• SSDs have the advantage of being faster than magnetic disks as there are no
moving parts and therefore do not have seek time or rotational latency.
• In an SSD the LBAs are actually inside of the flash media. SSDs contain a
number of NAND flash components.
• Solid-State Disks(SSDs) features :
1. Low power consumption.
2. Faster random access.
3. Greater shock resistance.
• SSD performance is being increased due to the exploitation of parallel I/O
architectures. An SSD interacts with the host computer via standard interface such
as PATA or SATA and behaves much like a standard hard drive.
• Operating systems use storage devices to provide file systems and virtual
memory. SSD controller is used to translate read/write requests into flash memory
operations.
• The controller exploits RAM to temporarily buffer write requests or accessed
data during handling read/write requests.
• To increase the read/write bandwidth of SSD, many SSDs use an interleaving
technique that exploits the parallelism of accessing multiple NAND chips
simultaneously.
• If there are multiple independent channels, the read/write bandwidth of SSDs can
not be accelerated further by exploiting inter-channel and intra-channel
parallelism.
• SSD challenges:
1. Reliability for large scale flash storage.
2. The balance between cost, performance and lifetime.
3. Cost per bit of NAND flash memory is still high.

Magnetic Tape
• Magnetic tapes are used mostly for storing files of data: For example, a
company's payroll record.
• Access is sequential and consists of records that can be accessed one after other
as Saib the tape moves along a stationary read-write mechanism.
• It is one of the cheapest and slowest methods for storage and has the advantage
that tapes can be recovered when not in use.
• A magnetically coated strip of plastic on which data can be encoded. Tape is
much less expensive than other storage mediums but commonly a much slower
solution that is commonly used for backup.
Fig. 5.1.5 shows connection of tape with processor.
• In addition, random access to magnetic tape is about a thousand times slower than
random access to magnetic disk, so tapes are not very useful for secondary is
storage.
• The I/O bus consists of data lines, address lines, and control lines. Each
peripheral device has associated with it an interface unit. Each interface decodes
the address and control received from the I/O bus, interprets them for the
peripheral, and provides signals for the peripheral controller.
• The I/O bus from the processor is attached to all peripheral interfaces. To
communicate with a particular device, the processor places a device address on the
address lines. Each interface attached to the I/O bus contains an address decoder
that monitors the address lines.
• When the interface detects its own address, it activates the path between the bus
lines and the device that it controls.
• All peripherals whose address does not correspond to the address in the bus are
disabled their interface. At the same time that the address is made available in the
address lines, the processor provides a function code in the control lines.
• The interface selected responds to the function code and proceeds to execute it.
The function code is referred to as an I/O command and is in essence an instruction
that is executed in the interface and its attached peripheral unit.
• The interpretation of the command depends on the peripheral that the processor is
addressing. There are four types of commands that an interface may receive. They
are classified as control, status, status, data output, and data input.
3.5 HDD Scheduling
Disk scheduling is done by operating systems to schedule I/O requests arriving for the
disk. Disk scheduling is also known as I/O Scheduling.
Importance of Disk Scheduling in Operating System
 Multiple I/O requests may arrive by different processes and only one I/O request can
be served at a time by the disk controller. Thus other I/O requests need to wait in the
waiting queue and need to be scheduled.
 Two or more requests may be far from each other so this can result in greater disk arm
movement.
 Hard drives are one of the slowest parts of the computer system and thus need to be
accessed in an efficient manner.
Key Terms Associated with Disk Scheduling
 Seek Time: Seek time is the time taken to locate the disk arm to a specified track
where the data is to be read or written. So the disk scheduling algorithm that gives a
minimum average seek time is better.
 Rotational Latency: Rotational Latency is the time taken by the desired sector of the
disk to rotate into a position so that it can access the read/write heads. So the disk
scheduling algorithm that gives minimum rotational latency is better.
 Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating
speed of the disk and the number of bytes to be transferred.
 Disk Access Time:
Disk Access Time = Seek Time + Rotational Latency + Transfer Time
Total Seek Time = Total head Movement * Seek Time

Disk Access Time and Disk Response Time

 Disk Response Time: Response Time is the average time spent by a request waiting
to perform its I/O operation. The average Response time is the response time of all
requests. Variance Response Time is the measure of how individual requests are
serviced with respect to average response time. So the disk scheduling algorithm that
gives minimum variance response time is better.
Disk Scheduling Algorithms
There are several Disk Several Algorithms. We will discuss each one of them.
FCFS (First Come First Serve)
FCFS is the simplest of all Disk Scheduling Algorithms. In FCFS, the requests are
addressed in the order they arrive in the disk queue. Let us understand this with the help
of an example.
First Come First Serve

Example:
Suppose the order of request is- (82,170,43,140,24,16,190)
And current position of Read/Write head is: 50
So, total overhead movement (total distance covered by the disk arm) =
(82-50)+(170-82)+(170-43)+(140-43)+(140-24)+(24-16)+(190-16) =642

Advantages of FCFS
Here are some of the advantages of First Come First Serve.
 Every request gets a fair chance
 No indefinite postponement
Disadvantages of FCFS
Here are some of the disadvantages of First Come First Serve.
 Does not try to optimize seek time
 May not provide the best possible service
SSTF (Shortest Seek Time First)
In SSTF (Shortest Seek Time First), requests having the shortest seek time are executed
first. So, the seek time of every request is calculated in advance in the queue and then
they are scheduled according to their calculated seek time. As a result, the request near
the disk arm will get executed first. SSTF is certainly an improvement over FCFS as it
decreases the average response time and increases the throughput of the system. Let us
understand this with the help of an example.
Example:

Shortest Seek Time First

Suppose the order of request is- (82,170,43,140,24,16,190)


And current position of Read/Write head is: 50
So,
total overhead movement (total distance covered by the disk arm) =
(50-43)+(43-24)+(24-16)+(82-16)+(140-82)+(170-140)+(190-170) =208
Advantages of Shortest Seek Time First
Here are some of the advantages of Shortest Seek Time First.
 The average Response Time decreases
 Throughput increases
Disadvantages of Shortest Seek Time First
Here are some of the disadvantages of Shortest Seek Time First.
 Overhead to calculate seek time in advance
 Can cause Starvation for a request if it has a higher seek time as compared to
incoming requests
 The high variance of response time as SSTF favors only some requests
SCAN
In the SCAN algorithm the disk arm moves in a particular direction and services the
requests coming in its path and after reaching the end of the disk, it reverses its direction
and again services the request arriving in its path. So, this algorithm works as an elevator
and is hence also known as an elevator algorithm. As a result, the requests at the
midrange are serviced more and those arriving behind the disk arm will have to wait.
Example:
SCAN Algorithm

Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write


arm is at 50, and it is also given that the disk arm should move “towards the larger
value”.
Therefore, the total overhead movement (total distance covered by the disk arm) is
calculated as
= (199-50) + (199-16) = 332

Advantages of SCAN Algorithm


Here are some of the advantages of the SCAN Algorithm.
 High throughput
 Low variance of response time
 Average response time
Disadvantages of SCAN Algorithm
Here are some of the disadvantages of the SCAN Algorithm.
 Long waiting time for requests for locations just visited by disk arm
C-SCAN
In the SCAN algorithm, the disk arm again scans the path that has been scanned, after
reversing its direction. So, it may be possible that too many requests are waiting at the
other end or there may be zero or few requests pending at the scanned area.
These situations are avoided in the CSCAN algorithm in which the disk arm instead of
reversing its direction goes to the other end of the disk and starts servicing the requests
from there. So, the disk arm moves in a circular fashion and this algorithm is also similar
to the SCAN algorithm hence it is known as C-SCAN (Circular SCAN).
Example:

Circular SCAN

Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write


arm is at 50, and it is also given that the disk arm should move “towards the larger
value”.
So, the total overhead movement (total distance covered by the disk arm) is calculated
as:
=(199-50) + (199-0) + (43-0) = 391

Advantages of C-SCAN Algorithm


Here are some of the advantages of C-SCAN.
 Provides more uniform wait time compared to SCAN.
LOOK
LOOK Algorithm is similar to the SCAN disk scheduling algorithm except for the difference
that the disk arm in spite of going to the end of the disk goes only to the last request to be
serviced in front of the head and then reverses its direction from there only. Thus it
prevents the extra delay which occurred due to unnecessary traversal to the end of the
disk.
Example:

LOOK Algorithm

Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the Read/Write


arm is at 50, and it is also given that the disk arm should move “towards the larger
value”.
So, the total overhead movement (total distance covered by the disk arm) is calculated
as:
= (190-50) + (190-16) = 314

C-LOOK
As LOOK is similar to the SCAN algorithm, in a similar way, C-LOOK is similar to the
CSCAN disk scheduling algorithm. In CLOOK, the disk arm in spite of going to the end
goes only to the last request to be serviced in front of the head and then from there goes
to the other end’s last request. Thus, it also prevents the extra delay which occurred due
to unnecessary traversal to the end of the disk.
Example:
1. Suppose the requests to be addressed are-82,170,43,140,24,16,190. And the
Read/Write arm is at 50, and it is also given that the disk arm should move “towards
the larger value”
C-LOOK

So, the total overhead movement (total distance covered by the disk arm) is calculated as
= (190-50) + (190-16) + (43-16) = 341

3.6 File concept


• Files are the building blocks of any operating system. Permanent storage of
information and data is a file. File provides an easy means of information
sharing. The operating system is not interested in the information stored in the
files. Operating system map files with physical devices.
• An unstructured sequence of data means a file. It is also logical units of
information created by processes. Information stored in the files must be
persistent. File is any organized information and stored within the secondary
storage. It is physical view of a file.
• A program which user prepare is a file. File represents programs and data.
The output from complier may be an object code file or an executable file.
• Content or information/data of file is decided by the creator of the file. File
contains various types of data like source program, object program, text and
numeric data, images, graphs, sounds, payroll records, dead-stock records etc.
File Naming
• File store information on the disk. It is an abstract mechanism. File name is
given, when process creates a file. File name continues to exist even after
closing a file. It is accessed by other process.
• File name rule is changed according the operating system. All operating
system allowed upto 8 string as a file name. Special characters and numbers are
allowed to use as a file name. Many file systems support names as long as 255
characters. File names contains two parts. It is separated by a period. For
example: sorting.c
• In the file name, after period is called file extension. File extension indicates
something about a file. UNIX operating system support more than one file
extension. It is up to the user, for extending the file extension.
• MS-DOS support only one file extension. File extension after period contains
upto three characters. Following is the list of file extension.

Types of File
• File type represents the internal structure of the file. According to the
structure, file is divided into certain types: text, source, executable and object
file.
1. Text file: It is sequence of character which organized into lines. Text file is a
regular file.
2. Source file: It contains sequence of subroutines, procedure and functions.
3. Executable file: It contains a series of code sections. This file is input to the
loader and loader loads this file into memory and then execute.
4. Object file: Object file is input to the linker. An Object file is a binary file
that the compiler creates that converts the source to object code.

File Types
File is divided into following types:
1. Ordinary file
2. Directory file
3. FIFO file
4. Character device file
5. Block device file.
Ordinary file
• Also called regular file. It contains only data as a stream of characters. An bis
ordinary file cannot contain another file, or directory.
• It is either text file or a binary file.
• Examples of ordinary files include simple text files, application data files,
files containing high-level source code, executable text files, and binary image
files.
• Text file: It contains only printable characters.
• Binary file: It contains printable and unprintable characters that cover the
entire ASCII range.
• Regular files may be created, browsed through, and modified by various
means such as text editors.
Directory file
• A directory file is like a folder that contains other files, including subdirectory
files.
• Directory files act as a container for other files, of any category. Directory
files don't contain data in the user sense of data; they merely contain references
to the files contained within them.
• Directory is created in UNIX by the mkdir command.
• The UNIX directory is considered empty if it contains no other files except the
"." and "..".
• Directory is removed by using rmdir command. Content of directory is displayed.
by ls command.
Device file
• Special files are also known as device files. In UNIX all physical devices are
accessed via device files; they are what programs use to communicate with
hardware.
• Files hold information on location, type, and access mode for a specific device.
There are two types of device files; character and block.
• Block device files are used to access block device I/O. Block devices do buffered
ar I/O, meaning that the data is collected in a buffer until a full block can be
transferred.
• Character device files are associated with character or raw device access. They
are used for un-buffered data transfers to and from a device. Rather than
transferring data in blocks the data is transferred character by character.
• One transfer can consist of multiple characters.
• Some devices, such as disk partitions, may be accessed in block or character
mode. Because each device file corresponds to a single access mode, physical
devices that have more than one access mode will have more than one device file.
• Device files are found in the /dev directory. Each device is assigned a major and
minor device number."
• The major device number identifies the type of device, i.e. all SCSI devices,
would have the same number as would all the keyboards.
• The minor device number identifies a specific device, i.e. the keyboard attached
to workstation.
• Device files are created using the mknod command.
• Example of character device files is printers, modems and consoles.
FIFO file
• FIFO file is special pipe device file which provides temporary buffers for two or
more processes to communicate by writing data to and reading data from the
buffer.
• A FIFO is created by the mknod system call and may be opened and accessed by
any process that knows the name and has the permissions.
• The buffer associated with a FIFO file is allocated when the first process opens
the FIFO file for read or write. The buffer is discarded when all processes which
are connected to the FIFO close their reference to the FIFO file.
• FIFO file may be removed like any regular file. FIFO files can be removed in
UNIX via the rm command.

File Attributes
• One of the characteristics of file is a set of file attributes that give the operating
system more information about the file and how it is intended to be used. For
human users convenience bane is given to the file. File attributes are varies from
system to system.
• File attributes are as follows:
1. Name
2. Identifier
3. Type
4. Location/place
5. Size
6. Protection
7. Date and Time
• File name is in human readable. User can perform any operation on file using its
name.
• When file is created by user, operating system assigns unique identification
number to each file. OS uses this identifier for its operation.
• Type information is required for systems that support different types of files.
• Location/place information is pointer to a device and actual location of files on
the device. The information needed to locate the file on disk is kept in memory.
• Size is measured in bits or bytes. It gives idea about current size of the file.
• Protection: This information is stored on the per-process table so the operating
system can allow or deny subsequent requests. Attributes like protection,
password, creator and owner provides protection to a file.
• Date and time: This information is related to creation and modification of files.
Protection, security and monitoring purposes this data is used by operating system.
Operation on File
• File operations are simply those things that user can perform on a file. For
example, user can create a file, save a file, open a file, read a file and modify a file.
There are many different types of file operations supported by operating system.
• Operating system can provides system call for performing various operations on
the file. Six basic file operations are creating, write, read, delete, repositioning and
truncating.
• Following are the some list of file operation:
1. Create
2. Write
3. Closes
4. Read
5. Delete
6. Repositioning.
• All these operations require that the directory structure be first searched for the
target file.
• File creation: Any time user can create a file. File is also created without data.
The steps for creating a file.
a. Space: File system must provide a space for the file.
b. New file entry is made in the directory.
• Write: To perform write operation on the file, file name and data is required. It
updates a file by adding new data and changes some content of the file. For writing
into a file, operating system searches the directory for particular file. Write pointer
is kept at the location where the writing starts. Write pointer position is at middle
of the file or end of the file. Write pointer is updated when writing to file is
completed.
• Close: Process is not used a file after closing. Process can not perform any
operation on file. Operating system remove it entry from open file table.n
• Read: A process reads all or some portion of the data in a file. Read system call
is used for reading a file. For reading a file, name and position of the memory is
specified. Read pointer is kept into the file for next read operation. Read pointer is
updated after completion of the read system call. Information about read pointer is
stored in per process current file position pointer.
• Delete: Operating system remove the file from file structure. For deleting a file,
no directory is searched with particular name and file is deleted. Deleting
means making space free from memory and disk. Operating system also removes
the directory entry. This free space is used by another file. ein
• Repositioning: The directory is searched for the proper entry, and the current-
file-position pointer is repositioned to a given value. Repositioning within
• Other file operations are open, append, seek, get and set attributes and rename.
• Open: Before performing any operation on file, it is necessary to
• Append: Append is related to write operation of file. Append only add data to
the end of the file.
• Get and set attributes: Get attribute is used before performing operation on file.
When user request a file for any operation, get attributes is executed by the
process. Depending upon the attributes, user can allow or deny the operation. User
can set the attributes and it changed after creation of file.
• Rename: User can change the name of existing file.

File Structure
• File structure is represented by field, record, file and database. It is also
represented by byte sequence, record sequence and tree.
• Fig. 6.1.1 shows the three different kinds of files. Unix and windows both use
unstructured byte sequence

• Byte sequence is unstructured file. Operating system is nothing to do with content


of file. All content is in byte format. Windows and UNIX operating system uses
this byte sequence method. It provides more flexibility to the user. User can put
anything in the file and assign name whatever they want to the file.
• In record sequence model, file contains a sequence of fixed length record. Read
and write operation on this type of file will perform one record at a time. It uses an
idea of 80 column punched card. Most of the operating system based their file
system on file consisting of 80 character records.
• Record sequence model also support 132 character records. Line printer uses 132
characters for printing.
• Last method is tree structure. File consists of tree of records. Each record
contains key field in the fixed position. Key field is used to sort the tree record.
• Field, record, file and database is used in these file structure. Field is a basic
element of data. Persons last name and date example of the field. It contains single
value. Length and data type is characteristics of field.
• Collection of related field is records. A student record contains name, address,
mobile number, university exam number, college name etc. Records may be fixed
length or variable length. A record also contains sub-records. Sub-records may be
one or more than one.
• File is collection of similar records. From user view, file is single entity and
reference by name.
• Database is a collection of related data. All records have some relation in
database. Engineering college database contains information about college,
student, staff, university, syllabus, timetable, fee' structure, various departments
etc. One or more field is used in database.

3.7 Access methods


• Information and data is kept in files. Files are stored on the secondary storage
device. When this information is to be used, it has to be accessed and brought into
primary main memory.
• Information in files could be accessed in many ways. It is usually dependent on
an application. File organization checks how efficiently the input-output storage
medium used.
• File access method defines the way processes read and write files. Different
access methods are available. Some operating systems provide only one access
method and other systems provide many access methods.
1. Sequential access 2. Direct /Random access 3. Indexed sequential access.
• Access method means accesses to files that use a particular file organization are
implemented by an input output control system.

Sequential Access Method


• Sequential access method simple method. The information in a file is accessed
quentially one record after another.
• In this method, a process could read all the records in a file in order, starting at
the beginning. It can not skip any records and can not read out of order.
• Fig. 6.2.1 shows sequential access method.

• Batch application uses sequential files. A byte stream file uses sequential access
method.
• Example: Compiler and editor usually access files in this method. Transaction
file is also example of sequential access method.
• Sequential file organization only method easily stored on tape and hard disk.
Sequential access is best suited where most of the records in a file are to be
processed.
Disadvantages:
• It provides poor performances.
• More efficient search technique is required.

Direct Access Method


• It is also called random access method. This access allows a user to position the
read/write mark before reading or writing.
• Fig. 6.2.2 shows direct method.
• Direct access file method provides, accessing the records directly. Direct access
method is based on the hard disk that is a direct access device. It allows random
access of any file block.

• Each record has its own address on the file with by the help of which it can be
directly accessed for reading or writing. This feature is used by editors. An editors
need to randomly access the contents of the file.
• There is no restriction on the order of reading or writing for a direct access file.
Operating system support is not required for direct access file.
• At the time of file creation, access method is defined. According to defined
access method, file is accessed. Sequential access of a direct access file is possible
but direct access of a sequential file is not.
Disadvantages:
1. Poor utilization of input-output device.
2. Consumes CPU time for record address calculation.

Indexed Sequential Access


• It is modified method of direct access method. This method is combination of
direct and sequential access method.
• In simple indexed sequential method, simple single level of indexing is used.
Sequential file is used as index.
• Fig. 6.2.3 shows indexed sequential file. Indexed sequential access contains key
field and a pointer to the main file.

• Indexed sequential files are store records in the order that they are written to the
disk. Records may be retrieved in sequential order or in random order using an
index to represent the record number in the file.
• If file size is large, larger index is required and it contains large number of
entries. CPU takes time to search in to the index. Higher level index is used to
reduce the search time. An entry in the higher level index points to a section of the
index. This higher index contains the records. This index is searched to find the
section sdns of the disk that may contains a required record.
• File system maintains an overflow file. It adds new records to an overflow file.
The record in the main file that immediately precedes the new record in logical
sequence is updated to contain pointer to the new record in the overflow file.
• The overflow file is merged with the main file during a batch update. The
multiple indexes for the same key field can be set up to increase efficiency.
• The lowest level of index file is treated as a sequential file and a higher level
index file is created for that file. Higher index file would contain pointers to lower
index files, which would point to the actual data items.
3.8 Directory Structure
User stores file in file system using directory. File system stores files of many
users. Files are stored on the secondary storage device like hard disk, optical disk
and memory disk. These device support random access method.
• Directory structure organizes and provides information about all files in the
system. Every partition has a file system which consists of files and directory. Hard
disks are split into one or more partitions. It is called as minidisks or volumes. User
can assign names to volumes. Each disk contains minimum one partition.
• Operating systems support upto 24 partitions. Partitions can be larger than a disk
i.e combing two hard disks. These partitions are called "virtual disks". Partition
maintains information about files in "Device Directory".
• Files are stored in the directory. Directory is created by user. User is free to create
as many as directory and assign suitable names. File system contains many
directories. Directory maintains information about the file. File information
includes type, size, date modified and name.
• In some operating system, directory itself is considered as a file. A set of
logically associated files is called directory. Directory structure of the file system
connects a directory to other directories in the system.
• Directory is a data structure that lists files and subdirectories in a collection.
Directory structure contains a list of entries one for each file.
• Directory does not store any user data. Single dot (.) indicates a current directory
rote and double dot (..) indicates parent directory. The root is identified by the
directory '/'. The root file system has several subdirectories.
• Windows file system uses a letter followed by colon for specifying root directory.
For example, root directory in windows is C: or D: or E:
• UNIX and Linux based file system uses slash (/) for specifying root directory.
• A directory can contain any number of files. A directory can also contain
subdirectories. Because a directory is nothing more than a special kind of file,
directories also have names.
Operation on directory :
1. File searching: Directory structure is searched for particular file entry. File uses
symbolic names and similar names may indicate a relationship between files.
2. Create a file: User creates new files and added to the directory.
3. Delete a file: User remove the file after completing its work on files.
4. Rename a file: User change the file name if file content is change.
5. Listing of directory: Listing of files in the directory for some use. MS-DOS
and windows uses "dir" command and Linux/UNIX uses "ls" command for this
purposes.

Single Level Directory


• Single level directory is a simple structure and there are no sub-directories.
• Fig. 6.3.1 shows three files with single level directory. It is also called flat
directory structure.

• Single level directory structure is suitable only for single user. If user increases, it
creates the problem with assigning the name to files.
• In single level directory structure, no two files can have the same name.
• It is simple to implement and searching of file is faster. This type of directory
system is used in cameras and phones.
• Because of limitation of file names, this structure is rarely implemented.
• File name size varies according to the operating system. MS-DOS operating
system allows only 11 character file names and UNIX OS allows upto 255
characters.
Disadvantages of single level directory:
1. Not suitable for a large number of files
2. Limitation of unique file name.
3. For large number of file, recalling file name is difficult.

Hierarchical Directory System


• Here files are grouped together to form a sub directory. Each directory may
contain several subdirectories. In hierarchical file system, a root directory points to
other directories and files.
• Hierarchical directory system contains various forms of directory structures. They
are as follows:
1. Two-level directory structure
2. Tree structured directories
3. Acyclic graph directories.

Two-level Directory Structure


• Two-level directory structure contains master file directory at the top level then
user file directory at the second level. Actual user files are at the third level.
• File system maintains a master block for each user. Master block has one entry
for each user.
• User directory address is stored in the master block. Each user has a private
directory. Different user can assign same names to their files as the directories for
each user are now separate.
• Fig. 6.3.2 shows two-level directory structure.

• Here user can work only in own directory. Other user need not worry about
deleting or modifying files by other users.
• When user wants to create a file, system search that particular file name in the
directory. If same file name is not found, then it creates a file otherwise it gives
error messages.
• In this structure, different users may have files with same name. It solves the Viol
name conflict problem. When user want to open a file, filename is searched for in
users directory.
• A two level directory can be a tree or an inverted tree of height 2.
• There are still problems with two-level directory structure. It effectively isolates
one user from another. This is some time advantage or some time disadvantages.
For completely independent user is an advantages and disadvantages when
cooperation between two users is required.

Tree Structured Directory


• Fig. 6.3.3 shows the tree structured directory.

• In this structure, directory itself is a file. A directory and sub directory contains a
set of files. Internal format is same for all directories
• Commonly used directory structure is tree structure. Tree has a root directory.
All files in disk have a unique path name.
• A path name describes the path that the operating system must take to get from
some starting point in the file system to the destination object. Each process has its
own working directory. Path names are of two types : relative and absolute.
• Relative path name : Its path starts from current working directory (may start
with
• Absolute path name: Its path starts from root directory (starts from "/").
• Tree structured directory differentiate file and subdirectory by using one bit
representation. Zero (0) represents file and one (1) represents subdirectory.
• When process makes reference to a file for opening, file system search this file in
the current directory. If needed file is not found in the current directory, then user
either change the directory or give the full path of the file. System calls are used
for performing any operation on the files or directory.
• Empty directory and its entry are easily deleted by operating system. If directory
contains files and subdirectory, i.e. non-empty directory, some operating systems
not delete the directory.
• To delete a directory, user must first delete all the files and subdirectory in that
directory.
Merits
1. User can create his/her own directory.
2. User can access other user files by specifying path name.
3. Separate subdirectory for files associated with different topics
4. Searching id fast and efficient.
Demerits
1. Sub directory can not share between the user
2. Path is longer than two level directory structure
Acyclic Graph Directory
• Acyclic graph directory solve the problem of tree structure directory.
• It allows sharing the directory in between two users. At a time more than one
places shared directory or file will exist in the file system.
• Fig. 6.3.4 shows acyclic graph directory. Links can be used to construct acyclic
graph
• It is very interesting to note that a shared directory or file is not the same as two
copies of the file. When there are two copies of files, each user can view the copy
rather than the original, but if one user changes the file content, the changes will e
file content, t not appear in the other's copy.
• Only one original file exists for shared copy. Any changes made by one user are
immediately visible to the other user. When user create file in shared directory, it
automatically appear in all the shared subdirectories.
Implementation of shared files and directory:
1. Using link :
• Link is used for creating shared files and directory. A link is a pointer to another
file or subdirectory. If reference to a file is made, the directory is first searched. A
link is a logical relationship between an inode and a file that relates the name of a
file to its physical location.
• UNIX operating system uses acyclic graph directory structure. Reference count is
maintained by UNIX for files and directory. UNIX operating system provides two
types of links: hard link and symbolic link
• A hard link contains multiple directory entries that both refer to the same file.
Hard links are only used with ordinary files in the same file system.
• A symbolic link is also called soft link. It contains a special file which maintains
the information about file where to find the linked file. Symbolic links may be used
to link directories and files in other file systems.
• Soft links were designed for two specific situations: Links to directories, which
must be symbolic, and links to files in other file systems.
• Windows operating system only supports symbolic links.
• Hard links require a reference count, or link count for each file, keeping track of
how many directory entries are currently referring to this file. Whenever one of the
references is removed the link count is reduced, and when it reaches zero, the disk
space can be reclaimed.
2. Duplicating information:
• Duplicate all information about shared files in both sharing directories. Original
file will remain as it is without modifying any content by shared user.
• Consistencyis not supported by copied file and shared file. Shared files may have
more than one absolute path.
Advantages:
1. Simple for file traverse.
2. Structure is more flexible than a simple tree structure.
3. It allows directories and files to be shared between other users.
Disadvantages:
1. Deletion of file is difficult.
2. Problem with duplicate directory entries is maintaining consistency if the file is
modified.

3.9 Sharing and Protection


File Sharing
• Multiprogramming and multitasking operating system support the multiple user.
These users perform various operations on the files. Files are shared between
numbers of users. File protection, naming and sharing is issue for file sharing.
• Directory structure may be allows files to be shared by users. Sharing must be
done through a protection scheme.
• In single user system, operating system maintains attributes for all files and
directory. According to the attributes, operating system allows to operate the files
for users. But on the multi-user system, more attributes are needed. An attributes
like owner, group and other user are required. These are the access permission for
files and directory.
• Access permissions are of three types : Read, Write, and execute.
1. An "r" indicates read permissions for a file or directory.
2. A "w" indicates write permissions.
3. An "x" indicates execution permissions if it is a file and search permissions if it
is a directory.
4. Owner is the file owner who created a file. Owner having all rights (read, write
and execute).
5. The groups of other user have some limited access permission. Mostly read Juda
yer and execute permission.
6. Last categories of user have only executed permission.
• Example In UNIX operating system, file owner can perform all operation on a
file. Group member can execute one subset of those operations and other than the
group user can execute another subset of operations.
• When a user requests an operation on a file, the user ID can be compared with the
owner attribute to determine if the requesting user is the owner of the file.
Likewise, the group IDs can be compared.
Remote file systems
• Computer network is used to support remote file system. User can access remote
file system. File Transfer Protocol (FTP) and Secure Shell protocol (SSH). Other
supporting protocol like distributed file system and world wide web is also used for
remote file system.
• SSH is a protocol for secure remote access to a machine over untrusted
networks.
• A client-server model has three components:
1. Service: A service is a software entity that runs on one or more machines. It
provides an abstraction of a set of well-defined operations in response to
applications' requests.
2. Server: A server is an instance of a particular service running on a single
machine.
3. Client: A client is a software entity that exploits services provided by servers.
• Client application program running on the local machine requests a service from
another application program, server running on the remote machine. Commonly
server provides service to any client, not a particular client.
• Generally, a client application program that requests a service should run only
when it is needed. A server program providing service should run all the time, as it
does not know when its services will be needed.
• Client-server model allows clients to mount remote file systems from servers.
The server is connected with multiple clients and it serve to all clients. Client and
user-on-client identification is insecure or complicated.
• A client opens the communication channel using IP address of the remote host
and the port address of the specific server program running on the host i.e. active
open. Request-response may be repeated several times, the process is finite. The
client closes the communication channel with an active close.
• A server program opens its door for incoming requests from clients but never
initiates a service unless explicitly requested i.e. passive open. A server program is
infinite and runs unless a problem occurs.
• Two or more clients can run at the same time on a machine is called concurrency
in client. One client must start, run and terminate before another client may start. It
is called iterative.
• Network File System (NFS) is standard for UNIX client-server file sharing
protocol and Common Internet File System (CIFS) is standard Windows operating
system protocol. The NFS client maintains a cache of file and directory attributes.
The default settings will not ensure that files created or modified on one system
will be visible on another system within a minute of file creation or modification.
Network file system is common distributed file sharing system.
• File data modifications might not be visible on any NFS client system other than
the one where the modifications are being made until an NFS commit is executed.
Most NFS clients will issue a commit as part of closing a file. If multiple systems
are reading files that might be modified, file system locking should be used.
• NFS communication protocols lets processes running in different environments
share a file system. NFS implements a file system model that is almost identical to
a UNIX system.
• Distributed Information Systems such as LDAP, DNS, NIS, and Active Directory
implement unified access to information needed for remote computing. It is also
known as distributed naming services.
• A name in a distributed system is a string of bits or characters used to refer to an
entity. To resolve names a naming system is needed. Names are used to share
resources, uniquely identify entities and refer to locations.
• The naming and locating facilities jointly form a naming system that provides the
users with an abstraction of an object that hides the details of how and where an
object is actually located in the network.
• It provides a further level of abstraction when dealing with object replicas. Email
and FTP is used for sending information to remote users. But these two protocols
will not support true file sharing. Domain Name System (DNS) is used to map the
host name to network address translation for the internet. DNS replace the Email
and FTP. The DNS is a hierarchical distributed naming system.
• On windows operating system, user name and password is used to create login on
the server. Using this authentication method, server will allow and deny access to a
requested file system. CIFS is used in conjunction with login name and password.
• Industry is moving towards the new technology. So new protocol called 18.
Lightweight Directory Access Protocol (LDAP) is used for secure distributed
naming service. LDAP allows user to search for an individual without knowing
where they are located.
• An LDAP directory can be distributed among many servers. Each server can have
a replicated version of the total directory that is synchronized periodically. An
LDAP server is called a Directory System Agent.
• An LDAP server that receives a request from a user takes responsibility for the
request, passing it to other DSAS as necessary, but ensuring a single coordinated
response for the user.
Failure modes
Reasons for local file system failures:
1. Media fails where file system is stored
2. Corruption of directory structure
3. Power cable and hard disk cable failure
4. Disk controller failure
5. Host adapter failure.
• Apart from these reasons, there are many other reasons for remote file systems.
Bandwidth and communication also cause the delay.
Consistency semantics
• Consistency semantics is related with file sharing on the network. When does
the changes of the original file is reflected to other users. If there is difference in
the oats content of the file, then it creates the problem.
• It deals with the consistency between the views of shared files on a networked
system. When one user changes the file, when do other users see the changes of the
content?
• Define when modifications of the file data made by a user are observable by
other users
1. Unix semantics
2. Session Semantics
3. Immutable shared-files semantics
4. Transaction-like semantics
• Difference operating systems consistency semantics is discussed here :
1. UNIX semantics
• Unix file system (UFS) implements:
a. Writes to an open file visible immediately to other users of the same open file.
b. Sharing file pointer to allow multiple users to read and write concurrently
• In UNIX semantics, a file is coupled with a single physical image that is
associated as special resource. If there is conflict for single then it causes delays in
user processes.
• Centralized system uses UNIX semantics. This is common for single processor
systems, but difficult to achieve for distributed file systems.
2. Session semantics
Andrew File System (AFS) implemented complex remote file sharing semantics.
1. Writes to a file by a user is not visible to other users.
2. Once the file is closed, the changes are visible only to new sessions.
• In this semantics, a file can be associated with multiple views. Almost no
constraints are imposed on scheduling accesses. No user is delayed in reading or
writing their personal copy of the file.
• AFS file systems may be accessible by systems around the world. Access control
is maintained through complicated access control lists, which may grant access to
the entire world or to specifically named users accessing the files from specifically
named remote environments.
• Questions arise about how to handle reads/writes by multiple processes. The file-
level transfer model should be used.
3. Immutable-shared-files semantics
• Under this system, when a file is declared as shared by its creator, it becomes
immutable and the name cannot be re-used for any other resource. Hence it
becomes read-only and shared access is simple.
• Once a file is declared as shared by its creator, it cannot be modified.
• An immutable file has two key properties. Its name may not be reused and its
contents may not be altered.
Protection
• User information and data is stored in the secondary storage. It is necessary to
provide security from physical damage and improper access.

Type of Access
• Access is limited or full access of data. User having full access can perform read,
write and modify operation on the data and information. In limited access, user
only read and executes the information.
• Protection mechanism provides controlled access. Following are some of the aw
operation performed on the files.
1. Read: User can read a file.
2. Write: User can rewrite a file.
3. Delete: User can delete a file whenever space is required.
4. Execute: User execute a file after loading into the main memory.
5. List: User check attributes of the file and file/directory names.

Access Control
• Traditionally, a file object in Linux is associated with three sets of permissions.
These sets assign read (r), write (w), and execute (x) permissions for the three user
groups file owner group, and other.
• Nine bits are used to determine the characteristics of all objects in a Linux
system. Additionally, the set user id, set group id and sticky bits can be set for
special cases.
• ACLS can be used for situations where the traditional file permission concept
does not suffice. They allow the assignment of permissions to individual users or
groups even if these do not correspond to the owner or the owning group. Access
Control Lists are a feature of the Linux kernel.
• There are two types of ACLS : Access ACLS and default ACLs. An access ACL
is the access control list for a specific file or directory. A default ACL can only be
associated with a directory; if a file within the directory does not have an
access ACL, it uses the rules of the default ACL for the directory. Default ACL's
are optional.
• ACL's can be configured:
1. Per user 2. Per group
3. Via the effective rights mask
4. For users not in the user group for the file.
Access determination
• When a process attempts to access a file, its effective UID is compared to the
UID that owns the file. If they are the same, access is determined by the ACL's
user permissions. Otherwise, if a matching user specific ACL entry exists,
permissions are determined by that entry in combination with the ACL mask.
• If no specific entry is available, the file system tries to locate a valid group related
b entry that provides the required access; these entries are processed in conjunction
se with the ACL mask. If no matching entry can be found, the other entry prevails.
NFSv4 ACL
• The NFSv4 (Network File System - Version 4 protocol introduces a new ACL
format that extends other existing ACL formats. NFSv4 ACL is easy to work with
and introduces more detailed file security attributes, making NFSv4ACLs more
• NFSv4 ACL's are similar to Windows ACL's in structural perspective. In both the
system, ACL stores this entity as a string.
The Windows and NFSv4 permission model is more granular than the traditional
UNIX read-write-execute model.
1. NFSv4 distinguishes permissions to create files within a directory from
permission to create subdirectories.
2. NFSv4 has a separate append permission bit.
3. NFSv4 has separate read and write permissions for data, file attributes, extended
attributes, and ACLs.
4. NFSv4 controls a user's ability to change the ownership of a file through the
standard ACL.
NFSv4 file permissions

Access Determination in NFS


• In the POSIX ACL system, the file system attempts to match the user's identity to
the single most appropriate access control entry. The Access Control Entry (ACE)
then provides a complete set of controlling permissions for the file.
• Each NFSv4 ACE is either an "allow" ACE or a "deny" ACE. When deciding
whether to allow a particular operation, the file system reads the ACL in order,
processing ACEs until either all requested permissions have been allowed or some
requested permission has been denied.
ACL inheritance
• ACL inheritance is a mechanism that lets container objects pass access control
information to their child objects. A container's child objects can be non-container
objects as well as other container objects.
• From an administrator point of view, ACL inheritance simplifies access control
management. An administrator can set the ACL on a parent object and if
inheritance is enabled, he shouldn't need to set ACLS on each child object.

3.10 File System Structure


• File system is mounted and maintain by the secondary storage which provides by
disk. Characteristics of disk are as follows:
1. Same place is used for reading, writing and modification.
2. User can access disk directly for any block of information.
• Block is used for data transfer. Each block contains one or more sectors. The I/O
transfer between memory and disk are performed on block. Default sector size is
512 bytes.
• Concept of file system is used for the efficient and convenient access to the disk.
File system allows data to be stored, located and retrieved easily. The file system is
generally composed of many different levels.
• Fig. 6.7.1 shows layers of file system.
• There are six layers. Each layers give support to neighbour layers. It also
provides function to above layer and below layer. Each layer uses the features of
neighbour layer while creating new features for use by the higher levels.
• File system creates two main design problems:
1. Creation of algorithm and data structure for of mapping of logical file system to
physical secondary storage devices.
2. File system view for user.
• Input-output control interface: It consists of device driver and interrupt
handler. Both are used for data transfer between main memory and disk system.
Device driver used as a translator. Device driver input is high level commands and
output is l ow level hardware specific instructions.
• Basic file system layer: It generates the command for device drivers. Particular
device driver read data and writes physical blocks on the disk. Basic file system
also manages the memory buffer and caches that hold various file system. Cache T
memory is used to hold meta-data information of file system.
• File organization modules layer: This layer maintain information about files
and be their logical blocks and physical blocks. It translate the logical block
address to physical block address by considering physical location of files and file
allocation method. File logical numbers are do not match with physical block
containing data, so translation is required. Free space manager is included in file
organization modules.
• Logical file system layer: It manages metadata information. Actual data is not
part of metadata information. But file system structure is part of metadata.
Directory structure is used to organized file module. Operating system maintains
file control block for each file. UNIX uses inode instead of file control block. File
control block stored information about file, location, ownership and access
permissions.
• Application program layer: User/programmer creates an application programs.
• Physical hardware devices layer: It contains actual hardware device link disk,
memory etc.
• Following is the list of different operating systems file system:
Google uses its own Google file system.

3.11 Directory implementation


• Directory is implemented by using linear list and hash table.
Linear list
• Linear list is simple method of directory implementation. It uses file names with
bead pointers to data block. It is time consuming because of searching overheads.
• To create a new file, file name is searched in the directory to avoid the file name
duplication. Then it adds new entry at the end of the directory. To delete a file,
again file name is searched in the directory. Space is released after deleting a file.
Directory entry is also removed. Unused space is marked as free entry. Last entry
of directory is copied into the free space list.
• For deleting a file, some OS uses linked list. Linked list decreases time required.
• Searching the directory entry is the major disadvantage. It is slow process.
Because of this reason, many operating system uses software cache memory. It
stores the most recently used directory information.
Hash table
• Hash table is one more data structure used for directory implementation. Hash
table takes a value computed from the file name and returns a pointer to the file
name in the liner list.
• Hash table reduces the searching time. It uses fixed size block.

3.12 Allocation Methods


• The primary issue of file implementing file storage is how to keep track of file
blocks. File consists of a collection of blocks.
File allocation
• Following issue are considered for file allocation:
1. After creation of new file, whether the required maximum space for the file is
allocated at once or not?
2. Portion Space is allocated to a file as one or more contiguous units.
3. Data structure or table used to keep track of the portion which is assigned to
a file.
• Three major methods of allocating disk space are in wide use,
1. Contiguous 2. Linked 3. Indexed.

Contiguous Allocation
• When user creates a file, system allocates a set of contiguous blocks on disk. This
is a pre-allocation method that uses portion of variable size. Contiguous allocation
is simple method to implement. It only search free list of correct number of
consecutive blocks and mark them as used block.
• Disk address is a linear ordering on the disk. Because of linear ordering,
accessing block b + 1 after block b normally requires no head movement. Here
head movement is only one track. Fig. 6.10.1 shows contiguous allocation.
• Contiguous allocation of a file is defined by the disk address and the length of the
on first block.
• If the file size is "n" blocks and starting location is "L", then it occupies blocks L,
L+1, L+2, L+3, ......, L+(n-1). The directory entry for each file indicates the
address of the starting block and the length of the area allocated for this file.
• Sequential and random access can be supported by contiguous allocation.
• It is easy to retrieve single block. To improve the I/O performance of sequential
processing, multiple blocks can be brought in one at a time. It supports sequential
access very well because files entire data is stored in adjacent block. This method
bra also supports random access.
• Contiguous allocation also suffers from external fragmentation. Small free disk
spaces are created after allocation free block and deleting files.. External
fragmentation means there will require free space available but that is not
contiguous. To solve the problem of external fragmentation, compaction method is
used.
• One more problem is that how to calculate the space needed for a file. It is
difficult to estimate the required space.
• This method is good for storing data on CD-ROM.
Characteristic of contiguous file allocation :
1. It supports variable size portions.
2. Pre-allocation is required.
3. It requires only single entry for a file.
4. Allocation frequency is only once.
Advantages:
1. It supports variable size portion.
2. Easy to retrieve single block.
3. Accessing a file is easy.
4. It provides good performance.
Disadvantages:
1. It suffers from external fragmentation.
2. Pre-allocation is required.

Linked Allocation
• Linked allocation is also called chained allocation. Operating system keeps an
ordered list of free blocks. File descriptor stores pointers to the first block and each
block stores pointer to the nest block.
• Fig. 6.10.2 shows linked allocation. The disk blocks may be scattered anywhere
on the disk. The directory contains a pointer to the first and last blocks of the file.
No space is lost to disk fragmentation.
• Creation of new file is easy. For new file, simply create new entry in the
directory. Reading a file is straightforward. User simple read blocks by following
pointers from block to block. There is no external fragmentation with linked
allocation.
• To write to file, system finds a free block, and this new block is written to and
linked to the end of the file.
• While creating a new file, it is not necessary to declare the size of the file. A file
can contiguous to grow as long as free blocks are available.
• Compaction can be used so that blocks of one file are located continuously on the
disk. It optimizes disk access.
• File allocation table is an extension of the linked allocation method. Instead of
putting the pointers in the file, keep a table of the pointers around. This pointer
table can be quickly searched to find ant random block in the file.
• Fig. 6.10.3 shows the file allocation table. All blocks on the disk must be
included in the table. This method is used by windows operating system.
(Refer Fig. 6.10.3 on next page)
Characteristics
1. It supports fixed size portions.
2. Pre-allocation is possible.
3. File allocation table is one entry for a file.
4. Allocation frequency is low to high.
Advantages:
1. There is no external fragmentation.
2. It is never necessary to compact disk space.
3. Pre-allocation is not required.
Disadvantages:
1. Files are accessed only sequentially.
2. Space required for pointers.
3. Reliability is not good.
4. Can not support direct access.

Indexed Allocation
• Indexed allocation method solves the problem of both contiguous and linked
allocation. It uses concept of index block. Index block stores the entire pointer in
one location. But the index block will occupy some space and thus could be
considered as an overhead of the method.
• OS keeps a list of free blocks. It allocates an array to hold pointers to all the
blocks used by the file. It allocates blocks only on demand. Fig. 6.10.4 shows
indexed allocation.
• In indexed allocation, each file maintains its own index block. It contains an array
of disk sector of addresses. For example: The nth entry in the index block points to
the nth sector of the file. The directory contains the address of the index block of a
file. To read the nth sector of the file, the pointer in the nth index block entry

• It supports direct access and without suffering from external fragmentation. Any
free block anywhere on the disk may satisfy a request for more space.
• Indexed allocation does suffer from wasted space. The pointer overhead of the
index block is generally greater than the pointer overhead of linked
allocation. Advantages:
1. It supports sequential and direct access.
2. No external fragmentation.
3. Faster than other two methods.
4. It supports fixed and variable size blocks.
Disadvantages:
1. Indexed allocation does suffer wasted space.
2. Pointer overhead is generally greater.

Comparison of Contiguous, Linked and Indexed File Allocation

3.13 Free Space Management


• Space that is allocated to files must be managed and space which is not allocated
to any file must be managed. To keep track of free disk space, the system
maintains a free space list. File allocation table and disk allocation both are
required to manage free space properly.
• When a file is deleted, its disk space is added to the free-space list.
• Following are the techniques used for free space management:
1. Bit tables or bit vector
2. Chained free portions or linked list
3. Indexing or grouping
4. Free block list or counting
1. Bit tables or bit vector old
• Each block on the disk is represented by bit. It uses vector chain for blocks. Free
block is represented by o and used block represented by 1.
• For example, consider a disk where blocks 3, 4, 5, 7, 9, 14, 15, 19, 30, 31, 32, 35,
36, 37, 38 are free blocks and rest of the blocks are allocated. The free space is
shown below:
111000101011110011101111111111000110000
• The memory required for a block bitmap = Disk size / 8 × (block size of file
system)
• Bit map requires extra space. For example:

• When bit table is stored into the memory, then exhaustive search of the table can
ano slow file system performance. Most of the file system use auxiliary data
structure al for bit table. File system also maintain summary table. Summary table
contains sub-range, number of free blocks and maximum sized contiguous number
of free blocks.
• Summary table is used to store information about contiguous free blocks.
Whenever file system needs a number of contiguous blocks, it can scan the
summary table to find an appropriate sub-range and then search that sub-range.
This method is used in Apple Macintosh.
Advantage :
a. Easy to find a free blocks
b. It is as small as possible.
Disadvantage :
It may not be feasible to keep the bitmap in memory for large disks.
2. Link list
• In this method, all free space disk blocks are linked, keeping a pointer to the first
free block. All file allocation methods used link list free space techniques.
• There is small space overhead because there is no need for a disk allocation table.
In the above example, free blocks are 3, 4, 5, 7, 9, 14, 15, 19, 30, 31, 32, 35, 36,
37, 38. Here free block pointer is on block number 3. Block 3 contains pointer to
block 4, block 4 contains pointer to block 5 and block 5 contains pointer to block 7
and so on.
• This method is not efficient because to reach free block 9, we have to traverse
973 block 3, 4, 5 and 7 then we will reach to block 9.
• Disk will become quite fragmented after some use. Many portions will be a single
block long.
3. Grouping
• First free block contains the addresses of n free blocks. The first n-1 of these
blocks is actually free. The last block also contains the address of another n free
block.
• Consider the free blocks: 3, 4, 5, 7, 9, 14, 15, 19, 30, 31, 32, 35, 36, 37, 38
• When all the blocks in the group have been allocated, then use the block that held
the pointer.
• Because of grouping method, address of a large number of free blocks can be
found quickly.
4. Counting
• It keeps the address of the first free block and the number n of free contiguous
blocks that follow the first block. Each entry in the free space list then consists of a
disk address and a count.

You might also like