0% found this document useful (0 votes)
69 views

20Z352 - OS Lab Report

This document summarizes an OS laboratory report on disk scheduling algorithms. It defines key terms like seek time, rotational latency, and transfer time that determine disk access time. It describes the FCFS, SSTF, SCAN, C-SCAN, LOOK, and C-LOOK disk scheduling algorithms and notes their advantages and disadvantages. It then provides a detailed explanation of the SCAN algorithm through an example problem.

Uploaded by

Arul Jothi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

20Z352 - OS Lab Report

This document summarizes an OS laboratory report on disk scheduling algorithms. It defines key terms like seek time, rotational latency, and transfer time that determine disk access time. It describes the FCFS, SSTF, SCAN, C-SCAN, LOOK, and C-LOOK disk scheduling algorithms and notes their advantages and disadvantages. It then provides a detailed explanation of the SCAN algorithm through an example problem.

Uploaded by

Arul Jothi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

OS Laboratory Report

Name: Tharunkumar Dhanasekaran

Roll No: 20Z352


Class: Computer Science & Engineering - G2

Course: 19Z410 - Operating Systems Laboratory

Introduction
Any program before execution resides in secondary memory or the hard disk drive
(HDD). Back when they were introduced, HDDs were a revolution. They were the
go-to secondary storage mechanism for computers. With the advent of solid state
drives, HDDs have however now fallen out of use, although they remain contextual
relevant in the history of computer evolution.

A Hard Disk Drive

HDDs are non-volatile memory storage devices, meaning that they retain the data
written onto them even after termination of power supply to the computer. HDDs

OS Laboratory Report 1
contain platters made out of non-magnetic material, coated with a shallow layer of
magnetic material. Data is stored on the platters by rotating them at high speeds with
read and write heads modifying the magnetisation of the material that passes
beneath them. The varying magnetisations of the material are interpreted as data.
The whole idea immediately suggests that a lot of energy is spent in running HDDs.
A powerful computer typically encounters situations where several HDD access
requests are made at a time. Responding to these requests irresponsibly will lead to
the computer bearing the brunt of resource misuse. This called for the development
of algorithms that optimised the way HDD access requests were handled by the
computer, and thus Disk Scheduling algorithms were born.

Disk Scheduling Algorithms


As the name suggests, Disk Scheduling algorithms are techniques which when
followed, introduced some kind of optimisation into the way HDD access requests
are handled. There are some things worth noting while discussing disk scheduling
algorithms:

HDDs are some of the slowest parts of the computer which need to be used
responsibly.

Although multiple HDD access requests are possible, only one can be served at
a time by a disk controller.

While one request is being handled by the disk controller, the other requests
have to wait to be served the disk controller.

The further two requested memory locations are physically, the further the
needle to the HDD travels to address the later requests after the earlier request.

OS Laboratory Report 2
A hard disk controller, the hardware the mediates between I/O requests and disk drives. Credits:
Wikipedia

Important Terminologies
Parts of an HDD

OS Laboratory Report 3
The internal structure of the hard disk drive showing spindle, arms with read-write heads, platters,
tracks and sectors. Credits:
https://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/10_MassStorage.html

Platter: Disk shaped structures which are rotated in an HDD. Data is stored on
them

Track: Concentric circles around the spindle, along which data is stored

Sector: A segment of the track

Cylinder: A collection of all the tracks of a given distance from the spindle

Arm Assembly: The apparatus against which the platters are rotated

Read-write heads: The parts of the arms capable of modifying the


magnetisation of the material beneath them, thereby storing data

Seek Time
The time taken to change the location of the disk arm to the requested memory
location is called seek time.

OS Laboratory Report 4
Seek time is directly proportional to the distance of separation between the
memory locations of the current request and the next request to be handled.

Lower average seek time is an indicator of algorithm efficiency

Rotational latency
The time taken by the desired sector of a disk to rotate into a position so that it can
access the read-write heads is called rotational latency.

Lower average rotational latency is an indicator of algorithm efficiency.

Usually taken as 0.5 for estimation.

Transfer Time
Transfer time is the time to transfer the data. It depends on the rotating speed of
the disk and number of bytes to be transferred.

Disk Access Time


Disk Access Time = Seek Time + Rotational Latency + Transfer Time

Disk Response Time


It is the average time spent by a process in the waiting state before it receives its
first response time is called disk response time.

Low response time is an indicator of an efficient algorithm.

Variance Response Time


A measure of how individual requests are serviced with respect to the average
disk response time is called variance response time.

An efficient algorithm minimises variance response time.

All the desired factors may not achievable in a single algorithm. Hence, there are a
number of algorithms giving precedence to selected factors and making certain
trade-offs between them. These algorithms may not suit all scenarios and may work
efficiently for special scenarios only. The following are some algorithms that have
been developed for disk scheduling:

FCFS (First-come-first-served)

OS Laboratory Report 5
It processes requests in the order of arrival of the requests into the disk queue.

SSTF (Shortest Seek Time First)


It responds to those requests first that have smaller seek times.

SCAN or elevator algorithm


It traverses from one end of the memory to the other end and processes all
requests in that direction in order of appearance of addresses. Once traversal
reaches the end, it reverses direction and processes requests in the reversed
direction, in order of appearance of addresses.

C-SCAN (Circular SCAN)


It is a unidirectional form of SCAN, where after reaching the opposite end,
traversal again begins from the initial end, thereby traversing the memory in a
circular manner.

LOOK
It is a slightly more optimised form of the SCAN algorithm, where instead of
traversing to the ends of the memory, traversal is made only up to the requests
closest to the ends of the memory.

C-LOOK (Circular LOOK)


It is a slightly more optimised form of the C-SCAN algorithm, where instead of
traversing to the ends of the memory, traversal is made only up to the requests
closest to the ends of the memory.

Other Scheduling Algorithms


Random Scheduling

LIFO (Last-in-first-out)

N-step SCAN or N-step LOOK

FSCAN

SCAN Algorithm
The SCAN algorithm is also termed the elevator algorithm. Elevators service stop
requests only as the floors appear during their ascent or descent. For example, a

OS Laboratory Report 6
press of buttons 2, 3, 4, and 5 at the first floor will lead to the elevator stopping at all
the 4 floors in the order of arrival of the floors; however, a press of 1 while the lift is
on the third floor will be not be serviced during the ascent and will only be serviced
on descent, after the 4th floor call is serviced. Much akin to this, the SCAN algorithm
works as follows:

Algorithm
Assume a stretch of memory from address 0 to address x.

1. Note the current position of the head, curr.

2. If the previously serviced request is closer to address 0 than curr, then the
servicing of requests happens in the direction moving towards x. Else, traversal
happens towards address 0.

3. Whilst traversing till either end (decided based on step 2), service requests that
appear along the way.

4. Traverse until the chosen end and complete all the requests encountered in this
traversal. The ignored requests will be serviced in the next traversal.

5. Reverse directions and traverse through the memory, heading to the opposite
end. In this traversal, service the remaining requests that appear along the way.

Disadvantages
1. It is slightly complex to implement.

2. Wasteful traversal till any one end even after reaching furthest request.

3. Requests that arrive just after the arm proceeds in the opposite direction are
serviced unfairly late.

Question
Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is
currently serving
a request at cylinder 143, and the previous request was at cylinder 125. The queue
of pending
requests, in FIFO order, is 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130. Starting
from the
current head position, what is the total distance (in cylinders) that the disk arm
moves to satisfy

OS Laboratory Report 7
all the pending requests, using SCAN disk-scheduling algorithms? Write a C
program to
implement the same.

#include <stdio.h>
#include <stdlib.h>
int main()
{
int requests[100], i, j, n, start, maxSize, traversals, prev, seekTime = 0;
printf("Enter the number of requests:\n");
scanf("%d", &n);
printf("Enter the requested addresses:\n");
for (int i = 0; i < n; i++)
{
scanf("%d", &requests[i]);
}
printf("Enter position where head must begin: \n");
scanf("%d", &start);
printf("Enter total disk size: \n");
scanf("%d", &maxSize);
printf("Enter the previously serviced request: \n");
scanf("%d", &prev);
traversals = (prev < start) ? 1 : 0;
for (i = 0; i < n; i++)
{
for (j = 0; j < n - i - 1; j++)
{
if (requests[j] > requests[j + 1])
{
int temp;
temp = requests[j];
requests[j] = requests[j + 1];
requests[j + 1] = temp;
}
}
}
int index;
for (i = 0; i < n; i++)
{
if (start < requests[i])
{
index = i;
break;
}
}
// if traversal is towards high value
if (traversals == 1)
{
for (i = index; i < n; i++)
{
seekTime = seekTime + abs(requests[i] - start);
start = requests[i];
}
// last traversal for maxSize
seekTime = seekTime + abs(maxSize - requests[i - 1] - 1);

OS Laboratory Report 8
start = maxSize - 1;
for (i = index - 1; i >= 0; i--)
{
seekTime = seekTime + abs(requests[i] - start);
start = requests[i];
}
}
// if traversal is towards low value
else
{
for (i = index - 1; i >= 0; i--)
{
seekTime = seekTime + abs(requests[i] - start);
start = requests[i];
}
// last traversal for min maxSize
seekTime = seekTime + abs(requests[i + 1] - 0);
start = 0;
for (i = index; i < n; i++)
{
seekTime = seekTime + abs(requests[i] - start);
start = requests[i];
}
}

printf("Total seek time is %d.\n", seekTime);


return 0;
}

Output:

User-Big-Sur:SchedulingAlgorithms $ gcc SCAN_modified.c


User-Big-Sur:SchedulingAlgorithms $ ./a.out
Enter the number of requests:
9
Enter the requested addresses:
86 1470 913 1774 948 1509 1022 1750 130
Enter position where head must begin:
143
Enter total disk size:
5000
Enter the previously serviced request:
125
Total seek time is 9769.
Chandrahasans-MacBook-Pro:SchedulingAlgorithms selvamari$

OS Laboratory Report 9

You might also like